jswayze
- 20th March 2005, 03:21
Hello all,
I've run into a hardware challenge and could use some help from those more experienced than myself (so that includes about everyone :) ) It's a fairly complex project, so I'll try to distill it down to the part that's relevant to my question - bear with me though as I try to describe it.
My system has 8 outputs, each tied to an output pin on a 16F628. I'm currently using the internal RC oscillator at 4MHz to limit part count, but will use a 20MHz resonator if necessary. The output is pulses at variable rates and durations, all determined by constants in my PICBasic program.
I use an interrupt to increment a counter which is then referenced by the loop that controls each output port. For example, the loop is constantly running and checking the counter. If the counter reaches the "start time" value then an output will go high. When the counter reaches "start time"+"duration", the output goes low, then the counter for that output port is reset.
I have two input pins, each connected to a PWM source (an R/C receiver channel). Therefore each input can see pulses of between 1 and 2ms with about a 20ms period. The measured pulse widths can modify some of the timing values within the main routine.
Now the tricky part. Somehow I need to simultaneously check two PWM inputs AND reliably increment my clock variable at a pretty fast rate. The problem I see is that, since the pulse period is 20ms, I'll have to sit and wait up to 2*20= 40ms while PULSIN tries to find the pulse widths.
This would be all fine and good if I could increment my timer variable in steps of 40ms or more, but I'd like to be able to use a much finer resolution - like 5ms per increment.
Ideally I would like to see the PWM routines run in the background and, like the interrupt, simply fill a variable with the current pulse width. That way the main program loop only has to reference 3 variables: PWM1, PWM2, and timer.
Is there any technique to do what I want here? Am I misinterpreting the time that PULSIN takes to do its job? Is this actually more of a "multitasking" question?
As usual, *any* thoughts would be ever so helpful.
Thank you in advance,
Jeff
I've run into a hardware challenge and could use some help from those more experienced than myself (so that includes about everyone :) ) It's a fairly complex project, so I'll try to distill it down to the part that's relevant to my question - bear with me though as I try to describe it.
My system has 8 outputs, each tied to an output pin on a 16F628. I'm currently using the internal RC oscillator at 4MHz to limit part count, but will use a 20MHz resonator if necessary. The output is pulses at variable rates and durations, all determined by constants in my PICBasic program.
I use an interrupt to increment a counter which is then referenced by the loop that controls each output port. For example, the loop is constantly running and checking the counter. If the counter reaches the "start time" value then an output will go high. When the counter reaches "start time"+"duration", the output goes low, then the counter for that output port is reset.
I have two input pins, each connected to a PWM source (an R/C receiver channel). Therefore each input can see pulses of between 1 and 2ms with about a 20ms period. The measured pulse widths can modify some of the timing values within the main routine.
Now the tricky part. Somehow I need to simultaneously check two PWM inputs AND reliably increment my clock variable at a pretty fast rate. The problem I see is that, since the pulse period is 20ms, I'll have to sit and wait up to 2*20= 40ms while PULSIN tries to find the pulse widths.
This would be all fine and good if I could increment my timer variable in steps of 40ms or more, but I'd like to be able to use a much finer resolution - like 5ms per increment.
Ideally I would like to see the PWM routines run in the background and, like the interrupt, simply fill a variable with the current pulse width. That way the main program loop only has to reference 3 variables: PWM1, PWM2, and timer.
Is there any technique to do what I want here? Am I misinterpreting the time that PULSIN takes to do its job? Is this actually more of a "multitasking" question?
As usual, *any* thoughts would be ever so helpful.
Thank you in advance,
Jeff