Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] RGB LED circuit help PWM control - beginner

Status
Not open for further replies.
Thanks for the help guys. I was hoping the 12F675 would do what I wanted for the slave, primarily because of space considerations where some of these will go (this entire set up is going to illuminate displays and indicators, and I want to be able to have the indicators turn on and off separately, but have the same color set that the displays have).

The USART is what I was thinking, but I wanted to make sure I wasn't missing anything thinking that I could use the 675 for this and still have my 5 output channels. I should be able to simply transmit a change code throught he USART, and have the 675 simply look up the PWM values in it's own tables. I don't need the USART constantly transmitting.

Well, here's a crude block diagram, but it should make it clearer what I'm looking for. My initial intention is to run the 4 displays off the main board using a 6 wire cable and plug. Two of them will have approximately 10-12 LEDs of each color (RGBWY), and the other two will only have 2-3 of each. This would bring the total number of LEDs per channel to 22-30 running off the main PIC board. The indicators will all have only one single LED per channel, but they will all be switched separately, so they need to run off their own PIC. The selector switch (momentary) will simply cycle through the preset colors. This setting must be saved so that it does not have to be reset each time power is applied to the main circuit.

I hope this clarifies what I'm doing.

I'm considering not having the main circuit power any of the displays at all, and having them all run off the USART signal. Would this make more sense?
 

Attachments

  • RGB backlight system block diagram.bmp
    900.1 KB · Views: 111
Last edited:

It is possible to do it as in your diagram but you will have to be very careful with the software. The reason is that the 675 doesn't have PWM hardware or a USART. Both are relatively easy to emulate in software but bear in mind that you will be performing both emulations simultaneously and in real-time. Unless you are very careful, your program timing will change as serial data is received an processed and this will impact on the PWM timing and might cause the LEDs to flicker.

Brian.
 
I would like to avoid software PWM as much as possible for the reasons you suggest, but space is really the limiting factor in some of this. I'm going to see if I can manage to get a slightly larger circuit in there. The other possibility is that I make modules for multiple indicators where the PIC is triggered via inputs from the switch for each individual LED group.

You've helped me a lot. I've kind of brainstormed on here a bit, and I think I have a good direction to go. I've been studying up on the coding, and I am pretty sure I'll be able to get this running shortly. I just have to order up some PICs and a programming module and start experimenting.
 

Software PWM is easy, especially if you are prepared to use 8-bit resolution (256 levels) and that should be more than adequate for a lighting system. If you use a hardware USART it takes all the strain off the software, it simply tells you a byte has been received and you pick it up from the receive register.

This is the principle:
Use two registers per PWM channel, call one 'present' and the other 'target'. For each channel you need one output pin.
Use a single timer to periodically increment 'present', this is most easily done using a timer interrupt. Just keep counting forever and let the register roll over to zero when it reaches 0xFF.
If 'present' is zero, turn the output pin on.
If 'present' is equal to 'target'. turn the output pin off.

Simple as that!

For example if 'target' hold the value 20, the output pin will be on for counts zero to 20 and off for counts 21 to 255. The LED output is 20/255 of full brightness.
If 'target' was 128, the output would be on for counts zero to 128 and off for counts 129 to 255 so the LED would be at about half brightness.
If 'target' was 255, the LED would be constantly on giving full brightness.

All you need to do is update 'target' with a new value when one is sent over the serial link. For example, if you use two serial bytes, the first being an address and the second the target value you could send "55,128" to set LED number 55 to half brightness.

Brian.
 
The pwm sub sub I posted further back has been used with software rs232, and it operated at 4800 baud, as well as 4 channels of pwm, so you can do it.
You'd probably have to use interrupts though, the system I designed used tmr0 and interrupt on port change, and it worked well, there was some modulation of the display with the incomming data as the interrupts caused by the incomming data made the micro miss timer clock ticks, but if you bear this in mind it will still be fine, and as you say there wont be a continous stream of data.
Its a fairly demanding project as you need to think about 2 or 3 things that will be happening at once.
I reccomend creating your own stack to save the w reg and the status reg so dissapearing for an interrupt doesnt screw everything up, look at the data sheet for popping the status reg back off the 'stack', you have to swap nibbles so as not to affect the bits.
 
OK, I'm getting a decent grasp on this project, and I'm narrowing down how I'm doing it. What I plan on doing is running all of my LED circuits from a UART signal, rather than having some feed directly off the main circuit. This should simplify it so that I'm not having different ways of doing things within the same system.

I'm going to have a simple control circuit that will only send out a signal if a setting is changed, or if a module requests information (I think this should be fairly simple to set up).

For the PWM, I think I'll stick to the chip with the PWM function built in, due to the 5 channels I want to run. However, if I were to use something like a 12F675, and I ran a simple software PWM program, how high could I expect the PWM frequency to be with 5 channels of output?

---------- Post added at 08:20 ---------- Previous post was at 08:11 ----------

Cant really answer 1 as I dont get the question, and I've never used microchips on board pwm, is it single or multi channel?

Sorry, I forgot to respond to this when you posted it. Here is the section of code from the Microchips website example of using CCP2 as a PWM operation. This is the setup portion:
;Set up PWM module
;Set PWM period by writing to PR2
;Set PWM duty cycle by writing to the CCPR2L register
; and the CCP2CON<5:4>>bits
;Make the CCP2 pin an output by clearing the TRISC<2> bit.
clrf CCP2CON ;CCP module is off
bsf CCP2CON, CCP2M3 ;select PWM mode
bsf CCP2CON, CCP2M2 ;select PWM mode
movlw 0x3F ;Set PWM frequency to 78.12kHz
movwf PR2 ;
bcf TRISC, 1 ;make channel 1 an output
movlw 0x00
movwf CCPR2L
I was slightly confused by "movlw 0x3F, because the hex value translates to 63, but it says this sets the frequency at 78.12. If I am to understand how to control this, I need to understand the correlation between the numbers.
 

OK, I've studied up on using the onboard PWM, and in C it's very straight forward chosing frequency and setting the PWM up. I've come up with my design, and I'll post it here over the next few days with the program for critique. I'm going to start with a single unit setup to get it working, then I'll work on the communication between a controller and a satelite unit using a simple UART. I think I'm going to start with the 24FJ32GA002. I was going to go with a 16F, but for what I'm doing, I need the extra PWM channels of the 24F32. Using the onboard PWM on that frees up the processor quite a bit and simplifies the software. I've already ordered all the components I'll need.

Thanks for all of the help. I'm sure I'll need more as I get this going.

---------- Post added at 07:47 ---------- Previous post was at 07:36 ----------

quick question as I'm writing my code: for the array of preset colors, I'm thinking that it makes the most sense to use shorts (ie. red[1], green[1], blue[1], etc.), then just have the PWM values written from these based on the setting. Does this make sense, or would you suggest another way?
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top