LusoRobótica - Robótica em Português

Robótica => Discussão geral sobre robótica => Tópico iniciado por: LuísR.A. em 04 de Junho de 2014, 19:34

Título: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 04 de Junho de 2014, 19:34
Ora boas caros colegas da lusorobotica, já algum tempo que nao aparecia cá

Venho de volta pedir-vos a quem ja me ensinou tanto mais um pouco de ajuda.

Bem entao eu decidi fazer um projecto com o driver de LEDs TLC5940/TLC5941.
Andei a ler a datasheet e decidi fazer um teste ainda sem usar o SSI do meu uControlador so para ver o seu funcionamento.
Basicamente fiz um codigo usando delays e outputs digitais, tendo este um clock de frequencia mt baixo.
Pois mas entao nao funciona nada, nenhum LED liga.

Estou ciente que isto não é a melhor (senao a pior) forma de controlar este driver mas se entedi o modo de funcionamente do TLC5940, isto deveria funcionar

uControlador usado: Tiva launchpad da Texas Instruments

Liguei:
TEST a VCC
MODE a VCC
IREF com resistencia 1k a GND
CLK, XTAL, BLANK, SIN  a pin digital do uControlador
GSCLK a pin PWM do uControlador


O pseudo codigo é:

Dá sempre sinal HIGH ao pin SIN do TLC5940.
Tem sempre um sinal de PWM a 50% de duty.
Pulsa 192 vezes o CLK
Liga a HIGH o pin BLANK e rapidamente logo a seguir o pin XTAL (tambem HIGH)
Desliga o XTAL e seguidamente o BLANK

sempre assim.



Pergunta, é necessário fazer dot correction antes?
Que poderei estar a fazer mal?
Agradecia qualquer ajuda de quem ja teve experimencia com este driver
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: senso em 04 de Junho de 2014, 21:13
Isso é um chip que precisa de muita atenção para funcionar correctamente, posso meter aqui o código que fiz para trabalhar com um atmega328p, numas matrizes de leds RGB de 4x4 que fiz.
Aconselho a ler isto, que tenho ideia que já postei num tópico teu sobre o assunto....
https://sites.google.com/site/artcfox/demystifying-the-tlc5940

Lê o PDF de ponta a ponta, depois lê o código, o meu é baseado nesse, mas com algumas alterações.

Não, o GS não é preciso para o chip funcionar, é preciso sim fazer reset ao GSCKL a cada 4096 transições.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 04 de Junho de 2014, 22:42
Isso é um chip que precisa de muita atenção para funcionar correctamente, posso meter aqui o código que fiz para trabalhar com um atmega328p, numas matrizes de leds RGB de 4x4 que fiz.
Aconselho a ler isto, que tenho ideia que já postei num tópico teu sobre o assunto....
https://sites.google.com/site/artcfox/demystifying-the-tlc5940

Lê o PDF de ponta a ponta, depois lê o código, o meu é baseado nesse, mas com algumas alterações.

Não, o GS não é preciso para o chip funcionar, é preciso sim fazer reset ao GSCKL a cada 4096 transições.

Obrigado, por acaso tinha esperanças de vires cá tu que lembro-me de falares de usares este chip.

Sim entao vou tentar criar um interrupt com o PWM do timer.

Depois digo como correu
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 04 de Junho de 2014, 23:18
Podes me dizer uma coisa? Para gerar o interrupt dos steps do PWM tiveste de usar outro timer sincronizado? Parece se um problema usar o interrupt de um timer tendo ja estado configurado para PWM


A melhor solução para mim que arranjei foi uma porta ligado ao PWM com um interrupt rising edge
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: senso em 05 de Junho de 2014, 01:08
Supondo que isso tem timers muito mais flexiveis que os do atmega, é simplesmente gerar um compare timer interrupt a cada 4096 ciclos do timer que está a gerar o clock, nada mais, nada menos.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 05 de Junho de 2014, 01:20
Supondo que isso tem timers muito mais flexiveis que os do atmega, é simplesmente gerar um compare timer interrupt a cada 4096 ciclos do timer que está a gerar o clock, nada mais, nada menos.

Até agora nao consegui ver como configurar para isso. Vou pesquisar melhor mas por agora terá de servir.

