Go Down

Topic: TLC5940mux.h with 74hc595 Mega2560, raw 3 and raw 7 issue.. (Read 328 times) previous topic - next topic

rat47

Jun 20, 2013, 05:15 am Last Edit: Jun 20, 2013, 07:02 pm by rat47 Reason: 1
I'm plan to drive 5x8 rgb led matrix with Mega 2560. Almost there with TLC5940Mux.h, but raw 3 and raw 7 is not functioning... Other all raws are fine and act as expected...

Please help if anyone can ...


Code: [Select]
#include "Tlc5940Mux.h"


#define  NUM_TLCS  1
#define  NUM_ROWS  8

// SHIFT_DATA_PIN (PC0 is analog 0) = '595 SER pin (Pin 14)
#define SHIFT_DATA_PORT PORTC
#define SHIFT_DATA_PIN  PC0
#define SHIFT_DATA_DDR  DDRC
// SHIFT_CLK_PIN (PC1 is analog 1) = '595 SRCLK (Pin 11)
#define SHIFT_CLK_PORT  PORTC
#define SHIFT_CLK_PIN   PC1
#define SHIFT_CLK_DDR   DDRC
// '595 RCLK is hooked to tlc XLAT pin (Arduino digital Pin 9, 74HC595 Pin 12)


volatile uint8_t isShifting;
uint8_t shiftRow;

static inline void shift8_595_row(uint8_t row)
{
  // the output of the '595 for the selected row should be high, all others
  // low
  uint16_t output = (1 << row);
  uint16_t nbit = 1 << (NUM_ROWS - 1); //0x80;
  for (; nbit; nbit >>= 1) {
    if (nbit & output) {
      SHIFT_DATA_PORT |= _BV(SHIFT_DATA_PIN);
    }
    else {
      SHIFT_DATA_PORT &= ~_BV(SHIFT_DATA_PIN);
    }   
    // pulse the '595 sclk
    SHIFT_CLK_PORT |= _BV(SHIFT_CLK_PIN);
    SHIFT_CLK_PORT &= ~_BV(SHIFT_CLK_PIN);
  }
}


ISR(TIMER1_OVF_vect)
{
  if (!isShifting) {
    disable_XLAT_pulses();
    isShifting = 1;
    sei();
    TlcMux_shiftRow(shiftRow);
    shift8_595_row(shiftRow);
    PORTC = shiftRow++;
       
    if (shiftRow == NUM_ROWS) {
      shiftRow = 0;
    }
    enable_XLAT_pulses();
    isShifting = 0;
  }
}


void test()
{


for(int x=0; x<8; x++){
 
  TlcMux_clear();
  TlcMux_set(x, 0, 4095);
  delay(100);
 
  TlcMux_clear();
  TlcMux_set(x, 1, 4095); 
  delay(100);
 
  TlcMux_clear();
  TlcMux_set(x, 2, 4095);
  delay(100);
 
  }
}



void setup()
{
 
  SHIFT_DATA_DDR |= _BV(SHIFT_DATA_PIN);
  SHIFT_CLK_DDR  |= _BV(SHIFT_CLK_PIN);
 
  DDRC |= _BV(PC0) | _BV(PC1) | _BV(PC2);
  TlcMux_init();
}

uint8_t color;
void loop()
{
delay(1);
  /*
 
  for (uint8_t col = 0; col < 11; col++) {
    for (uint8_t row = 0; row < NUM_ROWS; row++) {
      TlcMux_set(row, col + color * 16, 4095);
    }
    color++;
    if (color == 3) {
      color = 0;
    }
  }
 
  */
  test();
 
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy