Sorry to keep bothering you all but can anyone tell me how to get both HPWM channels working on a 16F877.
I get a pwm signal out of one channel but not the other. I have tried the declares listed below but no good.
My code is here.
@ Device pic16F877A, WDT_OFF, BOD_OFF, DEBUG_OFF , LVP_OFF, PROTECT_OFF, CPD_OFF, XT_OSC
include "Interrupter.bas"
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 7
Define LCD_EREG PORTC
Define LCD_EBIT 6
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
'DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
'DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
'DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
'DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
'DEFINE HPWM1_TIMER 1
'DEFINE HPWM2_TIMER 2
TRISC = %00000000
DUTY VAR WORD
T2CON=%00000100
PR2=1
DUTY=4
CCP1CON=%00001100 ' PWM MODE
CCP1CON.5=DUTY.1
CCP1CON.4=DUTY.0
CCPR1L=DUTY>>2
PlugOutput var portd.2
volts var word[2] 'to recieve the A2D value
PlugOn var byte
plugon = 0
low PlugOutput
INTCON.5 = 0
t1con.0 = 0
low portd.3
low portc.1
low portc.2
pause 500
main:
pause 100
lcdout $FE,1,"PWM Test:" ,#volts / 10, "." , #volts // 100
lcdout $FE, $C0, "Val = ", " : ", dec2 i_sec
'Run the glow plug for a set time
if portc.4 = 1 then
plugon = 1
i_sec = 0
endif
if plugon = 1 then
INTCON.5 = 1
t1con.0 = 1
endif
if i_sec >= 10 then
intcon.5 = 0
t1con.0 = 0
plugon = 0
i_sec = 0
low PlugOutput
low portd.3
endif
call SetVoltage1
call SetVoltage2
call SetVoltage3
'pause 100
goto main
SetVoltage1: '5vDc out put control (Gyro and Tail servo)
input porte.2
ADCON1 = 2 ' PORTA is analog
pause 50
ADCIN 7, volts ' Read channel 7 to variable Volts
volts = (volts * 1000)/((256 / 5)*10)
'if volts > ReqVolts1 then duty1 = duty1 - 1
'if volts < ReqVolts1 then duty1 = duty1 + 1
HPWM 1, 25, 200 'Channel1, duty cycle%, 2kHz
return
SetVoltage2: '5 to 7 vDc out put control (RX and other servos)
input porte.1
ADCON1 = 2
pause 50
ADCIN 6, volts
volts = (volts * 1000)/((256 / 5)*10)
'if volts > ReqVolts2 then duty2 = duty2 - 1
'if volts < ReqVolts2 then duty2 = duty2 + 1
HPWM 2, 50, 200
return
SetVoltage3: '1.2 vDc out put plug
input porte.0
ADCON1 = 2
pause 50
ADCIN 5, volts
volts = (volts * 1000)/((256 / 5)*10)
'if volts > PlugVolts then duty3 = duty3 - 1
'if volts < PlugVolts then duty3 = duty3 + 1
return
Bookmarks