Pages: [1] 2   Go Down
Author Topic: TLC5940 Changine to Bit Banging and Move Blank Pin????  (Read 1749 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


HI All,

I am currently developing a product that will use both the MCP CAN chips and also the TLC5940 LED Driver chip,

Both items run off Serial, and so i have to move the LED drive to Bit Banging mode, ( not a problem in itself ) but i also need to move the Blanking function pin of the TLC5940 from D10 on the Uno to another pin, as the CAN shield already uses this pin via the SPI interface,

Lookign throught the libraries that set up the TLC5940, i have had no luck changing this pin to D5, (also PWM capable)

I have tried changing the pinout library from PORTB2 to PORTD5 , D10 to D5 on the Uno, but no luck, it still uses D10,

Has anyone had any luck doing this , or running 2 serial chips from one serial out o the Uno?

Thanks

RIch
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


HI All,

I am currently developing a product that will use both the MCP CAN chips and also the TLC5940 LED Driver chip,

Both items run off Serial, and so i have to move the LED drive to Bit Banging mode, ( not a problem in itself ) but i also need to move the Blanking function pin of the TLC5940 from D10 on the Uno to another pin, as the CAN shield already uses this pin via the SPI interface,

Lookign throught the libraries that set up the TLC5940, i have had no luck changing this pin to D5, (also PWM capable)

I have tried changing the pinout library from PORTB2 to PORTD5 , D10 to D5 on the Uno, but no luck, it still uses D10,

Has anyone had any luck doing this , or running 2 serial chips from one serial out o the Uno?

D5 is PWM capable but it's on a different hardware timer than D10 (Timer0 instead of Timer1). The timer can't drive d5 directly.

You'll have to do it manually in the TLC5940 library's interrupt function.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, thanks for the info,

I couldnt determine that from the datasheets and libraries,

How involved is the procedure you describe, are you able to point me towards the library areas of the TLC5940 that it would be necessary to change?

Thanks

Rich
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How involved is the procedure you describe, are you able to point me towards the library areas of the TLC5940 that it would be necessary to change?


You'll have to disable the hardware BLANK/XLAT signals (look for "enable_XLAT_pulses") permanently enable the XLAT input (look for "set_XLAT_interrupt") then do BLANK/XLAT in software in the interrupt handler (search for "ISR(TIMER1_OVF_vect)").
« Last Edit: November 21, 2012, 12:22:20 pm by fungus » Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, i get the idea of what you are saying,

I have found the items you mention in the .h libraby, but there are also mention of setting timers up in the .ccp file,

Would this need to be changed too?

i have copied the .h file below, i will try and edit the areas i think you mean,

Code:
/*  Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com>

    This file is part of the Arduino TLC5940 Library.

    The Arduino TLC5940 Library is free software: you can redistribute it
    and/or modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    The Arduino TLC5940 Library is distributed in the hope that it will be
    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with The Arduino TLC5940 Library.  If not, see
    <http://www.gnu.org/licenses/>. */

#ifndef TLC5940_H
#define TLC5940_H

/** \file
    Tlc5940 library header file. */

#include <stdint.h>
#include "tlc_config.h"

#ifdef TLC_ATMEGA_8_H

/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
    pulse */
#define set_XLAT_interrupt()    TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1)
/** Disables any Timer1 interrupts */
#define clear_XLAT_interrupt()  TIMSK = 0

#else

/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
    pulse */
#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1) Not sure how to permenantly set this???
/** Disables any Timer1 interrupts */
#define clear_XLAT_interrupt()  TIMSK1 = 0

#endif

/** Enables the output of XLAT pulses */
//#define enable_XLAT_pulses()    TCCR1A = _BV(COM1A1) | _BV(COM1B1)      Have grayed this out??
/** Disables the output of XLAT pulses */
#define disable_XLAT_pulses()   TCCR1A = _BV(COM1B1)

extern volatile uint8_t tlc_needXLAT;
extern volatile void (*tlc_onUpdateFinished)(void);
extern uint8_t tlc_GSData[NUM_TLCS * 24];

/** The main Tlc5940 class for the entire library.  An instance of this class
    will be preinstantiated as Tlc. */
class Tlc5940
{
  public:
    void init(uint16_t initialValue = 0);
    void clear(void);
    uint8_t update(void);
    void set(TLC_CHANNEL_TYPE channel, uint16_t value);
    uint16_t get(TLC_CHANNEL_TYPE channel);
    void setAll(uint16_t value);
#if VPRG_ENABLED
    void setAllDC(uint8_t value);
#endif
#if XERR_ENABLED
    uint8_t readXERR(void);
#endif

};

void tlc_shift8_init(void);
void tlc_shift8(uint8_t byte);

#if VPRG_ENABLED
void tlc_dcModeStart(void);
void tlc_dcModeStop(void);
#endif

// for the preinstantiated Tlc variable.
extern Tlc5940 Tlc;

#endif





As you can see, i am not quite up to speed at re-writing library code , just yet

Thanks for the help tho smiley

Rich
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
    pulse */
#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1) Not sure how to permenantly set this???
/** Disables any Timer1 interrupts */
#define clear_XLAT_interrupt()  TIMSK1 = 0


eg. Copy the code for 'set_XLAT_interrupt' directly into Tlc.init() then take that stuff out of the header file so nobody can call it accidentally...
« Last Edit: November 22, 2012, 09:18:36 am by fungus » Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, so i will stick

#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1)

into the void setup() part of my main code where i do the

TLC.init()

, then Gray out what i have mentioned in my code example?

and what about the last item you mentioned, (TIMER1_OVF_vect)").

Really appreciating the help,

Rich
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, so i will stick

#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1)

into the void setup() part of my main code where i do the

TLC.init()


Just this part will do:

TIFR1 |= _BV(TOV1);
TIMSK1 = _BV(TOIE1)

Read the datasheet to see what that does.


and what about the last item you mentioned, (TIMER1_OVF_vect)").

That's the interrupt handler.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, so i have greyed out the

/**#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1)

and

/**#define enable_XLAT_pulses()    TCCR1A = _BV(COM1A1) | _BV(COM1B1)

in the Header File , correct?

i have placed the new XLAT setup in the void setup after TLC.init90 as shown below??

Code:


#include "mcp_can.h"
#include <SPI.h>
#include <stdio.h>
#define INT8U unsigned char

INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
char str[20];

#include "Tlc5940.h"  // LED DRiver chip Library

int i = 0;

int redArray[] = {0,3,6,9,12,15,18,21};  // Red LED Array
int greenArray[] = {1,4,7,10,13,16,19,22};  // Green LED Array
int blueArray[] = {2,5,8,11,14,17,20,23};  // Blue LED Array
int maskBit = 1;





void setup()

{
    Tlc.init();                              // Initialise TLC LED Driver Chip
     TIFR1 |= _BV(TOV1);
     TIMSK1 = _BV(TOIE1);

   
    CAN.begin(CAN_500KBPS);                   // init can bus : baudrate = 500k
  attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
       
}


void MCP2515_ISR()
{
     Flag_Recv = 1;
}


void loop()

{
 
   Flag_Recv = 0;                // clear flag
      CAN.readMsgBuf(&len, buf);  // Recieve CAN Message
     
     
maskBit = 1;  // Start with Bit 00000001


for (i=0; i<8; i=i+1){
 
  if ((255 & maskBit) > 0) {
   
     Tlc.set(redArray [i], 1000);  // Write Red LED Bit ON
     Tlc.set(greenArray [i],0 );  // Write Green LED Bit ON
     Tlc.set(blueArray [i],0 );  // Write Blue LED Bit ON
      Tlc.update();            // Update the LED Driver Chip
     
  }
 
  else{
   
      Tlc.set(redArray [i], 0);     // Write Red LED Bit OFF
       Tlc.set(greenArray [i], 0);  //  Write Green LED Bit OFF
        Tlc.set(blueArray [i], 0);  // Write Blue LED Bit OFF
        Tlc.update();               // Upadte the LED Driver Chip
     
  }
  maskBit = maskBit << 1; // Next Bit to check
}



}





and do i need to change anything on the interupt?

Thankyou soo much for all of your help so far smiley

Rich
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and do i need to change anything on the interupt?

Lots of things. That's where you should send your BLANK/XLAT pulses.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry but I'm not quite knowledgeable enough on this to understand how to make the changes,
Are you willing to give me step by step instructions?

Many thanks

Rich
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry but I'm not quite knowledgeable enough on this to understand how to make the changes

You give up too easy...

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LOL, i am really trying to understand what the library does,

I have downloaded both the data sheet for the TLC5940, the MCP2515, and the Atmel processor
But i seem to be going in loops and loops,

I have tried changing the MCP library where it defines the CS pin as 10, and changed it to 5, but the CAN chip no longer works,

I have searched other posts about moving the CS pin but i think the MCP calls the SPI library, and the SPI library references the SS pin back to the pins Arduino header, and i DONT want to go changing things in there lol

What do you think?

Thanks
RIch
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LOL, i am really trying to understand what the library does,

It sends 4096 pulses on GSCLK then one pulse on BLANK.

Both were being done by hardware, you have to modify it to do BLANK in software.

Luckily the library is set up to call a function after the 4096 GSCLK pulses....

I have searched other posts about moving the CS pin but i think the MCP calls the SPI library, and the SPI library references the SS pin back to the pins Arduino header, and i DONT want to go changing things in there lol

The SS pin has to be an output or the SPI interface shuts down. It doesn't matter if it's HIGH or LOW, that's under your control, but it has to be an output.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So if i do a

digitalWrite(5,HIGH);
digitalWrite(5,LOW);

(5 being the new BLANK Pin i want to use)

after the line of code which does the 4096 GSCLK pulses, this should give me the same result?

I just need to find the line of code that does the 4096 GSCLK pulses then? is that done in one of the libraries?

Then i should just grey out the line of code that does the original blank Pulse?

Thanks for the advice so far

Rich
Logged

Pages: [1] 2   Go Up
Jump to: