Show Posts
Pages: 1 [2] 3 4 ... 6
16  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 16, 2009, 05:30:35 pm
The library now supports servos - check out the Servo example (thank you Steve Pomeroy).

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

and updated documentation is at
http://students.washington.edu/acleone/codes/tlc5940arduino/html_r8/
17  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 11, 2009, 02:48:18 pm
Any time you want to use millis(), delay(), or Serial.xxx() inside an interrupt, you have call sei(); first.

This should work, but it might freeze the arduino if the interrupt is called repeatedly because it would keep getting called in the middle of the delay and would never return from the function.  You could lock it like so:
Code:
volatile char isRunning;
void myInterruptFunction(void)
{
  if (!isRunning) {
    isRunning = 1;
    sei();
    delay(debounceDelay);
    //make state changes
    isRunning = 0;
  }
}
18  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 11, 2009, 02:24:05 am
yes, that will work inside the interrupt.  See http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html
19  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 10, 2009, 09:43:06 pm
You can turn on interrupts, etc (so millis and serial will work) in an interrupt vector with
Code:
sei();

I updated the playground page to point to the Google Code project, thanks for the heads-up.
20  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 04, 2009, 05:20:08 pm
I added a few examples:
Tlc5940__2009_02_04_r2.zip
21  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 04, 2009, 01:11:41 am
Ok, I got my hardware out to test everything.  I fixed/cleaned-up the code a bunch and everything, including the fades, works now.

This is the latest version:
http://tlc5940arduino.googlecode.com/files/Tlc5940__2009_03_03.zip
22  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 03, 2009, 01:03:20 pm
Yes, independent of the voltage.

I think I may have solved the fading problem: C++ was ignoring
Code:
struct mystruct p = buffer[buffer_size]
p.field1 = ...
p.field2 = ...
Changing this to a pointer seemed to fix everything in the disassembly:
Code:
struct mystruct *p = buffer + buffer_size
p->field1 = ...
p->field2 = ...

There was literally no code in tlc_addFade after the check to see if the buffer was full!  It would just increment the buffer size!  I'm guessing that in C++ you can't access structs with '.' because it thinks you're talking about a class field.

edit: It turns out that this doesn't work in c either.

Try replacing tlc_fades.h with this tlc_fades.h

Lesson to be learned: I really need to put my hardware back together so I release stuff that actually works.
23  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 03, 2009, 12:24:33 pm
Imax = 39.06 / R (in ohms)
and Imax must be set between 5mA and 120mA.

(see pg. 14 of the datasheet)
24  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 02, 2009, 11:51:15 pm
Ok, probably a bit overkill, but I've put the source up on Google Code:
http://code.google.com/p/tlc5940arduino/

And this is the file that we're having trouble with
tlc_fades.h
25  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 02, 2009, 11:15:54 pm
Ack, it must be the structs.  Can a C++ master verify that this should work?
Code:
#define      TLC_FADE_BUFFER_LENGTH      24

struct tlc_fade {
      TLC_CHANNEL_TYPE channel;
      int16_t startValue;
      int16_t changeValue;
      uint32_t startMillis;
      uint32_t endMillis;
} tlc_fadeBuffer[TLC_FADE_BUFFER_LENGTH];

volatile uint8_t tlc_fadeBufferSize;

uint8_t tlc_addFade(TLC_CHANNEL_TYPE channel, int16_t startValue, int16_t endValue, uint32_t startMillis, uint32_t endMillis)
{
      if (tlc_fadeBufferSize == TLC_FADE_BUFFER_LENGTH) {
            return 0; // fade buffer full
      }
      struct tlc_fade p = tlc_fadeBuffer[tlc_fadeBufferSize++];
      p.channel = channel;
      p.startValue = startValue;
      p.changeValue = endValue - startValue;
      p.startMillis = startMillis;
      p.endMillis = endMillis;
}

uint8_t tlc_removeFade(TLC_CHANNEL_TYPE channel)
{
      // disable interrupts so we don't remove a fade while an update is in
      // progess
      uint8_t oldSREG = SREG;
      cli();
      uint8_t removed = 0;
      struct tlc_fade *p = tlc_fadeBuffer;
      struct tlc_fade *end = tlc_fadeBuffer + tlc_fadeBufferSize;
      for (; p < end; p++) {
            if (p->channel == channel) {
                  removed++;
                  tlc_removeFadeFromBuffer(p, &end);
            }
      }
      SREG = oldSREG;
      return removed;
}

uint8_t tlc_updateFades(uint32_t currentMillis)
{
      if (tlc_needXLAT) {
            return 1;
      }
      struct tlc_fade *p = tlc_fadeBuffer;
      struct tlc_fade *end = tlc_fadeBuffer + tlc_fadeBufferSize;
      uint8_t needsUpdate = 0;
      for (; p < end; p++){
            if (currentMillis >= p->endMillis) { // fade done
                  Tlc.set(p->channel, p->startValue + p->changeValue);
                  needsUpdate = 1;
                  tlc_removeFadeFromBuffer(p, &end);
            } else {
                  uint32_t startMillis = p->startMillis;
                  if (currentMillis >= startMillis) {
                        Tlc.set(p->channel, p->startValue + p->changeValue
                                    * (currentMillis - startMillis)
                                    / (p->endMillis - startMillis));
                        needsUpdate = 1;
                  }
            }
      }
      if (needsUpdate) {
            Tlc.update();
            return 1;
      }
      return tlc_fadeBufferSize;
}

void tlc_removeFadeFromBuffer(struct tlc_fade *current, struct tlc_fade **endp)
{
      struct tlc_fade *end = *endp;
      if (--end != current) { // if this is not the last fade
            // TODO: switch to memcpy?                        
            current->channel = end->channel;
            current->startValue = end->startValue;
            current->changeValue = end->changeValue;
            current->startMillis = end->startMillis;
            current->endMillis = end->endMillis;
      }
      tlc_fadeBufferSize--;
}
26  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 02, 2009, 11:04:41 pm
Hmm, I think it might be the use of millis() in tlc_fades.h.  Try
Tlc5940__2009_02_02.zip
27  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 02, 2009, 03:15:32 am
@joe912:
If every 2048us is fine, here's some example code:
Code:
#include "Tlc5940.h"

// do something every two periods, so ~1024us
#define XLAT_PERIODS  2

volatile uint8_t timesCalled;

volatile void myXLATCallback()
{
  if (timesCalled) { // do nothing the first time
    timesCalled--;
  } else {
    // do something the second time
    // code goes here
    
    timesCalled = XLAT_PERIODS - 1;
  }
  set_XLAT_interrupt(); // so this will continue to be called
}

void startXLATCallback() {
   timesCalled = XLAT_PERIODS - 1;
   tlc_onUpdateFinished = myXLATCallback;
   myXLATCallback();
}

void setup()
{
  Tlc.init();
  startXLATCallback();
}

void loop()
{
  
}
28  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: February 02, 2009, 03:02:36 am
Ok, try this:
Tlc5940__2009_02_01.zip

My plan to make the fades update in the background (with the XLAT interrupt) didn't seem to work, even though it works with the animations example.  For now I've changed back to the old style of having an update function that gets called every loop cycle.
29  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: January 27, 2009, 01:44:04 am
So the BasicAnimations example does something but the Fades example doesn't?
30  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: January 27, 2009, 12:03:03 am
Ack, stupid mistake on my part.  I think I had a similar bug in tlc_animations.h.  Try this:
Tlc5940__2009_01_26.zip
Pages: 1 [2] 3 4 ... 6