Issue Ramping PWM signal for blower

Status
Not open for further replies.

mal

New member
Hello,

I am currently trying to run a PWM blower through a sequence of events using the following program. The program works fine up until the for loop where the PWM signal will ramp down as it is supposed to but the program will not run the next item in the sequence. After the first for loop the program just stops. Can somebody please assist. Thanks.

void setup() {

analogWriteResolution (12); //Sets the analog output of Duty cycle to be between 0 and 4095
analogWriteFrequency (22, 100); //Sets the frequency to be outputted
}

void loop() {

int rampdutydown; //Ramp Down Duty Cycle
int rampdutyup; //Ramp Up Duty Cycle

analogWrite (22, 0); //0% duty cycle
delay (600000); //10 minutes
analogWrite (22, 737.1); //18% duty
delay (1800000); //30 minutes
analogWrite (22, 1515.15); //37% duty
delay (1200000); //20 minutes
analogWrite (22, 2702.7); //66% duty
delay (1200000); //20 minutes
analogWrite (22, 3685); //90% duty cycle
delay (900000); //15 minutes

for (rampdutydown=3685; rampdutydown<=0; rampdutydown--) //90% to 0% duty cycle ramp
{
analogWrite (22, rampdutydown); //decrement duty cycle
delay (40.71);
}

analogWrite (22, 0); //0% duty
delay (300000); //5 minutes

for (rampdutyup=0; rampdutyup<=3685; rampdutyup++) //0% to 90% duty cycle ramp
{
analogWrite (22, rampdutyup); //increment duty cycle
delay (40.71);
}

analogWrite (22, 0); //90% duty cycle
delay (900000); //15 minutes

}

/*PWM lookup table

Decimal = PWM
4095 100%
3890 95%
3685 90%
3480 85%
3276 80%
3071 75%
2866 70%
2661 65%
2457 60%
2252 55%
2048 50%
1842 45%
1638 40%
1433 35%
1228 30%
1023 25%
819 20%
614 15%
409 10%
204 5%
0 0%

*/
 
I think your problem is at rampdutydown<=0, when you are actually trying to check if number is greater than zero. A check here is to Serial.println(rampdutydown) and see if you are getting the number progression you expect.

Edit - if serial.printing you will also need to add begin statement to activate Serial
 
Status
Not open for further replies.
Back
Top