2009-05-05

Munny Software

Finally I had the time and the patience to write a "clean version" of the Munny code.
I wanted to use avr-as instead of AVR-Studio, it was much more difficult than what I expected. Information about using avr-as is scarce and I was unable to find an example of an assembler only project for avr-as. The main problem was that when you use preprocessor commands you must use preprocessor comments!
So remember the following:

#define ADC_SETTLE -32 /* arround 20ms */ GOOD
#define ADC_SETTLE -32 ;arround 20ms WRONG

I'm not a web-wizard but I wanted to post the code "online", I tried using google code. Probably I'm not using correctly and I don't think it was designed for such small projects but here is the link to the download.
Because the project might interest to more than one community I also tried to posted the project at the AVRFreaks site, usually the place to search for information when dealing with avr-gcc toolchain but unfortunately I cannot add a file to the project...
Programming the flash is straight forward with avrdude, but programming the oscillator calibration value and the fuses needs some more work. I used the interactive mode of avrdude ( -t) :
read calibration
write flash 0x3ff calibration_value
read flash 0x3ff 0x10
Here is a picture of the PCB during testing:

The software is a bit difficult to understand, the micro is put to sleep most of the time except once once every 32 times of watchdog resets.

Then a temperature measure is made, a port pin is used to power the temperature sensor and the micro is put to sleep for some 20ms, then a analog to digital conversion is started and the micro put to sleep again until the conversion is finished. Then the value is stored and the sensor is powered down (to save maximum power).

The following step is calculating the colors function of the temperature, according to the temperature one of Red, Green or Blue or a mix of two is calculated. Each color has a value of [0..255].

Finally blinking the LED, a software 3 channel pwm controller is created, a counter is incremented every Timer1 output compare and the calculated color values are compared with this running counter. When the counter value is higher than the set value the corresponding LED color is turn off, otherwise turned on. Timer 1 is set to auto reload every 1/25.6 ms this gives a 256 bit resolution every 10ms, this make the colour mixing invisible to the eye. After 100 repeated counter runs the micro goes to sleep until next Watch dog reset.

1 comment:

itsolusenz said...
This comment has been removed by a blog administrator.