• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microcontroller, Shift Register Array, and PWM

Status
Not open for further replies.

EvilGenius

Member
Hello Everyone:
I need ideas and possible help in PWM a shift register array. I will be using SPI data format and the data engine is produced by PIC16F628A. I am planning to use 3 pins of PORT A for my clock, data, and latch. (I have other near future plans for PORT B)

I have designed and built a 16 channel common anode RGB (48 bit) shift register array using TPIC6B595N. The system is buffered input and output with a pair of SN74HC245 (Buffers).

I am familiar with how to build a data engine in the micro, roll the data and communicate with the shift register array via SPI. I will be using a data table that can be modified and read during the program and passed on to the data engine.

The area I need help with is how to operate the data transfer in a PWM format for smooth transitions and color introduction. What is the best way to go about this? Are there short-cuts in using OE (Output enable) of the register to do the PWM across all the channels? Or does the PWM has to happen in bundles of data transfered?

Any help, guide, directions, pointing to previous posts/Treads, or pointing to a project that already utilizes PWM on registers will be very much appreciated. I have done several searches on the forum and could not find anything that would relate directly to what I am doing. Thank you in advance for your help, input, feedbacks, and suggestions

Regards,
Mike
 

KeepItSimpleStupid

Well-Known Member
Most Helpful Member
Mike:

I can't understand what you want to do, but check out the datasheet for a Linear Technology LT8500. It's a 48 channel PWM LED driver chip.
 

Gobbledok

Active Member
If you are using an output of the '595 as the PWM pin then you will have to send data whenever you want to toggle the PWM pin.

When you say operate the data transfer in a PWM format I assume you mean simply sending data at regular, timed intervals. To do this you would use a Timer and a Timer interrupt.

If you use the OE pin of the '595 to toggle the outputs, then you will also (assumedly) be toggling the BLANK input, SDO and SDI of the (I assume you are using) TLC5940. This will not work.

The best solution (and maybe the only one for speed and smooth transitions) is to use a pin from the microcontroller. If you do not have a spare one perhaps you should make one free :)


Edit: I realised that I misread your post and what you are trying to do. I will leave my old post above anyway. Perhaps you should look into Texas Instruments' TLC5940NT?
 
Last edited:

EvilGenius

Member
If you are using an output of the '595 as the PWM pin then you will have to send data whenever you want to toggle the PWM pin.

When you say operate the data transfer in a PWM format I assume you mean simply sending data at regular, timed intervals. To do this you would use a Timer and a Timer interrupt.

If you use the OE pin of the '595 to toggle the outputs, then you will also (assumedly) be toggling the BLANK input, SDO and SDI of the (I assume you are using) TLC5940. This will not work.

The best solution (and maybe the only one for speed and smooth transitions) is to use a pin from the microcontroller. If you do not have a spare one perhaps you should make one free :)


Edit: I realised that I misread your post and what you are trying to do. I will leave my old post above anyway. Perhaps you should look into Texas Instruments' TLC5940NT?
Hi Gobble:
Thank you for your response. At this time I am committed to use 595 registers. (6 of them data in, data out daisy-chained) I am using common clock, common latch. These 3 lines only burn up 3 pins of PORTA on 16F628A leaving me with an additional 3 pins free to ulitilize. I am not sure how to implement Timer and Timer interrupt (Hardware PWM) to modulate 48 channels. Instead I was suggesting to create a ramping (triangular wave) subroutine that would fade register outputs in and out while data was latched in each register. Then transfer another 48 bits in the registers, latch and ramp them again.

To do this I can think of couple of ways: 1) Latch data in registers, with an external high power CMOS ramp the anode feeds to RGB+ LED modules. 2) Latch the data in registers, then ramp the output enables (OE) of registers to fade the register outputs in and out.

Your suggested method of Timer Interupts is probabely the best if I knew how to PWM 48 channels. Additionally I am concerned about how much of additional code I need on the PIC to implement PWM on 48 channels. Your thoughts....
 

Gobbledok

Active Member
Basically, how I would do it (for 8-bit PWM):

Set up a timer interrupt and a register for each LED. Also a register for the timer.

On each interrupt you will increment the timer register and compare the timer register to each individual LED register. If the LED register is higher than the timer register, that particular LED will be on. Conversly if the timer register is higher than the LED register, then the LED will be off.

Doing it this way you will have to set up your interrupt at 256 (8 bits) x desired PWM frequency.
For example if you want your PWM frequency to be 100Hz, then you will have to set your timer to interrupt at 25.6KHz.

It's been a while since I have used that particular chip though so I can't help you on setting it up for interrupts.

Just make sure you have enough instruction cycles between each interrupt to get everything else done.
 
Last edited:

EvilGenius

Member
Gobble:
If I read your comments correctly I need to send data packets of 48 bits to the registers many times a second to produce PWM. Given that I have to cover a lot of bits many times a second I might elect to go with a lower resolution per each LED (Perhaps 4: off, low, medium, high) to speed up the process and allow myself to do other things in between those packets.
I have to read up a lot more on the datasheet and look at examples of PWM on 16F628A to achieve that. (my homework if I can find such examples)

Ultimate goal is to use PORT B of the micro to fetch data from a memory bank and enter received data in temporary working variables in "data engine". Then hand over the data to my PWM subroutine to put them out on the registers, latch them and repeat the cycle. I need to build my PWM engine to sync with data engine before I can go fetch data from the memory bank.

For now I need a 4 bit resolution, 48 channel PWM subroutine in assembly if you have any examples. (Or anything close to get me started)

Regards,
Mike
 

EvilGenius

Member
Update: Given limited available time I have to work on this project, I decided instead of learning hardware PWM from ground up to write my own software routine that would handle PWM for 48 channels. (16 RGB) If I am successful in implementing it I will gladly post my progress and final product.

Concept: First set of 48 bits (6 bytes) are entered into 6 primary variables. Second set of 48 (second color) is entered in 6 set of secondary variables. Writing a routine, the first 48 and second 48 bits are repeated in different proportions to achieve the desired mix hence fading smoothly from first set of colors to the next set of colors. The concept worked on 15 channel direct drive RGB and should work well with a bit of tweeking for SPI.

Example of software PWM:
call color1 5 times (48 bits), color2 0 times
call color1 4 times, color2 1 time
call color1 3 times, color2 2 times
so on until...
call color1 1 time, color2 4 times
call color1 0 times, color2 5 times
This subroutine will be integrated as part of data out routine to data line of shift registers, clocked and latched in between in set of data.
 

Mike - K8LH

Well-Known Member
Mike (EvilGenius),

Can you provide a schematic?

Are you multiplexing these sixteen displays?

Are you looking for individual PWM control of each LED (48 LEDs total)?

Cheerful regards, Mike
 

EvilGenius

Member
Mike (EvilGenius),

Can you provide a schematic?

Are you multiplexing these sixteen displays?

Are you looking for individual PWM control of each LED (48 LEDs total)?

Cheerful regards, Mike
Mike as you can see from the diagram posted, the registers are daisey chained direct driven via data, latch, clock bus lines. (No multiplexing)

I would like to have PWM of each LED modules (R, G, B) that would allow me to set individual color.



Regards, Mike
 

Mike - K8LH

Well-Known Member
The time it takes to load the shift registers with 48 bits of data is probably the biggest contributing factor for the number of PWM levels you can achieve at a particular refresh rate. For a 100 Hz refresh rate for example, you would need to be able to load the shift registers within 78.125 usecs (625 instruction cycles with a 32 MHz clock) for 128 PWM levels, or within 39.0625 usecs (312.5 cycles w/32 MHz clock) for 256 levels. Can you determine how many cycles your current method uses?

There are other methods available to load the shift registers much faster (26 cycles using bit banged parallel SPI, for example) but that would require seven I/O pins.

Good luck on your project... Happy Holidays!
 
Last edited:

EvilGenius

Member
The time it takes to load the shift registers with 48 bits of data is probably the biggest contributing factor for the number of PWM levels you can achieve at a particular refresh rate. For a 100 Hz refresh rate for example, you would need to be able to load the shift registers within 78.125 usecs (625 instruction cycles with a 32 MHz clock) for 128 PWM levels, or within 39.0625 usecs (312.5 cycles w/32 MHz clock) for 256 levels. Can you determine how many cycles your current method uses?
Mike I will try to answer your question the best I can. Correct me if I am wrong or if I need to take other factors in consideration. 100Hz referesh rate sounds about where I need to be to get good color brightness without flickering. I would limit total number of colors generated to 13 colors (Red, Orange, Yellow, Yellow-Green, Green, Teal, Aqua, Aqua-Blue, Blue, Purple, Violet, Pink, White). To achieve one color I would need 3 sets of 48 bits repeated 100 times (100Hz refresh rate). Total cycles of 300Hz. (3x100) Your thoughts...
Regards, Mike
 

