collapse

* Posts Recentes

Emulador NES em ESP32 por dropes
[13 de Março de 2024, 21:19]


Escolher Osciloscópio por jm_araujo
[06 de Fevereiro de 2024, 23:07]


TP4056 - Dúvida por dropes
[31 de Janeiro de 2024, 14:13]


Leitura de dados por Porta Serie por jm_araujo
[22 de Janeiro de 2024, 14:00]


Distancia Cabo por jm_araujo
[08 de Janeiro de 2024, 16:30]


Meu novo robô por josecarlos
[06 de Janeiro de 2024, 16:46]


Laser Engraver - Alguém tem? por almamater
[16 de Dezembro de 2023, 14:23]


Focos LED SMD por almamater
[16 de Dezembro de 2023, 14:12]


I Belive por dropes
[15 de Dezembro de 2023, 13:59]


Carga de corrente eletrónica ZPB30A1 60W por jm_araujo
[11 de Dezembro de 2023, 13:27]

Autor Tópico: TLC5940 - Como por a funcionar?  (Lida 14083 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #15 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)
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #16 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.
}




Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: TLC5940 - Como por a funcionar?
« Responder #17 em: 07 de Junho de 2014, 00:31 »
É impressão minha ou não estás a enviar dados nenhuns?
Avr fanboy

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #18 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
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #19 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
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #20 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 ?
« Última modificação: 08 de Junho de 2014, 15:51 por LuísR.A. »
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #21 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);
}
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #22 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
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #23 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?
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline jm_araujo

  • Mini Robot
  • *
  • Mensagens: 2.943
  • NERD!
Re: TLC5940 - Como por a funcionar?
« Responder #24 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.

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #25 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.
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #26 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
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: TLC5940 - Como por a funcionar?
« Responder #27 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.
Avr fanboy

Offline LuísR.A.

  • Mini Robot
  • *
  • Mensagens: 1.224
    • Clube de Robotica
Re: TLC5940 - Como por a funcionar?
« Responder #28 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
Tiva MCU é que é.

Tutoriais Tiva+codigos exemplo:
https://sites.google.com/site/luiselectronicprojects/