Electronic – PIC18F1320 with 4 separate PWM channels and C18 compiler for an RGB LED

picpwm

I'm pretty new to microcontroller programming and I find the lack of documentation on certain features of PICs with C18 compiler frustating. I've been trying to make a simple 3-color-led light up using PWM for each channel but I can't seem to figure out how to use the ECCP enhanced PWM feature of PIC18F1320.

I've got a couple of other PIC18Fs (2550, 1320, 4450 to name a few) so trying other ones is an option, but I specifically got the 1320s because they had Enhanced PWM, Page 115 in the Datasheet.

I've got some code to slowly pulsate 1 led channel using normal PWM, I've attached it here. Im using the pwm.h include and its helper functions, but people have mentioned just setting the registers manually. Im confused as to how I would set the specific ones the manual mentions, they are in a format Im not used to, something like CCP1M<3:2> =/

I keep finding scraps of useful material out there and constantly learning about whats inside these things, so hopefully with your help i'll be able to make sense of all of this and make some basic code to light up this damn LED =D

Best Answer

Note that the PIC18F1320 still has only a single PWM module. This means you cannot have 3 independent PWM output signals. The '4 output signals' in the manual means that the PWM module can drive all 4 legs of a H-bridge with the proper timing - but the depend on each other (see figure 15-5 in the data sheet).

Regarding the register descriptions: CCP1M<3:2> means the bits 2 and 3 of the CCP1M select bits (these are actually 4 bits, but only the upper two ones are of interest there). The easiest way to set these registers is by using the register descriptions:

CCP1CONbits.CCP1M=42;

You can also use CCP1CON directly, but then you write all bits of this register directly.