Pages: [1]   Go Down
Author Topic: Sketch Behavior Affected by Tlc.init Placement  (Read 1678 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a light clock that grabs the time from a RTC and displays it using LEDs and have come some strange results.  In the following sketch:


#include <Time.h> 
#include <Wire.h> 
#include "Tlc5940.h"
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

 int HourHold;
 int MinuteHold;
 int DimFactor = 13;
 int MaxBright = 3900;
 int CurrSec;
 int UpIntensity;
 int UpChannel;    // channels 1-12
 int DownIntensity;
 int DownChannel;
 int HourChannel;  // channels 17-28
 int DigitOne;

void setup()  {
  Tlc.init();  1  
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");   
//  Tlc.init();  2
     
}

void loop()
{
   ChannelCalculate();
   LEDParameterDisplay();
   LEDDisplay();
   digitalClockDisplay(); 
   delay(1000);
}

void ChannelCalculate()
{   
 
   HourChannel = (hour() % 12) + 17;            // Determine which LEDs to illuminate
   CurrSec = ((minute() % 5) * 60) + second();    // and set the intensity of the
   UpIntensity = CurrSec * DimFactor;         // minute LEDs
   DownIntensity = MaxBright - UpIntensity;
   DownChannel = minute()/5 + 1;
   if(DownChannel == 0){
     DownChannel = 12;
   }
   UpChannel = DownChannel + 1;
   if(UpChannel == 13){
     UpChannel = 1;
   }
}

void LEDParameterDisplay()
{
  Serial.print("Hour Channel: ");
  Serial.println(HourChannel);
  Serial.print("Up Channel: ");
  Serial.println(UpChannel);
  Serial.print("Up Intensity: ");
  Serial.println(UpIntensity);
  Serial.print("Down Channel: ");
  Serial.println(DownChannel);
  Serial.print("Down Intensity: ");
  Serial.println(DownIntensity);
}

void LEDDisplay()
{
    Tlc.clear();                             // address the appropriate LEDs thru the two
    Tlc.set(UpChannel, UpIntensity);         // TLC5940NTs
    Tlc.set(DownChannel, DownIntensity);
    Tlc.set(HourChannel, MaxBright);
    Tlc.update();
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

If the Tlc.init() is in position 1 above, I get an erroneous time and date from the RTC but the LEDs display as expected.  If the Tlc.init() is in position 2, the time and date are correct, but the LEDs  flicker terribly.  I have also noticed that, if I pull the connection from Arduino pin three to the 5940s before starting processing, the time and date are read correctly - but that disables the 5940s driving the LEDs. 
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 241
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is more likely due to a wiring error.

For example one fellow in here, who was encountering weird TLC5940 behavior, realized that he had connected the VPRG pin to GND rather than Vcc.

Start by carefully checking your wiring to the TLC5940.
Logged

Pages: [1]   Go Up
Jump to: