PWM don`t stop.
dar
Posts: 15
Hi again!:
I'm trying to work with a pwm signal, but i have a problem, the pwm start and works right, but when i go out the loop and i want to stop the pwm signal, it don't stop.
This is the code i'm using, i don't know where can i have a mistake:
Thanks
I'm trying to work with a pwm signal, but i have a problem, the pwm start and works right, but when i go out the loop and i want to stop the pwm signal, it don't stop.
This is the code i'm using, i don't know where can i have a mistake:
PUB CONTROL_LUMINARIA LEER_ADC debug.str(string("voltaje_panel:")) debug.str(ftos.FloatToString(voltios_panel)) debug.NewLine repeat while voltios_panel<15.0 pwm.start(mos_luminaria) 'Inicializamos el pwm en el mosfet pwm.SetPeriod(100000) debug.NewLine pwm.setduty(potencia1) LEER_ADC pwm.stop
Thanks
Comments
To make sure the PWM stops you could set the PWM to zero before calling stop.
Still, It would be good to know which object you're using.
I had this same problem yesterday, I'm not sure yet if the problem was my code of if for some reason the counters stay active even when a cog is stopped.
FYI, I was using Kye's "PWM2C_HBDEngine.spin". I'm inclined to suspect the problem was with my code, not Kye's object.
pwmAsm.spin
and the instruction to stop is that.
I'm not sure, but if you changed the following Start method from:
To:
It would allow the stop method to work correctly.
I don't understand what the author was doing with " > 0" part in the original code. I'm also not sure if the code above is from the same object you're using.
Sorry for my confusion but doesn't cog get assigned the cog # plus one? So, you'd need to make sure the cogstop call is done correctly (see same page191 example)
You're right, I missed the lack of a "-1" in the cogstop call. If the change I suggested is used, then the change shimniok suggested would also be needed.
I tryed to change that, but i couldn't do it works.
I download other object:
"PWM_32_V4"
It works fine.
Thanks for yours suggentions!
The bug in pwm object is, that it does not check whether it's already running and stop the other instace before. This way the driver looses information of all but the last started COG and can only stop this last one letting all others run and still generate the PWM.