A questão é que eu para gerar PWM estou so mesmo a usar o timer, não é modulo PWM. Eu divido um timer de 32bits em 2 de 16bits
Vou ver se será possivel pelo menos com a outra metade
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 05 de Junho de 2014, 23:43
Então continuo sem sucesso em sequer ligar um LED. E não estou certo porque.

Tenho o SIN sempre a 1.

Tenho um timer a executar o PWM para o GSCLK e outro a gerar um CLK. Está feito para que quando acabe o seu ciclo (de 4096 e 192 steps respetivamente), que espere que o outro acabe, estão de modo a que este tempo de espera seja o minimo possivel.

Ai depois de terem ambos feito esses cliclos, simplesmente:
Ligo BLANK
Ligo XTAL
Desligo XTAL
Desligo BLANK

Isto tudo com um delay(1); entre eles


há algo que me esteja a esquecer para o funcionamento do microcontrolador?
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: StarRider em 06 de Junho de 2014, 00:00
Então continuo sem sucesso em sequer ligar um LED. E não estou certo porque.

Tenho o SIN sempre a 1.

Tenho um timer a executar o PWM para o GSCLK e outro a gerar um CLK. Está feito para que quando acabe o seu ciclo (de 4096 e 192 steps respetivamente), que espere que o outro acabe, estão de modo a que este tempo de espera seja o minimo possivel.

Ai depois de terem ambos feito esses cliclos, simplesmente:
Ligo BLANK
Ligo XTAL
Desligo XTAL
Desligo BLANK

Isto tudo com um delay(1); entre eles


há algo que me esteja a esquecer para o funcionamento do microcontrolador?

Esperar como ? Dentro do interrupt do timer ? Num ciclo em que é controlado o contador do timer ?
Sem ver código é estar a dar palpites para o ar.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 06 de Junho de 2014, 00:09
Então continuo sem sucesso em sequer ligar um LED. E não estou certo porque.

Tenho o SIN sempre a 1.

Tenho um timer a executar o PWM para o GSCLK e outro a gerar um CLK. Está feito para que quando acabe o seu ciclo (de 4096 e 192 steps respetivamente), que espere que o outro acabe, estão de modo a que este tempo de espera seja o minimo possivel.

Ai depois de terem ambos feito esses cliclos, simplesmente:
Ligo BLANK
Ligo XTAL
Desligo XTAL
Desligo BLANK

Isto tudo com um delay(1); entre eles


há algo que me esteja a esquecer para o funcionamento do microcontrolador?

Esperar como ? Dentro do interrupt do timer ? Num ciclo em que é controlado o contador do timer ?
Sem ver código é estar a dar palpites para o ar.

dentro do interrupt so tenho controlo de variaveis.

Eu posto o codigo, qualquer duvida sobre as funçoes do api so perguntarem

Código: [Seleccione]
#include "inc/hw_ints.h"
#include "driverlib/interrupt.c"
#include "driverlib/sysctl.c"
#include "driverlib/Timer.c"


#include"inc/tm4c123gh6pm.h"

#define XLAT GPIO_PORTF_BASE, GPIO_INT_PIN_3
#define BLANK GPIO_PORTF_BASE, GPIO_INT_PIN_1

uint32_t  contaPWM =0;
uint32_t  contaCLK =0;
void setup()
{

  IntPrioritySet(INT_TIMER0B,0xE1);
  IntPrioritySet(INT_TIMER1A,0xE0);

  //pinMode(PF_3,OUTPUT);
  // put your setup code here, to run once:
  PWMoutInit();
  CLKInit();
}

void loop()
{
  // put your main code here, to run repeatedly:
  if( (contaPWM == 4096) && (contaCLK == 192) ){
    GPIOIntClear(BLANK); //MUITO necessário para resetar a flag de interrupt
    delay(1);
    GPIOIntClear(XLAT); //MUITO necessário para resetar a flag de interrupt
    GPIOIntClear(XLAT); //MUITO necessário para resetar a flag de interrupt
    delay(1);   
    GPIOIntClear(BLANK); //MUITO necessário para resetar a flag de interrupt
    delay(1);   
  }


}


void CLKInit(){

  //Configurar porta F3: Ligar GPIO, Definir bit 2 como output
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
  // 
  unsigned long ulPeriod, dutyCycle;
  ulPeriod = 5000; // 16 Khz
  dutyCycle = ulPeriod/2; // dutyCycle é o tempo que fica a 0

  // Configure PB4 as T1CCP0
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);   
  GPIOPinConfigure(GPIO_PB4_T1CCP0);             
  GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4); 
  //

  // Configure timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);                       
  TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);   
  TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1);                     
  TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle); // PWM   

  //Configura Interrupt no timer
  TimerIntRegister(TIMER1_BASE,TIMER_A,CLKint);
  TimerControlEvent(TIMER1_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
  TimerIntEnable(TIMER1_BASE,TIMER_CAPA_EVENT);

  //Liga PWM 
  TimerEnable(TIMER1_BASE, TIMER_A);
  // 


}
void PWMoutInit(){

  //Configurar porta F3: Ligar GPIO, Definir bit 3 como output
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
  //


  unsigned long ulPeriod, dutyCycle;
  ulPeriod = 1000; // 80 Khz
  dutyCycle = ulPeriod/2; // dutyCycle é o tempo que fica a 0

  // Configure PB7 as T0CCP1
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);   
  GPIOPinConfigure(GPIO_PB7_T0CCP1);             
  GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7); 
  //

  // Configure timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);                       
  TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);   
  TimerLoadSet(TIMER0_BASE, TIMER_B, ulPeriod -1);                     
  TimerMatchSet(TIMER0_BASE, TIMER_B, dutyCycle); // PWM 

  //Configura Interrupt no timer
  TimerIntRegister(TIMER0_BASE,TIMER_B,BLANKint);
  TimerControlEvent(TIMER0_BASE,TIMER_B,TIMER_EVENT_POS_EDGE);
  TimerIntEnable(TIMER0_BASE,TIMER_CAPB_EVENT);

  //Liga o PWM
  TimerEnable(TIMER0_BASE, TIMER_B);
  //
}

void CLKint(){

  if(contaCLK < 192){
    contaCLK++;
  }
  else {
    TimerDisable(TIMER1_BASE, TIMER_A);
  }

  TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT);    // Clear TIMER_CAPA_EVENT immediately. 

}
void BLANKint(){

  if(contaPWM < 4096){
    contaPWM++;
  }
  else {
    TimerDisable(TIMER0_BASE, TIMER_B);
  }
  TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);    // Clear TIMER_CAPB_EVENT immediately.
}


Título: Re: TLC5940 - Como por a funcionar?
Enviado por: jm_araujo em 06 de Junho de 2014, 00:15
Lendo por alto a datasheet e uns documentos na net (http://flipmu.com/files/2011/04/Demystifying-the-TLC5940.pdf (http://flipmu.com/files/2011/04/Demystifying-the-TLC5940.pdf)), não te esqueceste de ligar o VPRG à GND?

Edit:
Estava a ler a datasheet do TLC5940, reparei agora que pelo nome dos pinos, estás a usar o TLC5941. Nesse caso não devias ligar o MODE à GND (modo GS- GrayScale PWM). Ligado ao VCC estás em modo DC (Dot Correction)
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 06 de Junho de 2014, 00:32
Lendo por alto a datasheet e uns documentos na net (http://flipmu.com/files/2011/04/Demystifying-the-TLC5940.pdf (http://flipmu.com/files/2011/04/Demystifying-the-TLC5940.pdf)), não te esqueceste de ligar o VPRG à GND?

Edit:
Estava a ler a datasheet do TLC5940, reparei agora que pelo nome dos pinos, estás a usar o TLC5941. Nesse caso não devias ligar o MODE à GND (modo GS- GrayScale PWM). Ligado ao VCC estás em modo DC (Dot Correction)

Na verdade estou ate a usar o TLC5940. Eu é que pensava que tinha o TLC5941 e fiquei com esses nomes na cabeça.
Tenho quase a certeza que liguei tudo bem mas vou ver se volta ligar tudo de novo e verificar com o multimetro de nao ha fios partidos
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: jm_araujo em 06 de Junho de 2014, 00:34
Chamei a atenção porque no início do tópico disseste:
Liguei:
MODE a VCC
E se for assim não vai funcionar.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 06 de Junho de 2014, 00:39
Chamei a atenção porque no início do tópico disseste:
Liguei:
MODE a VCC
E se for assim não vai funcionar.

queres ver que sou uma besta quadrada? -.-

Obrigado pelo reparo quando puder vou tentar fazer as ligaçoes todas de novo
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: jm_araujo em 06 de Junho de 2014, 00:58
Que exagerado :D

Antes de refazer todas as ligações, troca só o MODE e corre o código. Se era esse o erro vês logo resultados ;)
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: senso em 06 de Junho de 2014, 03:21
No pdf que deixei tem um esquema e tudo..
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 06 de Junho de 2014, 12:50
No pdf que deixei tem um esquema e tudo..

Eu sei, eu sei. Tive a ler e tudo e as ligações até era algo que nem tinha grandes duvidas mas pelos vistos fiz asneira (vamos a ver ainda se nao me enganei foi a escrever ca)
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 07 de Junho de 2014, 00:29
Bem... ligações estao todas bem e o codigo tb me parece que esteja

Código: [Seleccione]
#include "inc/hw_ints.h"
#include "driverlib/interrupt.c"
#include "driverlib/sysctl.c"
#include "driverlib/Timer.c"
#include"inc/tm4c123gh6pm.h"

#define XLAT GPIO_PORTF_BASE, GPIO_PIN_3
#define XLATon GPIO_PIN_3
#define XLAToff 0x04

#define BLANK GPIO_PORTF_BASE, GPIO_PIN_1
#define BLANKon GPIO_PIN_1
#define BLANKoff 0x01

uint32_t  contaPWM =0;
uint32_t  contaCLK =0;
void setup()
{
  IntPrioritySet(INT_TIMER0B,0xE1);
  IntPrioritySet(INT_TIMER1A,0xE0);

  PWMoutInit();
  CLKInit();
}

void loop()
{
  // put your main code here, to run repeatedly:
  if( (contaPWM == 4096) && (contaCLK == 192) ){
    GPIOPinWrite(BLANK,BLANKon); //Liga BLANK
    delay(1);
    GPIOPinWrite(XLAT,XLATon); //Liga XTAL
    delay(1);
    GPIOPinWrite(XLAT,XLAToff); //Desliga XTAL
    delay(1);   
    GPIOPinWrite(BLANK,BLANKoff); //Desliga BLANK

    contaPWM=0;
    contaCLK=0;
    TimerEnable(TIMER1_BASE, TIMER_A);
    TimerEnable(TIMER0_BASE, TIMER_B);
  }
}


void CLKInit(){

  //Configurar porta F3: Ligar GPIO, Definir bit 2 como output
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
  // 
  unsigned long ulPeriod, dutyCycle;
  ulPeriod = 4000; // 20 Khz
  dutyCycle = ulPeriod/2;

  // Configure PB4 as T1CCP0
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);   
  GPIOPinConfigure(GPIO_PB4_T1CCP0);             
  GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4); 
  //

  // Configure timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);                       
  TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);   
  TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1);                     
  TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle); // PWM   

  //Configura Interrupt no timer
  TimerIntRegister(TIMER1_BASE,TIMER_A,CLKint);
  TimerControlEvent(TIMER1_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
  TimerIntEnable(TIMER1_BASE,TIMER_CAPA_EVENT);

  //Liga PWM 
  TimerEnable(TIMER1_BASE, TIMER_A);
  // 


}
void PWMoutInit(){

  //Configurar porta F3: Ligar GPIO, Definir bit 3 como output
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
  //


  unsigned long ulPeriod, dutyCycle;
  ulPeriod = 200; // 400 Khz
  dutyCycle = ulPeriod/2;

  // Configure PB7 as T0CCP1
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);   
  GPIOPinConfigure(GPIO_PB7_T0CCP1);             
  GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7); 
  //

  // Configure timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);                       
  TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);   
  TimerLoadSet(TIMER0_BASE, TIMER_B, ulPeriod -1);                     
  TimerMatchSet(TIMER0_BASE, TIMER_B, dutyCycle); // PWM 

  //Configura Interrupt no timer
  TimerIntRegister(TIMER0_BASE,TIMER_B,BLANKint);
  TimerControlEvent(TIMER0_BASE,TIMER_B,TIMER_EVENT_POS_EDGE);
  TimerIntEnable(TIMER0_BASE,TIMER_CAPB_EVENT);

  //Liga o PWM
  TimerEnable(TIMER0_BASE, TIMER_B);
  //
}
void CLKint(){

  if(contaCLK < 192){
    contaCLK++;
  }
  else {
    TimerDisable(TIMER1_BASE, TIMER_A);  //desliga timer que gera PWM para CLK
  }

  TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT);    // Clear TIMER_CAPA_EVENT immediately. 

}
void BLANKint(){

  if(contaPWM < 4096){
    contaPWM++;
  }
  else {
    TimerDisable(TIMER0_BASE, TIMER_B);    //desliga timer que gera PWM para GSCLK
  }
  TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);    // Clear TIMER_CAPB_EVENT immediately.
}




