Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Networking, Protocols, and Devices / Re: Running 2 serial devices from an Arduino? CAN chip and TLC5940 on: November 22, 2012, 10:51:03 am
this is the link to the library,

http://code.google.com/p/tlc5940arduino/

The MCP CAN chip uses

D2
D10
D11
D12

for the SPI interface

We have changed the operation of the TLC to BIT_BANG as mentioned in the TLC_config file so as it wont slow down the SPI bus for the CAN Chip,

So What i want to do is move the BLANK pin function to D5 which is PWM capable,

I am a relatively novice code writer and i ended up lost and confused when it got to library level changes,

I really appreciate this help

Rich
32  Using Arduino / Networking, Protocols, and Devices / Re: Running 2 serial devices from an Arduino? CAN chip and TLC5940 on: November 22, 2012, 10:30:42 am
Ah i see,

The issue i have, is that D10 on the UNO board is being used as a CS pin from the SPI library on the CAN chip, whereas d10 is being used as a BLANK signal on the TLC chip, would this not interfere with eachother?

The TLC doesnt seem to require an SS signal?? or am i being silly?

Thanks for the advice

Rich
33  Using Arduino / LEDs and Multiplexing / Re: TLC5940 Changine to Bit Banging and Move Blank Pin???? on: November 22, 2012, 09:40:26 am
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
34  Using Arduino / LEDs and Multiplexing / Re: TLC5940 Changine to Bit Banging and Move Blank Pin???? on: November 22, 2012, 09:24:34 am
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
35  Using Arduino / Networking, Protocols, and Devices / Running 2 serial devices from an Arduino? CAN chip and TLC5940 on: November 22, 2012, 09:10:12 am
Has anyone run 2 Serial devices from an UNO?

I have the MCP CAN chip running on the SPI bus, and i need to add the TLC5940 LED driver chip which also runs on SPI

Now i know i can move the TLC to run in BIT BANG mode, but i still need to move the BLANK pin that the TLC uses as the CAN chip requires this too,

I am not competent enough to modify libraries so i was wondering if anyone can help me do this?

Many thanks

Rich
36  Using Arduino / LEDs and Multiplexing / Re: TLC5940 Changine to Bit Banging and Move Blank Pin???? on: November 22, 2012, 09:02:45 am
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
37  Using Arduino / LEDs and Multiplexing / Re: TLC5940 Changine to Bit Banging and Move Blank Pin???? on: November 21, 2012, 07:15:23 am
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
38  Using Arduino / LEDs and Multiplexing / TLC5940 Changine to Bit Banging and Move Blank Pin???? on: November 21, 2012, 05:27:34 am

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
39  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 19, 2012, 04:37:47 am
Thanks, im just waitinf for the correct command from the cuy that wrote the library to try it out, but looks great,

Any idea why when the CAN message is removed, or i disconnect the board from the CAN bus, it seems to display the last recieved sequence on the lights,

In principal, it should be able to show more than one colour at a time as the CAN speed is high enough, and writing some simple code of digital write high's and low's allows me to do it,

I think i may have something in there that is taking to long, or it isnt clearing the messge buffer fast enough,

What do you think?

Cheers

Rich
40  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 16, 2012, 03:45:32 am
1, the CAN.ReadMsgBuf command in the code above will read the CAN messages that are being recieved into the message buffer.

Currently, i am using the contents of the CAN message frame   eg, buf[1] being the first part, for the sequence of the LED's,

So weather the Message being sent had a base ID of 0x500 or ox600 , or any other base ID, the LED's would still do whatever the frame of data held.

i want to be able to "take notice" of only a single given CAN id to get my data from,     

2, i tried doing this at the beginning of each loop, it seems to just cause the LED's to flash very quickly and at hardly any brightness, maybe i need to place it elsewehere in the loop?

3, thanks, i should have noticed that


Thanks

Rich
41  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 15, 2012, 11:29:56 am
Seems to be working great,

Thanks for all of the help Crossroads,

3 questions

1, How can i set the CAN code up to look at only a single base CAN id, at the moment, regardless of CAN id, it simple recieves any message and uses the data in the melevant bits to run the lights,

2, How can i clear the message buffers at the beginning of each time through the loop? at the moment, once the CAN message is removed from the bus, the led's remain in the last message state,

