Skip to main content

First post here. So I have an issue, which I have identified, but I'm not quite sure how to fix it. I'd I'd really appreciate some input and suggestions. I I realize that my "pwmDelta" is the problem, but I am not sure what to do to fix it. So 

I am trying to write a program that will increment the value of the pin 3 a set amount of time, in a somewhat linear fashion, starting at my low point, and finishing at my high point. 

The issue is that my equation is incorrect and I can't output a partial bit value. Huge oversight on my part. If you read the data from the serial monitor with the code written as I have it, you'll see that it isn't coming even close to reaching my max value.

int motor1=3;motor1 = 3;         //pin for PWM output to motor
float t=0;t = 0;            //Variable to keep Track of time
int tLim=30;tLim = 30;          //Time Limit for Ramp
float lowLim=21;lowLim = 21;      //Low Limit, in Duty Cycle %
float highLim=65;highLim = 65;     //High Limit, in Duty Cycle %
float motorPWM=53motorPWM = 53.55; //Starting Value of PWM, in Bits
float pwmDelta=pwmDelta = ((255/100)*(highLim-lowLim))/(tLim); //Delta equation, to calculate how much to change PWM value each time it is incremented
float motorDelta;       //Variable to write value to Motor Output

void setup() {
  // put your setup code here, to run once:
pinMode(motor1, OUTPUT);
  analogWrite(motor1, 53.55); //run motor at initial value for 20 seconds before beginnning ramp
  delay(20000);
  Serial.begin(9600);
 
}

