I am using a PIC for the first time. I would like to use C but a client wants it to be in Basic. So, here is what i have:
program Pwm_Demo
dim current_duty, old_duty, current_duty1, old_duty1 as word
pwm_period1, pwm_period2, i, hold as word
sub procedure InitMain()
ADPCFG = 0xFFFF ' initialize AN pins as digital
PORTB = 0 ' set PORTD to 0
TRISB = 0 ' designate PORTD pins as output
PPS_Mapping(11, _OUTPUT, _OC1) ' RPx pin mapping OC1 to pin 8
PPS_Mapping(10, _OUTPUT, _OC2) ' RPx pin mapping OC2 to pin 9
end sub
main:
InitMain()
current_duty = 16 ' initial value for current_duty
current_duty1 = 16 ' initial value for current_duty1
SetBit(PORTB, 8)
Delay_ms(100)
ClearBit(PortB, 8)
Delay_ms(100)
SetBit(PORTB, 8)
Delay_ms(100)
ClearBit(PortB, 8)
Delay_ms(100)
SetBit(PORTB, 8)
Delay_ms(100)
ClearBit(PortB, 8)
Delay_ms(100)
pwm_period1 = PWM_Init(5000 , 1, 1, 2)
pwm_period2 = PWM_Init(5000, 2, 1, 3)
PWM_Start(1)
PWM_Start(2)
PWM_Set_Duty(current_duty, 1) ' Set current duty for PWM1
PWM_Set_Duty(current_duty1, 2) ' Set current duty for PWM2
if hold = 0xFFFF then
While TRUE
SetBit(PORTB, 8)
Delay_ms(100)
ClearBit(PortB, 8)
Delay_ms(100)
wend
end if
i = 1
while (TRUE) ' endless loop
for current_duty = 0 to 300
PWM_Set_Duty(current_duty, 1) ' set newly acquired duty ratio
PWM_Set_Duty(current_duty, 2)
Delay_ms(5)
i = Not i
next current_duty
current_duty = 0
wend
end.
PWM output on OC1 works but not on OC2... any ideas?
Thanks,
rick