Steve Ravet
/
ticker_test5
short program to show a problem with spi and tickers
Revision 0:85d990bd01f4, committed 2010-10-20
- Comitter:
- sravet
- Date:
- Wed Oct 20 04:32:32 2010 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 85d990bd01f4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 20 04:32:32 2010 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" +#include "pattern.h" + + +SPI spi(p5, p6, p7); // mosi, miso, sclk +DigitalOut cs(p8); +DigitalOut blank(p11); +DigitalOut xlat(p12); +AnalogIn audio(p15); +AnalogOut DAC(p18); + +Serial pc(USBTX, USBRX); // tx, rx +Ticker refresh; + +void refresh_leds(void); +pattern p1; + +int main() { + int i,j,done=0,key,inc=10; + int red,green,blue,sat,value; + float f1,f2; + +// configure SPI to match TLC5947. 12 bit word, mode zero +// frequency of 1 MHz. + spi.format(12,0); + spi.frequency(1000000); + +// attach the LED refresh function + refresh.attach_us(refresh_leds,10000); + +//start the pattern isr + p1.start(); + + while(1); + +} + +void refresh_leds(void) +{ + int color,led,r,g,b,h,s,v; + cs=1; + for (led=0;led<24;led++){ + spi.write(r); + spi.write(b); + spi.write(g); + } + xlat=1; + xlat=0; + if (blank) blank=0; + cs=0; +} + + + + + + \ No newline at end of file
diff -r 000000000000 -r 85d990bd01f4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 20 04:32:32 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
diff -r 000000000000 -r 85d990bd01f4 pattern.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pattern.cpp Wed Oct 20 04:32:32 2010 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +#include "pattern.h" + + +DigitalOut led1(LED1); //rotate_leds +DigitalOut led2(LED2); //HSV2RGB +DigitalOut led3(LED3); +DigitalOut led4(LED4); +AnalogOut aout(p18); + +// pattern constructor. Turn off LEDs, initialize class variables. +pattern::pattern() +{ +} + + +// start up the pattern ticker. Keep track of rotation and throb counters and update +// the LEDs when necessary. +void pattern::start(void) +{ + update_ticker.attach_us(this,&pattern::update_isr,1000000/ISR_FREQ); +} + + + + +void pattern::update_isr() +{ + led4=1; + led4=0; + led4=1; + wait_us(2); + led4=0; +} + +
diff -r 000000000000 -r 85d990bd01f4 pattern.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pattern.h Wed Oct 20 04:32:32 2010 +0000 @@ -0,0 +1,13 @@ + + +#define ISR_FREQ 5000 +#define NUM_SAMPLES 100 + +class pattern { + Ticker update_ticker; +private: + void update_isr(void); +public: + pattern(void); + void start(void); +};