Am I at all close? I can get it to compile without it but adding a
"For HPWMFREQ2 leaves me in the dark as two FOR NEXT loops is not correct but both timers need to change frequency at the same time. Thanks again to the best support group I've ever known!
DEFINE LOADER_USED 1
DEFINE ONINT_USED 1
DEFINE OSC 10
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port pin 17 rc2 ccp1
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE ADC_BITS 12 ' Set number of bits in result 8-10-12
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 500 ' Set sampling time in microseconds
HPWMFREQ VAR WORD
HPWMFREQ2 VAR WORD
DUTY VAR BYTE
DUTY2 VAR BYTE
CNTRL var word 'ADC BEGINNING SAMPLE
TST var word 'ADC COMPARISON SAMPLE
HPWMFREQ=1500 'CURRENT FREQUENCY OF HPWM
HPWMFREQ2=3000 'CURRENT FREQUENCY OF HPWM
CNTRL=0 'ADC CONTROL
TST=0 'ADC TEST SAMPLE
TRISA = 255 'ADC Set PORTA to all input
ADCON1 = 2
BEGIN:
hpwm 1,DUTY, HPWMFREQ
HPWM 2,DUTY2,HPWMFREQ2 'OR HPWMFREQ/2?
ADCIN 0, CNTRL
For HPWMFREQ = 1500 To 2000 Step 100
'FOR HPWMFREQ2=3000 to 4000 Step 200
DUTY=65
DUTY2 = 65
HPWMFREQ=HPWMFREQ+1
HPWMFREQ2=HPWMFREQ2+1
ADCIN 0, CNTRL
ADCIN 0, TST
IF TST < CNTRL THEN
HPWMFREQ=HPWMFREQ +1
HPWMFREQ2=HPWMFREQ2+1
Endif
ADCIN 0, TST
if TST >= CNTRL then
HPWMFREQ=HPWMFREQ +1
HPWMFREQ2=HPWMFREQ2+1
ENDIF
NEXT HPWMFREQ
goto BEGIN:
end
But does it mean that the chips with three pwm's need to be the same frequency? I'll try it in the simulator then run it on the chip Thanks much for your time! Emmett
Hi group, The PBP manual says that the highest frequency at the HPWM's at any oscillator speed is 32767Hz. Is this correct? I'm looking for 48Khz. Also It says that if two are used they have to be the same frequency. The same frequency if I use three? Don't understand the limitations. Thanks again all! Emmett
BTW @48MHZ, the highest frequency possible by using the calc should be 'round 5 MHZ (even if i have some doubt), 32.xxxKHZ is really low.
HPWM is certainelay limited. To avoid this limitation, you have to write to the CCP register.
Here's a short code snip for 2.5MHZ @ 50% duty cycle on a 16F877.
Bookmarks