void loop() {
  (motorDelta=(motorDelta = motorPWM) +(pwmDelta)); pwmDelta; //incrementing output value based on Delta Equation
  motorPWM=motorDelta;motorPWM = motorDelta; //Setting new incremented value equal to old value, so incrementing can continue

  if (t <=tLim<= tLim) {  //Check if time is <= time limit
 
  {(  analogWrite(motor1, (motorDelta))); //write incremented value to output pin
    delay(1000);  //wait 1 second, increment t, to keep track of time
    t++;
  }
  else {
    analogWrite(motor1, motorPWM=165motorPWM = 165.75); //set pin to high value for 60 seconds, then set to 0
    delay(60000);
    analogWrite(motor1, motorPWM=0motorPWM = 0);
  }

 
  Serial.print(motorDelta);
  Serial.println();
  Serial.print(t);
  Serial.println();

 
}

First post here. So I have an issue, which I have identified, but I'm not quite sure how to fix it. I'd really appreciate some input and suggestions. I realize that my "pwmDelta" is the problem, but I am not sure what to do to fix it. So I am trying to write a program that will increment the value of the pin 3 a set amount of time, in a somewhat linear fashion, starting at my low point, and finishing at my high point. The issue is that my equation is incorrect and I can't output a partial bit value. Huge oversight on my part. If you read the data from the serial monitor with the code written as I have it, you'll see that it isn't coming even close to reaching my max value.

int motor1=3;//pin for PWM output to motor
float t=0; //Variable to keep Track of time
int tLim=30; //Time Limit for Ramp
float lowLim=21; //Low Limit, in Duty Cycle %
float highLim=65; //High Limit, in Duty Cycle %
float motorPWM=53.55; //Starting Value of PWM, in Bits
float pwmDelta=((255/100)*(highLim-lowLim))/(tLim); //Delta equation, to calculate how much to change PWM value each time it is incremented
float motorDelta; //Variable to write value to Motor Output

void setup() {
  // put your setup code here, to run once:
pinMode(motor1, OUTPUT);
analogWrite(motor1, 53.55); //run motor at initial value for 20 seconds before beginnning ramp
delay(20000);
Serial.begin(9600);
 
}

void loop() {
  (motorDelta=(motorPWM)+(pwmDelta)); //incrementing output value based on Delta Equation
  motorPWM=motorDelta; //Setting new incremented value equal to old value, so incrementing can continue

  if (t <=tLim)//Check if time is <= time limit
 
  {(analogWrite(motor1, (motorDelta))); //write incremented value to output pin
  delay(1000); //wait 1 second, increment t, to keep track of time
  t++;
  }
else {
  analogWrite(motor1, motorPWM=165.75); //set pin to high value for 60 seconds, then set to 0
  delay(60000);
  analogWrite(motor1, motorPWM=0);
}

 
Serial.print(motorDelta);
Serial.println();
Serial.print(t);
Serial.println();

 
}

First post here. So I have an issue, which I have identified, but I'm not quite sure how to fix it. I'd really appreciate some input and suggestions. I realize that my "pwmDelta" is the problem, but I am not sure what to do to fix it. 

I am trying to write a program that will increment the value of the pin 3 a set amount of time, in a somewhat linear fashion, starting at my low point, and finishing at my high point. 

The issue is that my equation is incorrect and I can't output a partial bit value. Huge oversight on my part. If you read the data from the serial monitor with the code written as I have it, you'll see that it isn't coming even close to reaching my max value.

int motor1 = 3;         //pin for PWM output to motor
float t = 0;            //Variable to keep Track of time
int tLim = 30;          //Time Limit for Ramp
float lowLim = 21;      //Low Limit, in Duty Cycle %
float highLim = 65;     //High Limit, in Duty Cycle %
float motorPWM = 53.55; //Starting Value of PWM, in Bits
float pwmDelta = ((255/100)*(highLim-lowLim))/(tLim); //Delta equation, to calculate how much to change PWM value each time it is incremented
float motorDelta;       //Variable to write value to Motor Output

void setup() {
  pinMode(motor1, OUTPUT);
  analogWrite(motor1, 53.55); //run motor at initial value for 20 seconds before beginnning ramp
  delay(20000);
  Serial.begin(9600);
}

void loop() {
  motorDelta = motorPWM + pwmDelta; //incrementing output value based on Delta Equation
  motorPWM = motorDelta; //Setting new incremented value equal to old value, so incrementing can continue

  if (t <= tLim) {  //Check if time is <= time limit
    analogWrite(motor1, (motorDelta)); //write incremented value to output pin
    delay(1000);  //wait 1 second, increment t, to keep track of time
    t++;
  }
  else {
    analogWrite(motor1, motorPWM = 165.75); //set pin to high value for 60 seconds, then set to 0
    delay(60000);
    analogWrite(motor1, motorPWM = 0);
  }
  Serial.print(motorDelta);
  Serial.println();
  Serial.print(t);
  Serial.println();
}
Source Link

Issue with incrementing PWM over time

First post here. So I have an issue, which I have identified, but I'm not quite sure how to fix it. I'd really appreciate some input and suggestions. I realize that my "pwmDelta" is the problem, but I am not sure what to do to fix it. So I am trying to write a program that will increment the value of the pin 3 a set amount of time, in a somewhat linear fashion, starting at my low point, and finishing at my high point. The issue is that my equation is incorrect and I can't output a partial bit value. Huge oversight on my part. If you read the data from the serial monitor with the code written as I have it, you'll see that it isn't coming even close to reaching my max value.

I need suggestions on how I can have the program figure out the delta in a way that I can send an integer value to the PWM output pin, yet still keep a somewhat linear increase over time. Would this even be possible?

int motor1=3;//pin for PWM output to motor
float t=0; //Variable to keep Track of time
int tLim=30; //Time Limit for Ramp
float lowLim=21; //Low Limit, in Duty Cycle %
float highLim=65; //High Limit, in Duty Cycle %
float motorPWM=53.55; //Starting Value of PWM, in Bits
float pwmDelta=((255/100)*(highLim-lowLim))/(tLim); //Delta equation, to calculate how much to change PWM value each time it is incremented
float motorDelta; //Variable to write value to Motor Output

void setup() {
  // put your setup code here, to run once:
pinMode(motor1, OUTPUT);
analogWrite(motor1, 53.55); //run motor at initial value for 20 seconds before beginnning ramp
delay(20000);
Serial.begin(9600);

}

void loop() {
  (motorDelta=(motorPWM)+(pwmDelta)); //incrementing output value based on Delta Equation
  motorPWM=motorDelta; //Setting new incremented value equal to old value, so incrementing can continue

  if (t <=tLim)//Check if time is <= time limit

  {(analogWrite(motor1, (motorDelta))); //write incremented value to output pin
  delay(1000); //wait 1 second, increment t, to keep track of time
  t++;
  }
else {
  analogWrite(motor1, motorPWM=165.75); //set pin to high value for 60 seconds, then set to 0
  delay(60000);
  analogWrite(motor1, motorPWM=0);
}


Serial.print(motorDelta);
Serial.println();
Serial.print(t);
Serial.println();


}