How can I stop HPWM and then manually set the pin level?
I have built a frequency generator with a 16F88 to fake a speed source when working on farm equipment.
Originally I was manually calculating the period using 1000*1000, then DIV32 by my desired frequency to get my period in us and manually outputting the signal, but it takes too long at higher frequencies. I have since changed it to use my old output below 250Hz and HPWM above that. This works great when starting below 250Hz and transitioning up, but after it switches to HPWM and I come back down below 250Hz I can't control the pin manually anymore. I was stopping the output with HPWM 1,0,0 but the pin is stuck at 0 after that.
The only work around I have come up with so far is allowing the controller to reset itself at this transition point so that it starts fresh without HPWM active; however, I don't like this method.
Is there a way to completely stop the HPWM command, or am I going about this the wrong way?
Regards,
Gavin
Re: How can I stop HPWM and then manually set the pin level?
I did similar using this technique many years ago
HPWM 1,0,250
oPWM = 0
where oPWM is the hardware pin associated with the HPWM.
Re: How can I stop HPWM and then manually set the pin level?
You can set and reset pin using hpwm Ch,0,freq and hpwm Ch,255,freq.
Or just set CCPxCON to 0 and use portx or latx register.
Re: How can I stop HPWM and then manually set the pin level?
Quote:
Originally Posted by
pedja089
You can set and reset pin using hpwm Ch,0,freq and hpwm Ch,255,freq.
Or just set CCPxCON to 0 and use portx or latx register.
That was my initial thought, so I tried this:
HPWM 1, 255, 250 'Output high
PAUSEUS HPd 'for half the period
HPWM 1, 0, 250 'Output low
PAUSEUS (HPd-120) 'for other half, less ADCIN time
But the results were less than ideal. If I recall correctly I couldn’t get more than 140 Hz using this method. Without changing anything else in my code other than this:
PortB.0 = 1 'Output high
pauseus HPd 'for half the period
PortB.0 = 0 'Output low
Pauseus (Hpd-120) 'for other half, less ADCIN time
The output was smooth through the range.
I’ll try CCP1CON = 0
Thank you,
Gavin