Hi all trying to make an LED Christmas tree light controller using a 16F1938 PIC, onlythe red channel has an output, what am I doing wrong?
'Christmas Tree Controller
'By E.V. LaBudde copyright 2016
'Christmas Tree Controller
'By E.V. LaBudde copyright 2016
#chip 16F1938, 32 'Chip model
#config WDT = On
#config FOSC_INTOSC
WDTCON = b'01010'Set Prescaler to 32768
PWMon
'Set Directions
Dir PortB.0 Out 'White
Dir PortC.2 Out 'Red
Dir PortC.1 Out 'Green
Dir PortC.6 Out 'Blue
Dir PORTA.0 Out 'LCD
'set defines
#define SendAHigh Set PORTA.0 On 'Note Polarity for 4X20 Newhaven display
#define SendALow Set PORTA.0 Off
#Define White PortB.0 'pin21
#Define Red PortC.2 'pin 13
#Define Green PortC.1 'pin 12
#Define Blue PortC.6 'pin 17
#Define LCD PORTA.0 'pin 2
Main:
HPWM white, 1 , 25
HPWM red, 1 , 50
HPWM green, 1 , 75
HPWM blue, 1 , 90
CLRWDT
PulseOut LCD, 1 us
Goto Main
Edited for Code Formatting - WR
Last edit: William Roth 2017-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William I tried it out but still only get a PWM siganl on channels 1 and 4. 2 and 3 no output. I have some more chips coming in case it is defective, Thanks, Ed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Syntax: HPWM channel, frequency, duty cycle
Command Availability: Only available on Microchip PIC microcontrollers with
Capture/Compare/PWM module.
you are using #Chip 16F1938,32
So the CCP Channels are:
RC2 -> CCP1
RB3 -> CCP2
RC6 -> CCP3
RB0 -> CCP4
So I suspect you are defining the wrong pins.
Cheers
Chris
Edit:
I see from the Datasheet that CCP2 and CCP3 are duplicated with the footnote:
Pin functions can be moved using the APFCON register, so you may need to set that too.
Last edit: Chris Roper 2017-11-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all trying to make an LED Christmas tree light controller using a 16F1938 PIC, onlythe red channel has an output, what am I doing wrong?
'Christmas Tree Controller
'By E.V. LaBudde copyright 2016
Edited for Code Formatting - WR
Last edit: William Roth 2017-11-27
You appear to be confusing PWM Channel with Port.Pin.
The channel can be either 1, 2,3,4 or 5.
So the correct syntax is:
William I tried it out but still only get a PWM siganl on channels 1 and 4. 2 and 3 no output. I have some more chips coming in case it is defective, Thanks, Ed.
From the Help:
you are using #Chip 16F1938,32
So the CCP Channels are:
RC2 -> CCP1
RB3 -> CCP2
RC6 -> CCP3
RB0 -> CCP4
So I suspect you are defining the wrong pins.
Cheers
Chris
Edit:
I see from the Datasheet that CCP2 and CCP3 are duplicated with the footnote:
Pin functions can be moved using the APFCON register, so you may need to set that too.
Last edit: Chris Roper 2017-11-29
Chris, it was a bad chip, got PWM outputs on
RC6 CCP3
RC2 CCP1
RC1 CCP2
RB0 CCP4
Thanks, Ed.