EvilGenius

Member
Update and correction: To produce 13 colors, I only need two passes. (2 sets of 48 bits) At 100 Hz, I will be cycling @ 2x100 = 200 cycles per second.
Example of color generation (i.e.: Color Orange across all 16 RGB modules)
1st pass: 011 011 011 011 011 011 011 011 011 011 011 011 011 011 011 011
2nd pass: 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001
 
Last edited:

EvilGenius

Member
For those of you who would like to do this along with me or would like to pick a portion and contribute a portion of the code here is what I am planning to do in a systematic fashion:

PART1 ( DATA TABLE): Create a data table consisting of two 8 bits data sets to address 16 RGB. Each bit (Letter) designates a color on a specific RGB module.
R= red, O=orange, Y=Yellow, L=lime, G=green, T=teal, A=aqua, S=slate, B=blue, P=purple, M=magenta, F=fusia, W=white, N=null (black)
There are 14 colors in total.

Each data set represents one frame of the scanning all 16 RGB modules. Multiple frames will make up an entire effect or function.
Example of Data entries:

Table1 ;RAINBOW FX
B, P, M, F, R, O, Y, L ;(RGB9= BLUE, RGB10=PURPLE, RGB11=MAGENTA, RGB12=FUSHIA, RGB13=RED, RGB14=ORANGE, RGB15=YELLOW, RGB16=LIME)
R, O, Y, L, G, T, A, S ;(RGB1=RED, RGB2=ORANGE, RGB3=YELLOW, RGB4=LIME, RGB5=GREEN, RGB6=TEAL, RGB7=AQUA, RGB8=SLATE)
.
.
.
.
.
return
 

EvilGenius

Member
PART2 (PUT COLOR IN VARIABLES): Create 2 groups of variables. Group1 has six 8-bit variables translating letters from the first line of data table into individual bits for the first set of color (COLOR1).
Group2 is similar to Group one but rather reads the second line of the data table and puts it in another six 8-bit varaibles for COLOR2.
To produce 16 individual colors on 16 RGB, COLOR1 and COLOR2 are called in one after the other 100 times. This creates one entire frame.

This process is repeated for each two lines of data table and colors are placed in each additional frame. To create a smooth transition between frames, a software PWM is implemented.
Software PWM for Transitions: After calling Frame1 100 times to set the color1, we break the 100 cycles down in 4 sub-sections. Call Frame1 75 times-Frame2 25 times, call Frame1 50 times-call Frame2 50 times, call Frame1 25 times-call Frame2 75 times.

Now we are ready for introduction of Frame2 (Color2) and so on...
 
Last edited:

EvilGenius

Member
PART3 (bit generation for data input of shift registers): Each variable from PART2, one by one is rotated into carry (z), tested for 1 or 0, and put on data line of PORTA1. Clock data in, rotate bits one more in the same variable, and continue the process untill all 8 bits are rotated out and placed on data line of A1. Next grab the next varaible, and follow the steps above until all data is dumped into A1 and clocked in. Once the data on all six variables are dumped in and clocked in, we do a latch. To follow we do the same with the Group2 variables for color2 and complete above steps. This completes one frame. Remember we are looping each frame 100 times to set the colors. Otherwise the process is so fast that you will not see it.
 
Last edited:

EvilGenius

Member
Progress: Having a bit of time on my hand during the holidays, I was able to improve on both hardware and software layout. I decided to forgo creating a table in the PIC (Part1) and instead having a EEPROM chip feed the data in. The role of the Microcontroller is now to communicate with the EEPROM, fetch the data stream, enter them in package of 12 8-bit variables (Part2), then push the data out into shift registers (Part3). This prevents double handling of the data stream, expands available memory space for data needed, and overall speeds up the process. The EEPROM I elected to use is 25LC1024, 1Mbit SPI Serial EEPROM by Microchip(TM). Here is the modified schematics...
 

Attachments

Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top