brid0030
- 3rd February 2013, 19:14
I've got an existing/working device on which I need to implement a simple temporary pulse series using the hardware PWM. I'm trying to use the HPWM command to no avail. The device is a 28-pin PIC18F25K22, and I need to have the pulse on either PORTB.2 or PORTB.3. According to the datasheet, PWM should be possible on both of these pins, but there is so much multiplexing and enhancing on this device, that I think my problem lies in setting registers correctly for HPWM to work.
Here's the relevant code that does not work.
....
define CCP1_REG PORTB
define CCP1_BIT 2
....
HPWM 1,200,2
PAUSE 5000
CCP1CON = %00000000 'turns off PWM
High PORTB.2 'Test port connection with LED
pause 50
low PORTB.2
'pause 50
The last bit flashes an LED on PORTB.2 as it should. But I see nothing resulting from the HPWM command. Anybody got a clue for the registers on this pic? By the way, I've tried various permutations to do the pulses manually:
'TRISB = %00000000
'CCPTMRS0 = %00000000
'PR1 = %00000111
'CCP2CON = %00001100 'define lsb of duty cycle. make PWM move high PxA and high PxB
'CCPR1L = %00011111 'duty cycle MSB
'T2CON = %00000101 'set prescaler and turn on PWM
'TRISB = %00000000
Can't get this to work either. I just don't get this datasheet I'm afraid. Thanks for any help.
Here's the relevant code that does not work.
....
define CCP1_REG PORTB
define CCP1_BIT 2
....
HPWM 1,200,2
PAUSE 5000
CCP1CON = %00000000 'turns off PWM
High PORTB.2 'Test port connection with LED
pause 50
low PORTB.2
'pause 50
The last bit flashes an LED on PORTB.2 as it should. But I see nothing resulting from the HPWM command. Anybody got a clue for the registers on this pic? By the way, I've tried various permutations to do the pulses manually:
'TRISB = %00000000
'CCPTMRS0 = %00000000
'PR1 = %00000111
'CCP2CON = %00001100 'define lsb of duty cycle. make PWM move high PxA and high PxB
'CCPR1L = %00011111 'duty cycle MSB
'T2CON = %00000101 'set prescaler and turn on PWM
'TRISB = %00000000
Can't get this to work either. I just don't get this datasheet I'm afraid. Thanks for any help.