Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 19
91  Using Arduino / LEDs and Multiplexing / Re: blink-without-delay slowing things by factor 10 ? on: May 07, 2013, 06:45:15 pm
The measurement values I provided in the starting post are for a complete fade using the ledOne(0,0,0,255,255,25) 256 times to cross the color cube from all-off to all-on. So I have not measured the speed of the routine directly e.g. by switching a digital pin on-off and using my oscilloscope but for comparative purposes its good enough.

The three lines you marked as "not needed" do just that.

However, I believe that really does not answer the question why eliminating/out-commenting that one line of code:
Code:
previousMillis = currentMillis;
Speeds up the code by several factors.

Even more puzzling is that I use this same code in the rgbFade Method and it does not seem to have the same effect there. the only difference is that I don't use it within the if(){} structure.
92  Using Arduino / LEDs and Multiplexing / Re: blink-without-delay slowing things by factor 10 ? on: May 07, 2013, 05:22:56 am
Well..I did intend to use micros() at some point just to see if it would make any difference, but it did not, so I have changed it back already.

What does however seem to be slowing down the process is this line:

Code:
previousMillis = currentMillis;

There seem to be two reasons for that.
1. Both are of a different type "unsigned long" and "long"
2. They are 32 bit values

Changing the unsigned long to a long - while not the end solution - already showed improved execution time. My idea is to use pointers instead of copying bytes. I yet have to try that out.
93  Using Arduino / LEDs and Multiplexing / blink-without-delay slowing things by factor 10 ? on: May 06, 2013, 06:50:49 pm
The code below works in conjunction with my High Power RGB LED shield http://ledshield.wordpress.com. The shield is connected to the Arduino compatible Teensy3 per I2C bus.
The core routine is an adapted 3D Bresenham algorithm to with the three coordinates being red, green, blue. each time through the main loop the algorithm advances one pixel in 3D RGB space (I guess in that case it's really a voxel ). I apologize for the lack of commention/documenting. This is still under heavy development.

When out-commenting the blink-without-delay code marked as such in the main loop (at the very end) the fading algorithm runs substantially faster than with it enabled (the value for "interval" is set to 0). The rough measurement for an 8-bit fade from r,g,b 0,0,0 --> 255,255,255 appears to be dependent on which frequency I am running the I2C bus with. Going from 100kHz to 2.4MHz results in a 10x increase. When the blink-without-delay code is enabled there is no increase in execution speed beyond 4ookHz.

Is there an alternative method to mills() or am I using this incorrectly or inefficiently ?

Without blink-without-delay code

100 kHz --> 337 ms
400 kHz --> 97 ms
600 kHz --> 75 ms
800 kHz --> 58 ms
1000 kHz --> 53 ms
1200 kHz --> 47 ms
1500 kHz --> 42 ms
2000 kHz --> 36 ms
2400 kHz --> 33 ms

with blink-without-delay

100kHz --> 337 ms
400kHz --> 256 ms
600kHz --> 256 ms
800kHz --> 256 ms
1000kHz --> 256 ms
1200kHz --> 256 ms
1500kHz --> 256 ms
2000kHz --> 256 ms
2400kHz --> 256 ms

Code:
#include "i2c_t3.h"
#include "HPRGB2.h"

long interval = 0;
long previousMillis = 0;
long previousMillisTimer = 0;
int current;

class RGBFader:
public HPRGB {
public:
  RGBFader (uint8_t mcp4728ID = 0x00, uint8_t pca9685ID = 0x00);
  void randomLineInit(void);
  void randomLine(void);
  void rgbFade(uint8_t x1, uint8_t y1, uint8_t z1,uint8_t x2,uint8_t y2,uint8_t z2);
 
private:
  int16_t  xd, yd, zd;
  uint8_t  x, y, z;
  uint16_t ax, ay, az;
  int8_t   sx, sy, sz;
  int16_t  dx, dy, dz;
  uint8_t  x1, y1, z1;
  uint8_t  x2, y2, z2;
  uint8_t  r, g, b;
  boolean newLine;
  boolean (RGBFader::*pLine)();
  uint16_t MAX(uint16_t a, uint16_t b);
  uint16_t ABS(int16_t a);
  int8_t ZSGN(int16_t a);
  boolean lineXdominant(void);
  boolean lineYdominant(void);
  boolean lineZdominant(void);
};

RGBFader::RGBFader(uint8_t mcp4728ID, uint8_t pca9685ID)
{
  _mcp4728ID = mcp4728ID;
  _mcp4728_address = (MCP4728_BASE_ADDR | _mcp4728ID);
  _pca9685ID = pca9685ID;
  _pca9685_address = (PCA9685_BASE_ADDR | _pca9685ID);
}

/* find maximum of a and b */
inline uint16_t RGBFader::MAX(uint16_t a, uint16_t b) {
  return (a > b) ? a : b;
}

/* absolute value of a */
inline uint16_t RGBFader::ABS(int16_t a) {
  return (a < 0) ? -a : a;
}

/* take sign of a, either -1, 0, or 1 */
inline int8_t RGBFader::ZSGN(int16_t a) {
  return (a < 0) ? -1 : a > 0 ? 1 : 0;
}

void RGBFader::randomLineInit(void){

    uint8_t rand;
    rand = random (1, 4);
   
    x1 = 0;
    y1 = 0;
    z1 = 0;
   
    if (rand==1) { x2=255; } else { x2= random(0, 256); };
    if (rand==2) { y2=255; } else { y2= random(0, 256); };
    if (rand==3) { z2=255; } else { z2= random(0, 256); };

    x = x1;
    y = y1;
    z = z1;
   
    dx = x2 - x1;
    dy = y2 - y1;
    dz = z2 - z1;
     
    ax = ABS(dx) << 1;
    ay = ABS(dy) << 1;
    az = ABS(dz) << 1;

    sx = ZSGN(dx);
    sy = ZSGN(dy);
    sz = ZSGN(dz);

    if (ax >= MAX(ay, az)){                 /* x dominant */
      yd = ay - (ax >> 1);
      zd = az - (ax >> 1);
      pLine = &RGBFader::lineXdominant;
    }
    else if (ay >= MAX(ax, az)){            /* y dominant */
      xd = ax - (ay >> 1);
      zd = az - (ay >> 1);
      pLine = &RGBFader::lineYdominant;
    }
    else if (az >= MAX(ax, ay)){            /* z dominant */
      xd = ax - (az >> 1);
      yd = ay - (az >> 1);
      pLine = &RGBFader::lineZdominant;
    }
}

void RGBFader::rgbFade(uint8_t x1, uint8_t y1, uint8_t z1, uint8_t x2, uint8_t y2, uint8_t z2){
    newLine = (this->*pLine) ();
    if (newLine){
     
    unsigned long currentMillis = micros();           
    Serial.println(currentMillis-previousMillisTimer);
    previousMillisTimer = currentMillis;
   
    x = x1;
    y = y1;
    z = z1;

    dx = x2 - x1;
    dy = y2 - y1;
    dz = z2 - z1;

    ax = ABS(dx) << 1;
    ay = ABS(dy) << 1;
    az = ABS(dz) << 1;

    sx = ZSGN(dx);
    sy = ZSGN(dy);
    sz = ZSGN(dz);

    if (ax >= MAX(ay, az)){                 /* x dominant */
      yd = ay - (ax >> 1);
      zd = az - (ax >> 1);
      pLine = &RGBFader::lineXdominant;
    }
    else if (ay >= MAX(ax, az)){            /* y dominant */
      xd = ax - (ay >> 1);
      zd = az - (ay >> 1);
      pLine = &RGBFader::lineYdominant;
    }
    else if (az >= MAX(ax, ay)){            /* z dominant */
      xd = ax - (az >> 1);
      yd = ay - (az >> 1);
      pLine = &RGBFader::lineZdominant;
    }
  }
}

void RGBFader::randomLine(void){
  newLine = (this->*pLine) ();   
 
    if (newLine){
    int rand;
    rand = random (1, 4);
   
    x1 = x2;
    y1 = y2;
    z1 = z2;
   
    if (rand==1) { x2=0; } else { x2= random(0, 256); };
    if (rand==2) { y2=0; } else { y2= random(0, 256); };
    if (rand==3) { z2=0; } else { z2= random(0, 256); };

    x = x1;
    y = y1;
    z = z1;

    dx = x2 - x1;
    dy = y2 - y1;
    dz = z2 - z1;

    ax = ABS(dx) << 1;
    ay = ABS(dy) << 1;
    az = ABS(dz) << 1;

    sx = ZSGN(dx);
    sy = ZSGN(dy);
    sz = ZSGN(dz);

    if (ax >= MAX(ay, az)){                 /* x dominant */
      yd = ay - (ax >> 1);
      zd = az - (ax >> 1);
      pLine = &RGBFader::lineXdominant;
    }
    else if (ay >= MAX(ax, az)){            /* y dominant */
      xd = ax - (ay >> 1);
      zd = az - (ay >> 1);
      pLine = &RGBFader::lineYdominant;
    }
    else if (az >= MAX(ax, ay)){            /* z dominant */
      xd = ax - (az >> 1);
      yd = ay - (az >> 1);
      pLine = &RGBFader::lineZdominant;
    }
  }
}

boolean RGBFader::lineXdominant(void){
 
  goToRGB(x, y, z);
  if (x == x2)
  {
    return 1;
  }
  if (yd >= 0)
  {
    y += sy;
    yd -= ax;
  }
  if (zd >= 0)
  {
    z += sz;
    zd -= ax;
  }
  x += sx;
  yd += ay;
  zd += az;
  return 0;
}


boolean RGBFader::lineYdominant(void){
   
  goToRGB(x, y, z);
  if (y == y2){
    return true;
  }
  if (xd >= 0){
    x += sx;
    xd -= ay;
  }
  if (zd >= 0){
    z += sz;
    zd -= ay;
  }
  y += sy;
  xd += ax;
  zd += az;
  return false;
 
}

boolean RGBFader::lineZdominant(void){
   
  goToRGB(x, y, z);
  if (z == z2)
  {
    return true;
  }
  if (xd >= 0)
  {
    x += sx;
    xd -= az;
  }
  if (yd >= 0)
  {
    y += sy;
    yd -= az;
  }
  z += sz;
  xd += ax;
  yd += ay;
  return false;

}

RGBFader ledOne;// default mcp4728 id(0) and default PCA9685 id(0)

void setup()
{
  Serial.begin(115200);
   
  ledOne.begin();
  ledOne.setCurrent(100,100,100); // set maximum current for channel 1-3 (mA)
  ledOne.setFreq(330);            // operation frequency of the LED driver (KHz)
  ledOne.setPWMFrequency(120);
  ledOne.eepromWrite();           // write current settings to EEPROM
  delay(100);                     // wait for EEPROM writing
 
 
//test current-settings read function 
  Serial.print("Max current - channel one   :");
  Serial.println(ledOne.getCurrent(1));
  Serial.print("Max current - channel two   :");
  Serial.println(ledOne.getCurrent(2));
  Serial.print("Max current - channel three :");
  Serial.println(ledOne.getCurrent(3));
 
//test current-switch-frequency read function
  Serial.print("Operating Frequency :");
  Serial.println(ledOne.getFreq());
}

void loop()
{
  unsigned long currentMillis = millis();            // if out commented
  if(currentMillis - previousMillis > interval) {    // code runs
    previousMillis = currentMillis;                     // substantially 
    ledOne.rgbFade(0,0,0,255,255,255);
  }                                                             // faster
}
94  Using Arduino / LEDs and Multiplexing / Re: 3W Dimmable LED Driver DC 7-30V 700mA on: May 06, 2013, 06:44:46 pm
The LED driver board I posted is available throug ebay and costs 3,50 not including shipping.

@OP,

No I did not operate that LED driver board from a 9V battery I had three of these to operate a 700mA RGB LED. I would not attempt to do that with a 9V battery ;-)

However, If you initial Driver worked from a 9V battery there is no reason the Driver I suggested should not be able to do that. It uses the same IC.
95  Using Arduino / LEDs and Multiplexing / Re: 3W Dimmable LED Driver DC 7-30V 700mA on: May 06, 2013, 04:35:44 pm
Perhaps you post a little schematic of what is connected how. From your description I cannot gather what a schematic would look like.
96  Using Arduino / Networking, Protocols, and Devices / Re: I2C or USB PCAP touch sensor output - help! on: April 29, 2013, 05:47:42 am
A link to the data sheet for the capacitive touch sensor would help ;-)
97  Using Arduino / LEDs and Multiplexing / Re: Turning a simple 3w led w/arduino on: April 27, 2013, 08:47:50 pm
Well, this would be simple and inexpensive and you can drive it with PWM directly from one of the Arduino PWM pins:

http://ledsee.com/index.php/led-accessories/led-driver-9-26v-3507001000ma-with-dim-function-detail

Only caveat is that you definitely need a 6V power supply because the PT4115 chip on this driver has  5V under voltage lockout. Otherwise I have used three of these and they work fine.
98  Using Arduino / LEDs and Multiplexing / Re: Turning a simple 3w led w/arduino on: April 27, 2013, 12:55:17 pm
Hi Steve,

Welcome to the Forum. Switching a 3w high brightness LED with a linear regulator works but is not recommended. LEDs are constant current devices and that's not really the purpose linear regulators are made for. They also tend to get pretty hot and may require heat sinking.
Also, if you have not mounted a heat sink to your 3W LED now would be a good time!

You cannot switch a 3W LED directly with the Arduino as the pins on the Arduino cannot supply that much current, which is usually in the 350 - 700 mA range.

If you've not found the answer here on the forum then I'd encourage you to search a bit more as this topic has been discussed many, many times.

BTW The best, most efficient way to drive high brightness LED and being able to fade them is a switched constant current power supply that allows PWM control.
99  Using Arduino / LEDs and Multiplexing / Re: RGB LED easy smooth colour transitions on: April 25, 2013, 06:22:35 pm
Any jumpyness in color has nothing to do with the LEDs being common and or common cathode but rather with the fact that only 8 bit are used per color and that the eyes response to light intensity is not linear.
@OP I've seen this algorithm referenced in another post fairly recently, but the poster did not quite understand it. If you've reinvented this from scratch kudos to you!
100  Using Arduino / LEDs and Multiplexing / Re: LED driver shield on: April 23, 2013, 06:00:02 am
That is quite a massive tank!
It looks like you are trying to directly compare the lumen output of a metal Hali lamp with the lumen output of LEDs. Traditional lamps, including metal halide, distribute their light ove a much steradian, thus the need for large reflectors to collect all that light.
LEDs distribute their light much more dictional and with appropriate TIR optics are able to direct their light output with much higher optical efficiency. So light output per steradian - light density - is more important than overall lumen output.
101  Using Arduino / LEDs and Multiplexing / Re: LED driver shield on: April 23, 2013, 05:33:16 am

I've never did anything with LEDs before so I'm still trying to learn...I don't think this driver shield is gonna be enough for my needs,looks like 36 LEDs will be the max I could use without stacking about 4 of those shields...I appreciate the help


Your setup with this shield should put out  at least 4000 lumens ( the blue LEDs usually have a lot less output than the white LEDs). That is extremely bright! No need to stack 4 of those together!
If you really need more lumen output you can also try to find LEDs that run at 1A max instead of the 700mA as these should have a higher lumen output.
102  Using Arduino / LEDs and Multiplexing / Re: 3W Dimmable LED Driver DC 7-30V 700mA on: April 15, 2013, 05:49:47 am
Quote
Perhaps you start reading and understanding the alnalogWrite sample http://arduino.cc/en/Reference/AnalogWrite provided on the Arduino website. The code you posted above is missing an essential line in the setup that configures your pin 3 as an output.
Headroom, there's no pinMode missing, if that's what you're implying
Yup, that's what I was referring to. Guess I need to do my own reading  smiley-lol

@OP
The LED driver you are using employs a PT4115. The data sheet recommends an input voltage of 6-30V and has an under voltage lockout of 5.1V. I have used three of these http://www.ebay.com/itm/high-efficient-led-driver-0-35-and-0-7-and-1A-good-use-Arduino-/370632520478?pt=LH_DefaultDomain_0&hash=item564b6b731e which use the same chip and when trying these out first I had hoped to get by with a 5V wall wart I had handy. Unfortunately at 4.9V it was below the low voltage lockout. When I used a 9V Wallwart things started working as expected :-)
103  Using Arduino / LEDs and Multiplexing / Re: 3W Dimmable LED Driver DC 7-30V 700mA on: April 14, 2013, 10:06:44 am
Perhaps you start reading and understanding the alnalogWrite sample http://arduino.cc/en/Reference/AnalogWrite provided on the Arduino website. The code you posted above is missing an essential line in the setup that configures your pin 3 as an output.

