PDA

View Full Version : 12F629 PWM usage



MARAD75
- 9th November 2007, 15:48
Hi, I have a question that involves how PBP runs in a 12F629 which is basically not knowing how the program runs. (guess I can't think at 4 mhz!!) I am fairly experienced at writing code so it assembles properly, but don't know how certain things run - if that's possible!!!
When it does a goto a label, the first line in the label runs PWM (not HPWM) and outputs to a pin. There are additional lines in the label which do other things to a DIFFERENToutput.
Question: Does PBP run the PWM first and WAIT until it is finished before moving on to the additional lines to do them, or does it start running the PWM, then move on to these other things BEFORE FINISHING THE PWM?
Another way to put it is that I need to have these two things happening simultaneously on two separate outputs!
Example: The first pin is outputting a percentage output WHILE the other is flashing on and off.

PS I will put enough time in the PWM line to last until the other pin flashing is finished, then the code goes back, out of the label and will cancel everything. Also, the quality of the PWM is not important because it is driving an NPN which drives a mosfet, and only for about a minute - max. (the NPN makes it a pretty good square wave)
Is there another command I could use instead of if/goto to insure that the label doesn't wait for the PWM to finish before moving on, such as a while/wend?
Thanks for any help!
Ron

mister_e
- 9th November 2007, 16:35
PWM need to be finished before jumping to the next instruction. If you can deal with it, that great, unless you may need to use a Timer interrupt to produce your PWM or switch to the 12F683 which have a built-in PWM module.

Multitasking will be more than likely time slicing process, but fast enough to looks like multitasking. Once again Timer interrupts are pretty handy.

You can have a periodic timer interrupt and increase/decrease some variables in. Once you reach x value, then you enable/disable your i/os in the main program or in the ISR. But i usually prefer to do it in the mainloop when possible, keeping the ISR as short as possible.

MARAD75
- 10th November 2007, 13:21
Thanks Steve. I never thought of timer interrupts. However, I need to use the 12F629 and will try to set up some multitasking in this and let you know if I get it going.
Ron