That was what I was thinking. I could have an infinite loop containing a few pin high/pin low commands, and a pause command, where the pause variable is set in the interrupt routine.
yep it could be this. You can use interrupt for port pin level change for that... surely. A little problem may happen... latency to answer to interrupt. In this case, you'll fix it really simple using a loop delay let' say with PAUSEUS 10... about 10Usec.
Here's a simple snippet to explain.
Code:
main:
......
Frequency=250 ;have 250Hz as frequency
Period_Delay_ms=1000 / frequency ;calculate period delay
Half_Period_ms=Period_Delay_ms/2 ;calculate half period delay
gosub PseudoPWM
.....
PseudoPWM:
For a=0 to Half_Period_ms
For b=0 to 100
HIGH PORTB.0
PAUSEUS 10
Next
next
For a=0 to Half_Period_ms
For b=0 to 100
LOW PORTB.0
PAUSEUS 10
Next
next
return
in the above, if any interrupt happen in the PseudoPWM, it will be answer in *about* 10 Usec
for frequency acurracy you'll have to measure the frequency out regarding the frequency you're suppose to have with your delay and play with PAUSE delay, NAP or @NOP to fine tune the error percentage. Once it's done everything will work just fine.
regards
Last edited by mister_e; - 16th November 2004 at 16:39.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks