Table of values providing an analogue or pwm out

Hi, I am looking to put together a program which can take a table which would contain 0-255 values and provide a PWM or analogue 0-[near rail]v output.

I put a similar thing onto the picaxe forum but their limited memory space and not having many pwm outputs limits me.

The application is to simulate the light cycle of a 24 hour period using RGB led and white lights. The white provides the bulk light with the RGB to adjust the general colour.

There would be 4 columns of numbers, eg:

Step. Ch1. Ch2. Ch3. Ch4. 1. 238. 154. 57. 37 2. 189. 189. 48. 28 3. 119. 245. 35. 15 N. 35. 26. 2. 0

These would be for rgb and White.

Each "step" would be a unit of time for which the four values would need to be output from the IC. Depending on the program it could be ms to minutes.

I would normally expect 4 values per minute For a 24 hour period there Would be 5760 steps. This could be changed to perhaps 63msec/step for testing so 24 hours runs through in 6 mins, for example.

Is it possible to have a program which starts at the top of a table providing a corresponding analogue output for a predetermined period of time and just runs through then repeats?

I can either work with pwm (0-255 = 0-100%) (at 20-30kHz) or analogue (0-255 = 0-10v) (where the 10v would be achieved via an opamp). The output would be controlling LED drivers and fluorescent ballasts with PWM or analogue inputs for the dimming so the IC output signal wont be controlling the power electronics or LED's directly - its just a signal i need.

If there are any known examples or such a thing i would be interested in this.


Hi, I see your point. As im looking to create a natural dalight colour cycle, it doesnt change colour very quickly so even once per minute would be more than enough. that would be 1440 samples. i could drop to 4 bit colour (producing 16^3 = 4096 colours) and this would be a 4.32kB table.

Also, outwith sunset and sunrise, the colour may not change for a few hours so i could hold a current set of values.

I'm thinking: - A 2 hour dark-light table which can be reversed so it would run samples 1-120 for sunrise say, then 120-1 for sunset. - A set of "night" values and a set of "day" values - The program would run as follows:

Loop forever Start @ just after sunrise in "day" mode Wait 10 hours Run the "sunset" values for the 2 hour duration Be dark for 10 hours Run the "sunrise" values for the 2 hour duration Go back to start

I had been hoping to be able to tweak things hourly from data collected natural light colour fluctuations but its not a huge change.

Colour change is vaguley COSine in nature but its probably easyiest to produce a table and have it run though them!

On the memory - i see there is 32kB flash memory on say the ATmega328, can i not just write the table to flash when the IC is programmed and read from this in the form:

Loop forever Start Read line 1 of CSV (for example) values from flash memory and give data to the PWM program, this line equals "n" Read line "n"+1 of flash memory, unitll No more lines? -> go to start again

Or did i read that for a lookup table function moves the whole table into RAM for operation?

If i could use the 32kB flash then i wouldn't need to compromise on the minute-minute reproduction of colour tone and brightness.

Thanks, Stuart

Why not put the per minute table on an SD card (I2C EEPROM) and read one line at the time, that makes 4 bytes in memory for the last minute and 4 bytes for the new minute. Total 8 bytes. For the seconds you might even interpolate linear between two values to go smooooooth.

check out the SD or sdfat libraries ..

Well you could put that look up table into flash memory, plenty of room in a Mega for that.

I do like the idea of the sd card, new programs could be loaded by changing sd card. I'm also guessing it's similar code complexity to read an sd card as it is to read the flash memory.

I'll have a look about and start making up some code which will be fun as I've only ever made an excel macro before!

I'm also guessing it's similar code complexity to read an sd card as it is to read the flash memory.

No it is much much easer to read flash, they just look like arrays. Where as an SD card has a fileing system, file names and a whole hoste of software to read it. Check how much code you need to read SD cards.