Commit 9ce6804b70a183f79ff67843c49809f824070bd6

Authored by pfrison
1 parent 6a806062

ledDriver test a tester

tests/atmega2560/ledControl/ledControl.c
1 #include <avr/io.h> 1 #include <avr/io.h>
2 #include <util/delay.h> 2 #include <util/delay.h>
  3 +#include <math.h>
  4 +
  5 +#define NB_DRIVERS 3
  6 +#define MAX_VALUE 85 //TODO tbd !
  7 +#define DELAY 100
3 8
4 int main(void){ 9 int main(void){
5 - // SCLK PIN 37  
6 - // SIN PIN 35  
7 - DDRC = 0x03;  
8 - uint8_t LEDs = {10, 20, 30, 40, 50, 60, 70, 80, 90,  
9 - 100, 110, 120, 130, 140, 150, 160, 170, 180, 190  
10 - 200, 210, 220, 230, 240};  
11 - uint8_t ANDs = {0x001, 0x002, 0x004, 0x008, 0x010, 0x020, 0x040, 0x080,  
12 - 0x100, 0x200, 0x400, 0x800}; 10 + // Initialisation
  11 + unsigned int ledValues[NB_DRIVERS * DLED_CHANNELS];
  12 + init_LED_Drivers(NB_DRIVERS);
13 13
  14 + // Animation
  15 + unsigned int animTick = 0;
14 while(1){ 16 while(1){
15 - for(int i=0; i<24; i++){  
16 - uint16_t n = LEDs[i] << 4;  
17 - int clkStatus = 0;  
18 - for(int j=0; j<12; j++){  
19 - if(j == 6)  
20 - clkStatus = 1;  
21 - PORTC = (n & ANDs[j]) << 1 | clkStatus;  
22 - _delay_ms(1);  
23 - } 17 + // Build animation
  18 + for(int i=0; i<NB_DRIVERS * DLED_CHANNELS; i++){
  19 + double sinIn = (double) animTick / 8;
  20 + unsigned int val = (unsigned int) (0.5 + (sin(sinIn) * 0.5));
  21 + ledValues[i] = val * MAX_VALUE;
24 } 22 }
  23 + animTick++;
  24 + if(animTick >= 10000)
  25 + animTick = 0;
  26 +
  27 + set_LED_Drivers(groupes, NB_DRIVERS);
  28 + _delay_ms(100);
25 } 29 }
26 return 0; 30 return 0;
27 } 31 }
tests/atmega2560/ledControl/tlc5947.c 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  1 +#include <avr/io.h>
  2 +#include "tlc5947.h"
  3 +
  4 +#define DLED_CHANNELS 24
  5 +
  6 +#define DDR_DLED DDRD
  7 +#define PORT_DLED PORTD
  8 +
  9 +#define PIN_DLED_CLOCK 5
  10 +#define PIN_DLED_DATA 4
  11 +#define PIN_DLED_LATCH 6
  12 +
  13 +void init_LED_Drivers(int nb){
  14 + // LED drivers I/O as outputs
  15 + DDR_DLED |= (1<<PIN_DLED_CLOCK) | (1<<PIN_DLED_DATA) | (1<<PIN_DLED_LATCH);
  16 + // Set LATCH output low
  17 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  18 +}
  19 +
  20 +
  21 +void set_LED_Drivers(unsigned int pwm[], int nb){
  22 + // Set LATCH output low
  23 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  24 + // 24 channels per TLC5947
  25 + int i;
  26 + for(i=DLED_CHANNELS*nb-1; i>=0; i--){
  27 + // 12 bits per channel, send MSB first
  28 + int v=pwm[i];
  29 + int j;
  30 + for(j=0; j<12; j++){
  31 + // Set CLOCK output low
  32 + PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
  33 +
  34 + // Set DATA as stated by bit #j of i
  35 + if(v & 0x0800)
  36 + PORT_DLED |= (1<<PIN_DLED_DATA);
  37 + else
  38 + PORT_DLED &= ~(1<<PIN_DLED_DATA);
  39 +
  40 + // Set CLOCK output HIGH
  41 + PORT_DLED |= (1<<PIN_DLED_CLOCK);
  42 + v <<= 1;
  43 + }
  44 + }
  45 + // Set CLOCK output low
  46 + PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
  47 +
  48 + // Set LATCH output high
  49 + PORT_DLED |= (1<<PIN_DLED_LATCH);
  50 + // Set LATCH output low
  51 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  52 +}
tests/atmega2560/ledControl/tlc5947.h 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +#ifndef TLC5947
  2 +#define TLC5947
  3 +
  4 +void init_LED_Drivers(int nb);
  5 +void set_LED_Drivers(unsigned int pwm[], int nb);
  6 +
  7 +#endif