3, Any way of getting the code to run faster, as i believe i can display multiple colours at a time in software as the CAN u[pdate rate is fast enough for visual deception,

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];

////////////////////////////////////////// CAN Setup Above

int x = 0;
int pinsArray[] = {4,7,8,9,14,15,16,17};  // could be whatever group you select
int maskBit = 1;
int i = 0;
///////////////////////////////////////////////////// LED Setup Above

void setup()

{
  for(i=0; i<8; i++)
pinMode(pinsArray[i],OUTPUT);
pinMode(3,OUTPUT);   // Red PWM
pinMode(5,OUTPUT);   // Green PWM
pinMode(6,OUTPUT);   // Blue PWM

//////////////////////////////////////////////////////////////// LED Outputs Above

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

////////////////////////////////////////////////////////CAN Begin Above
}


void MCP2515_ISR()
{
     Flag_Recv = 1;
}
/////////////////////////////////////////////CAN Calling code

void loop ()
{
 


 if(Flag_Recv)                   // check if get data
    {
      Flag_Recv = 0;                // clear flag
 
      CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
      Serial.println("CAN_BUS GET DATA!");
      Serial.print("data len = ");Serial.println(len);
      for(int i = 0; i<len; i++)    // print the data
      {
        Serial.print(buf[i]);Serial.print("\t");
       
      }
      Serial.println();
    }
////////////////////////////////////////////////////////////////////////////////Recieve CAN Message
analogWrite(3,buf[1]);
analogWrite(5,buf[2]);
analogWrite(6,buf[3]);
////////////////////////////////////////////////////////Set RGB Colour With CAN Message


  maskBit = 1;                                  // start with B00000001

for (x=0; x<8; x=x+1){
 
if ((buf[0] & maskBit) >0){                 // makes all bits but 1 low: 0000000C, next pass 000000C0, etc

digitalWrite (pinsArray[x],  HIGH);
}

else {
 
digitalWrite (pinsArray[x], LOW);
}



maskBit = maskBit << 1;   // next bit - B00000010, B00000100, B00001000, etc up to B10000000
}

////////////////////////////////////////////////////////////////////////////////////////////////Write LED Pattern
}// next x



42  Using Arduino / Networking, Protocols, and Devices / How to clear CAN BUS Buffer with 2515 ?? on: November 15, 2012, 10:06:17 am
Hi, i have some code running with the 2515 setup,

I want to set the message buffers to all  zero at the beginning of each loop so as it recieves a new message each time and it doesnt hold the last message sent once it is no longer recieveing a new message,

can anyone help with this?

thanks
Rich
43  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 15, 2012, 05:33:15 am
Ah great thanks Riva, i will go try that code out now, the swapping of MSB and LSB looks very usefull
44  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 15, 2012, 05:31:41 am
Sorted, a few tweaks and i am there, i had to replace the == operator at the top of the loop with a single = operator as it was running a comparison and getting stuck,

will follow up with some updates when i have meged the PWM colour code and CAN recieve and transmit code into the main code.

Thanks again

Rich
45  Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array on: November 15, 2012, 04:41:18 am
OK, so i have managed to get the code to start running, and modifying the decimal number where the CANbyte value was will give me the desired LED patter,

The isue being, that is only flashes up for a second and it doesnt seem to be running through the loops correctly,

I have had a look over it and i cant spot anything obvious,

I had to add a "<" to the Maskbit line at the bottom as i assume it was supposed to be a Bitshift command? is thios correct?

Appreciating all the help folks

RIch

Code:

int x = 0;
int pinsArray[] = {2,3,4,5,6,7,8,9};  // could be whatever group you select
int maskBit = 1;
int i = 0;


void setup()

{
  for(i=0; i<8; i++)
pinMode(pinsArray[i],OUTPUT);
pinMode(10,OUTPUT);


maskBit == 1;

}

void loop ()
{
digitalWrite(10,HIGH);
                                   // start with B00000001

for (x=0; x<8; x=x+1){
 
if ((255 & maskBit) >0){                 // makes all bits but 1 low: 0000000C, next pass 000000C0, etc

digitalWrite (pinsArray[x],  HIGH);
}

else {
 
digitalWrite (pinsArray[x], LOW);
}

}

maskBit = maskBit<<1;   // next bit - B00000010, B00000100, B00001000, etc up to B10000000

}// next x

Pages: 1 2 [3] 4