Also, you may want to urgently mount your LED to a heat sink with some thermal tape, thermal epoxy or screws and thermal paste. If the LED gets the full 700mA for too long it will overheat and that will dramatically reduce its lifetime!
104  Using Arduino / LEDs and Multiplexing / Re: High Power (Brightness) RGB LED shield on: April 10, 2013, 06:32:51 pm
Buck configuration.
105  Using Arduino / LEDs and Multiplexing / High Power RGB LED shield - 12bit/channel dimming - I2C (TWI) on: April 09, 2013, 08:58:51 pm
After slowly starting to redesign the shield in January I now have a functioning prototype and I am considering having a batch of these either manufactured or possibly manufacturing them myself.But lets take a little step back.

I used a number of five of a previous version of this shield in my own LED lighting project (trippylighting.com). The maker of the original shield sold these through his blog. The last entry on the blog is from Dec. 2012 announcing a christmas break and while there have been a few answers in response to inquiries on the blog he has not posted anything in over 9 months and appears to have lost interest in his creation.

Much to my dismay as I was hoping to use these in a few more projects. When it seemed a possibility that the blog would go offline another user of the shield created another blog and pulled all the information over so it would not be lost.
He invited me to co-host the blog and I accepted. We discussed having a batch of these manufactured in their original form, but as I started creating a costed BOM it became clear that the original Inductors would not be available anymore and we had to find alternatives.

Also there were a few things that I wanted to change and as one thing lead to another...
You can read more details here on our blog: http://ledshield.wordpress.com.

So let's quickly go through the Features the shield has to offer:

  • Three independent constant current channels. This shield will NOT operate common anode or common cathode LEDs!
  • Meant to drive high brightness LEDs with a constant current from 350 to 700mA.
  • 42V input. 36V output can drive up to 40W of LEDs.
  • On-board 5V switching power supply and I2C connectivity provide for standalone operation.
  • Shield stacks on top of an Arduino but can be operated independently as it only uses GND and I2C (SCA,SDL) from Arduino.
    Shield is stackable (also in multiples) onto Arduino Uno (Rev 2 and Rev 3) and Arduino Leonardo but can be
    connected and operated from any other Arduino Board or microcotroller platform that offers I2C.
  • 12bit PWM resolution per channel allowing for CIE lab brightness corrected dimming(library function).
    The 12bit PWM in conjunction with the LED driver chip provide a dimming ratio of 3000:1 and more.
  • Dynamically adjustable constant current (I2C) between 100mA to 700mA allowing for analog dimming.
  • Adjustable/programmable (I2C) PWM frequency 40Hz to 1.6kHz
  • On-board I2C pull-up resistors can be disabled by means of solder jumpers.
  • Shield is stackable onto Arduino Uno (Rev 2 and Rev 3) and Arduino Leonardo but can be connected and operated from any other Arduino Board through I2C.
  • Optional temp sensor to monitor led temp
  • An Arduino library that provides access to all functions is available on Github.

If all that sounds attractive, please come over to to our blog http://ledshield.wordpress.com and leave a comment if you're interested.
The original price of this shield was US$41.50 and we hope to keep it in that range, but that obviously depends somewhat on quantity.
  
The posted image is a prototype and a few minor refinements are needed, e.g. all the Arduino Pin labels are missing. The terminal block for power input (5mm pitch) is too tall to allow stacking multiple shields and will be exchanged for a smaller one (3.5mm pitch).

Pages: 1 ... 5 6 [7] 8 9 ... 19