Título: Re: TLC5940 - Como por a funcionar?
Enviado por: senso em 07 de Junho de 2014, 00:31
É impressão minha ou não estás a enviar dados nenhuns?
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 07 de Junho de 2014, 00:35
É impressão minha ou não estás a enviar dados nenhuns?

Tenho o SIN ligado sempre aos 3.3V. Quero apenas ver se ligo os leds
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 07 de Junho de 2014, 01:09
Prontos ja descobri.

O meu arqui-inimigo!!! um fio partido por dentro do isolamento!....... o que ligava o led ao VCC.
Ta certo XD


Obrigado pela ajuda, agora vou ve se meto algo de jeito
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 08 de Junho de 2014, 15:44
Agora tou com o problema de praticamente nao ter controlo de brilho nenhum.

Parece-me que nao estou a conseguir mudar o SIN de estado rapido o suficiente. Provavelmente vou ter de passar a usar o modulo SSI

Por curiosidade, senso que frequencia usas-te para o GSCLK e o CLK ?
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 09 de Junho de 2014, 21:52
Então já tenho isto a funcionar +-.

So tenho o problema de ainda nao conseguir passar dos 400Khz e ainda nao descobri que parte está a falhar para isso nao ser possivel.

Mas bem, ja passei a usar apenas 1 PWM para o GSCLK e o SCLK para impedir conflitos nos interrupts.
Tenho o BLANK, XLAT e SIN no bus mais rapido dos GPIOs e com acesso directo a registos (velocidade pulso de 8Mhz)
Tambem diminui a resolução do PWM do driver para 256bits para maior velocidade

Código: [Seleccione]
/*
This is for tm4c1294ncpdt to control a TLC5940 grayscale mode
In this version of the code:

I use only 1 timer (T2CCP0) for both SCLK and GSCLK
  There's just 1 PWM output (PA_4)
  1 interrupt for each rising edge of the PWM
 
The update of data to the TLC5940 is done by changing the variable "updating"
  The timer interrupt will react acordingly to that variable
  If you want to send data the interrupt will start the SOUT sequence after the resolution-194 number of edges
 
I use the AHB bus for the GPIO PE_1, PE_2 and PE_3 that are
  respectively SOUT, XLAT and BLANK
  And i control them with direct register access
 
The PWM i use only has 256 bits of resolution
  This makes it possible to have a faster refresh rate
   I didn't realy need much resolution
   You can change the "define resolution" to watever value betwen 194 and 4096


*/


#include "inc/hw_ints.h"
#include "driverlib/interrupt.c"
#include "driverlib/sysctl.c"
#include "driverlib/Timer.c"
#include"inc/tm4c1294ncpdt.h"

#define resolution 256

/*
 XLAT - PE_2
 BLANK - PE_3
 CLK -  PA_4 T2CCP0
 GSCLK - PA_4 T2CCP0
 SOUT -  PE_1
 
 */
void PWMInit(uint32_t freq);  //Configures output port for GSCLK PWM and corresponding timer
void PWMint();  //Interrupt function for GSCLK rising edge
void DectoBool();  //Converts a int to bool
void SetAllOFF();
void ChangeValue(int valor, int pos);  //Changes a port value
void send();  //Initiates CLK and updating of PWM values

bool DataPacket [16][12];
volatile byte updating = 1;
volatile uint32_t  contaPWM =0;
volatile uint32_t  contaCLK =0;

void setup()


  //Serial.begin(115220);
  IntPrioritySet(INT_TIMER2A,0xC1);

  PWMInit(400000); //0,00512

  SetAllOFF();
  send();
  ChangeValue(resolution-1,1);
  send();
}

void loop()
{

  for(int i=0; i <resolution; i+=1){
    ChangeValue(i,2);
    send();
     delay(10);
  }
  for(int i=resolution-1; i >= 0; i-=1){
    ChangeValue(i,2);
    send();
    delay(10);
  }
  for(int i=0; i <resolution; i+=1){
    ChangeValue(i,3);
    send();
     delay(10);
  }
  for(int i=resolution-1; i >= 0; i-=1){
    ChangeValue(i,3);
    send();
    delay(10);
  }
}

void PWMInit(uint32_t freq){

  //Configure port E1:
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOE);
  GPIOPinTypeGPIOOutput(GPIO_PORTE_AHB_BASE , GPIO_PIN_1);
  GPIOPadConfigSet(GPIO_PORTE_AHB_BASE,  GPIO_PIN_1,  GPIO_STRENGTH_8MA,  GPIO_PIN_TYPE_STD); 

  //Configure port E2:
  // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  GPIOPadConfigSet(GPIO_PORTE_AHB_BASE,  GPIO_PIN_2,  GPIO_STRENGTH_8MA,  GPIO_PIN_TYPE_STD);
  GPIOPinTypeGPIOOutput(GPIO_PORTE_AHB_BASE, GPIO_PIN_2);
  // 

  //Configure port E3:
 // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
 // SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOE);
  GPIOPinTypeGPIOOutput(GPIO_PORTE_AHB_BASE , GPIO_PIN_3);
  GPIOPadConfigSet(GPIO_PORTE_AHB_BASE,  GPIO_PIN_3,  GPIO_STRENGTH_8MA,  GPIO_PIN_TYPE_STD); 
  //


  unsigned long ulPeriod, dutyCycle;
  ulPeriod = 120000000/freq ;
  dutyCycle = ulPeriod/2;

  // Configure PA4 as T2CCP0
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);   
  GPIOPinConfigure(GPIO_PA4_T2CCP0);             
  GPIOPinTypeTimer(GPIO_PORTA_BASE, GPIO_PIN_4); 
  //

  // Configure timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);                       
  TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);   
  TimerLoadSet(TIMER2_BASE, TIMER_A, ulPeriod -1);                     
  TimerMatchSet(TIMER2_BASE, TIMER_A, dutyCycle); // PWM 

  //Configura Interrupt on the timer
  TimerIntRegister(TIMER2_BASE,TIMER_A,PWMint);
  TimerControlEvent(TIMER2_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
  TimerIntEnable(TIMER2_BASE,TIMER_CAPA_EVENT);

  //Turn on PWM
   TimerEnable(TIMER2_BASE, TIMER_A);
  //
}

void PWMint(){
  if(updating !=2){
    if(contaPWM < resolution){
      contaPWM++;
    }
    else if(updating==1){
      TimerDisable(TIMER2_BASE, TIMER_A);
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = GPIO_PIN_3;
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = 0;
      TimerEnable(TIMER2_BASE, TIMER_A);
      contaPWM=0;
      updating=2;
    }
    else{
      TimerDisable(TIMER2_BASE, TIMER_A);
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = GPIO_PIN_3;
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = 0;
      TimerEnable(TIMER2_BASE, TIMER_A);
      contaPWM=0;
    }
  }
  else{
    int linha= (contaPWM-(resolution-194))/12;
    int coluna=  (contaPWM-(resolution-194)) - (12*((contaPWM-(resolution-194))/12));
   
    if(contaPWM < (resolution-193)){
      contaPWM++;
    }
    else if(contaPWM == (resolution-193)){
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_1 << 2))) = 0;
      contaPWM++;
    }
    else if(contaPWM < resolution){
      if(DataPacket[linha][coluna]==1)
        HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_1 << 2))) = GPIO_PIN_1;
      else
        HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_1 << 2))) = 0;
      contaPWM++;
    }
    else{
      //Turn off PWM, pulse XLAT while BLANK is off, Turn BLANK on and Turn back on the PWM
      TimerDisable(TIMER2_BASE, TIMER_A);
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = GPIO_PIN_3;
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_2 << 2))) = GPIO_PIN_2;
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_2 << 2))) = 0;
      HWREG(GPIO_PORTE_AHB_BASE + ((GPIO_PIN_3 << 2))) = 0;
      TimerEnable(TIMER2_BASE, TIMER_A);
      contaPWM=0;     
      updating=0;
    }

  }

  TimerIntClear(TIMER2_BASE, TIMER_CAPA_EVENT);    // Clear TIMER_CAPA_EVENT immediately.   

}

void DectoBool(int value, bool Bit[]){
  for(int i = 11; i >= 0; i--){
    Bit[i] = 0b1 & value;
    value = value >> 1;   
  }
}

void SetAllOFF(){
  //while(updating !=0);

  for(int i=0; i < 16; i++)
    DectoBool(0, DataPacket[i]);
}

void ChangeValue(int value, int pos){
  //while(updating !=0);
  if (pos > 15 || pos < 0) return;
  /*  if( (value!=0) && (value!=4095))
   if( (value >0) && (value <= 10) );
   value = (0b111 << (value-1));*/

  if(value > resolution) value = resolution;
  if(value < 0) value = 0;
  //  Serial.println(value);
  DectoBool(value, DataPacket[15-pos]);
  /*  for(int j=0; j <16; j++){
   for(int i=0; i < 12; i++){
   Serial.print(DataPacket[j][i]);
   }
   Serial.println();
   }
   Serial.println();*/
}

void send(){
  updating=1;
  while(updating !=0);
}
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 01 de Agosto de 2014, 19:59
Ora boas tardes  :D

Agora com ferias ja consegui meter o TLC5940 com um GSCLK e SCLK de 30Mhz!
Aqui esta um teste so com 1 led RGB que nao tenho ca mais nenhum.

https://www.youtube.com/watch?v=s4N40TdbgN8&feature=youtu.be (https://www.youtube.com/watch?v=s4N40TdbgN8&feature=youtu.be)
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 02 de Agosto de 2014, 15:44
Bem, alguem me podia me explicar uma cena que para mim nao faz qualquer sentido, mas esta parte da electronica nao aprendi ainda.

Isto a 30Mhz obviamente tem problemas de o sinal sofrer muito com capacitancia na linha de sinal.
Entao quando alimento o TLC5940 com 3.3V isto nota-se um pouco, com flicker da transferencia de dados nao ser ideal.
Ora agora tentei alimentar o TLC5940 com 5V e funciona na perfeição.

É algo como, o aumento do VCC diminui a impedancia dos pins input?
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: jm_araujo em 02 de Agosto de 2014, 18:37
Não, mas aumentas a amplitude do sinal e torna mais fácil de distinguir os níveis lógicos, mas com  aumento  do consumo porque tens que forçar mais corrente na impedância.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 03 de Agosto de 2014, 04:33
Não, mas aumentas a amplitude do sinal e torna mais fácil de distinguir os níveis lógicos, mas com  aumento  do consumo porque tens que forçar mais corrente na impedância.

mas o sinal é exatamente o mesmo de 3.3V, so mudou a alimentaçao do IC.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 03 de Agosto de 2014, 16:04
Há alguma maneira de aumentar a corrente dos sinais CLK e data sem ser com um transistor/mosfet?
Queria aumentar a qualidade do sinal que já nem é uma onda quadrada, é triangular
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: senso em 03 de Agosto de 2014, 17:08
Isso tem muito a ver como a forma como estás a fazer o probe aos sinais, a inductancia do fio de massa da ponta de prova do osciloscópio faz isso, usa a mola que elas trazem e liga directamente á massa.
Título: Re: TLC5940 - Como por a funcionar?
Enviado por: LuísR.A. em 04 de Agosto de 2014, 19:45
Adicionei um anel de ferrite aos fios e ficou tudo porreiro sem qualquer problema

https://www.youtube.com/watch?v=w1PSUIQFN_g&feature=youtu.be (https://www.youtube.com/watch?v=w1PSUIQFN_g&feature=youtu.be)