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.

[AVR] MULTIPLE PATTERNS OF LEDs

Status
Not open for further replies.

ssquared

Junior Member level 3
Joined
Jun 6, 2015
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
213
I am working on a Project to control 22 TLC5971 LED derivers using Atmega1284p. I have written the code and tested for controlling each of the drivers in the chain and it is working well.

Now I want to modify the code so that I can control a group of drivers using different values of n. I have an idea to put the the Drivers in three groups and use a switch statement to change from one group to another.

I would appreciate if you can help me correct my code. My code is found below.

Code:
int main(void)
{
	
		usartSPI_init();
		static struct TLC5971 tlcarray[22];		/* Declare an array of 22 structure TLC5971 */
		struct TLC5971 *ptlc;					/* ptlc is a pointer to a structure */
		uint8_t i = 0; 
		uint8_t n = 2;
		
		

		// For Turning on 0*n 1*n 2*n 3*n drivers where number of drivers should be less than 22
				
		for (i=0; i<22; i+=n)
		{
			ptlc = &tlcarray[i];
			ptlc->BCR = 3;						
			ptlc->BCG = 3;
			ptlc->BCB = 3;
			ptlc->TMGRST = 1;
			ptlc->EXTGCK = 1;
			ptlc->cmd = 0x25;
	
			ptlc->GS[0][BLUE] = 0x1000;			// OUTB0
			ptlc->GS[0][GREEN] = 0x1000;		// OUTG0
			ptlc->GS[0][RED] = 0x1000;			// OUTR0
	
			ptlc->GS[1][BLUE] = 0x1000;			// OUTB1
			ptlc->GS[1][GREEN] = 0x1000;		// OUTG1
			ptlc->GS[1][RED] = 0x1000;			// OUTR1
	
			ptlc->GS[2][BLUE] = 0x1000;			// OUTB2
			ptlc->GS[2][GREEN] = 0x1000;		// OUTG2
			ptlc->GS[2][RED] = 0x1000;			// OUTR2
	
			ptlc->GS[3][BLUE] = 0x1000;			// OUTB3
			ptlc->GS[3][GREEN] = 0x1000;		// OUTG3
			ptlc->GS[3][RED] = 0x1000;			// OUTR3
				
		}
		for (uint8_t i = 0; i < 22; i++)
		{	
			CS_lo();
			sendBits(&tlcarray[i]);
			CS_hi();	
		}
					
		
		
		while (1)
		{
		
			for (uint8_t i = 0; i < 22; i++)
			{
				
				CS_lo();
				sendBits(&tlcarray[i]);
				CS_hi();	
			}
					
			// Stop SCKI at high or Low for 8 times the period between 224*N
			PORTD &= ~(1 << PD4);
			_delay_us(5);		// Atleast: 8*Period T + 1.34us
		
			// Send one SCKI clock with SDTI Low after 1.34us
			PORTD |= (1 << PD4);
			PORTD &= ~(1 << PD3);
		
			// OUTXn are Turned ON
			tlc5971.BLANK = 0;
					
		}	
							
		
}

Another idea is to use a for loop to turn on the Data pin ON and OFF. I have tried with this loop, but it is still not changing the pattern

Code:
for(uint8_t j = 0; j < 65535; j++)
		{
			//This turns Pin D3 ON and OFF : Turns D3 HIGH
			PORTD |=(1<<PD3);
			//PAUSE 1 Second
			_delay_ms(1000);
			//turns D3 LOW
			PORTD &= ~(1 << PD3);
			//PAUSE 1 Second
			_delay_ms(1000);
			
		}

Below is the complete code with the added loop

Code:
#include "usartSPI.h"
#include "tlc5971_poecie.h"
#include <avr/io.h>

void tlc5971_init()
{
	//tlc5971.BLANK = 1;
	//tlc5971.DSPRPT = 0;
	//tlc5971.TMGRST = 1;
	//tlc5971.EXTGCK = 1;
	//tlc5971.OUTTMG = 0;
	
}


// The sendBits() is used to send bits to address of the particular struct

void sendBits(struct TLC5971 *ptlc)			/* ptlc points to the struct TLC5971 */
{
	uint8_t n, *p = (uint8_t*)ptlc;			/* copy the structure pointed to by ptlc to the structure pointed to by p*/	
	
	for (n = 28; n-- > 0; )					/* Looping 28 times to send the 28 bytes for one LED driver  */
	{
		usartSPI_transfer(p[n]);			/* Using SPI to send each of the 28 bytes  */	
	}
	
}  


	
int main(void)
{
	
		usartSPI_init();
		static struct TLC5971 tlcarray[22];		/* Declare an array of 22 structure TLC5971 */
		struct TLC5971 *ptlc;					/* ptlc is a pointer to a structure */
		uint8_t i = 0; 
		uint8_t n = 2;
		
		

		// For Turning on 0*n 1*n 2*n 3*n drivers where number of drivers should be less than 22
				
		for (i=0; i<22; i+=n)
		{
			ptlc = &tlcarray[i];
			ptlc->BCR = 3;						
			ptlc->BCG = 3;
			ptlc->BCB = 3;
			ptlc->TMGRST = 1;
			ptlc->EXTGCK = 1;
			ptlc->cmd = 0x25;
	
			ptlc->GS[0][BLUE] = 0x1000;			// OUTB0
			ptlc->GS[0][GREEN] = 0x1000;		// OUTG0
			ptlc->GS[0][RED] = 0x1000;			// OUTR0
	
			ptlc->GS[1][BLUE] = 0x1000;			// OUTB1
			ptlc->GS[1][GREEN] = 0x1000;		// OUTG1
			ptlc->GS[1][RED] = 0x1000;			// OUTR1
	
			ptlc->GS[2][BLUE] = 0x1000;			// OUTB2
			ptlc->GS[2][GREEN] = 0x1000;		// OUTG2
			ptlc->GS[2][RED] = 0x1000;			// OUTR2
	
			ptlc->GS[3][BLUE] = 0x1000;			// OUTB3
			ptlc->GS[3][GREEN] = 0x1000;		// OUTG3
			ptlc->GS[3][RED] = 0x1000;			// OUTR3
				
		}
		for (uint8_t i = 0; i < 22; i++)
		{	
			CS_lo();
			sendBits(&tlcarray[i]);
			CS_hi();	
		}
					
		
		for(uint8_t j = 0; j < 65535; j++)
		{
			//This turns Pin D3 ON and OFF : Turns D3 HIGH
			PORTD |=(1<<PD3);
			//PAUSE 1 Second
			_delay_ms(1000);
			//turns D3 LOW
			PORTD &= ~(1 << PD3);
			//PAUSE 1 Second
			_delay_ms(1000);
			
		}
		
		while (1)
		{
		
			for (uint8_t i = 0; i < 22; i++)
			{
				
				CS_lo();
				sendBits(&tlcarray[i]);
				CS_hi();	
			}
					
			// Stop SCKI at high or Low for 8 times the period between 224*N
			PORTD &= ~(1 << PD4);
			_delay_us(5);		// Atleast: 8*Period T + 1.34us
		
			// Send one SCKI clock with SDTI Low after 1.34us
			PORTD |= (1 << PD4);
			PORTD &= ~(1 << PD3);
		
			// OUTXn are Turned ON
			tlc5971.BLANK = 0;
					
		}	
							
		
}
 

Hi,

When you want to control it in groups, then you need a special wiring .
I schematic would be helpful.


Klaus
 

Hi,

When you want to control it in groups, then you need a special wiring .
I schematic would be helpful.


Klaus

I don't think a special wiring is needed. I think it can be done with just the code such that some of the LEDS will be on at a particular time, then when they go off, others turn on. Since the LEDs are controlled by 22 TLC5971 LED drivers. This can be achieved by controlling the Drivers such that some chosen drivers are selected at some given time. The implementation is now the problem
 

Hi,

This can be achieved by controlling the Drivers such that some chosen drivers are selected at some given time.

I read the datasheet, but i can't find how to select a driver.
As far as i understand the datasheet there is a simple shift register, and if you connect all drivers in series like in thd datasheet, with a data transfer always all drivers are affected. But maybe i'm wrong...

Klaus
 

Hi,



I read the datasheet, but i can't find how to select a driver.
As far as i understand the datasheet there is a simple shift register, and if you connect all drivers in series like in thd datasheet, with a data transfer always all drivers are affected. But maybe i'm wrong...

Klaus

Hi Klaus,

Thanks for your reply. You are correct that all the drivers are affected but In my code I used a struct of 224 bits representing each TLC5971 of the 22 drivers, with this I can select the drivers with I want to turn on. So my goal now is to choose some of the drivers to turn on the LEDs connected to the outputs of this LED driver for some time, then when they turn OFF andother set of drivers are slected to to turn on the LEDs connected to their outputs.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top