vaka85
Advanced Member level 4
Hi all,
I'm trying to use pwm with the "bit banging" method. I know it's not very efficient, but it's a start..
The code below has a problem, and I'm not able to understand what it is...
I'd like to change the pwm value after some seconds, and so I start the pwm and after 5 seconds I call the function again, but with a different duty cycle value.
When I call the function "pwm start" without
it works fine.
But when I add the condition, pwm_start runs forever, without changing value and never ending, even if the IN4 goes off.
Could you give me any help? thank you
I'm trying to use pwm with the "bit banging" method. I know it's not very efficient, but it's a start..
The code below has a problem, and I'm not able to understand what it is...
I'd like to change the pwm value after some seconds, and so I start the pwm and after 5 seconds I call the function again, but with a different duty cycle value.
When I call the function "pwm start" without
Code:
if(count<500000){
But when I add the condition, pwm_start runs forever, without changing value and never ending, even if the IN4 goes off.
Could you give me any help? thank you
Code:
void pwm_start(long on, long off){
out3 = 1;
for (cntt=0; cntt< on;cntt++);
out3 = 0;
for (cntt=0; cntt< off;cntt++);
}
void main(void)
{
Ton = 2500; //2.5 ms
Toff = 2500; //2.5 ms
count=0;
while (1){
if( IN4 == 1) {
if(count<500000){
pwm_start(3800,1200);
count++;
} else {
pwm_start(4999,1);
}
} else {
count=0;
out3 = 0;
}
}
}