diff options
Diffstat (limited to 'electic_streaming328p/main.c')
| -rw-r--r-- | electic_streaming328p/main.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/electic_streaming328p/main.c b/electic_streaming328p/main.c new file mode 100644 index 0000000..5cdf3a6 --- /dev/null +++ b/electic_streaming328p/main.c @@ -0,0 +1,83 @@ +/* test streaming sample data + * bluetooth + * TJR 141011 + + want: 1 second + 16M / 1024 prescale = + + */ + +#include <stdlib.h> +#include <avr/io.h> +#include <avr/interrupt.h> +//include <avr/signal.h> +#include <avr/pgmspace.h> + +#include <math.h> + +#include "uart.h" + +//#include "HardwareSerial.h" + +#define SAMPLES 512 + +#ifndef F_CPU +#define F_CPU 16000000UL +#endif +#define UART_BAUD_RATE 57600 + +//unsigned char dd[SAMPLES]; // ram buffer +int enabled=0; +int loopCount=0; +int sample=0; + +int main(void) +{ + Serial.begin(57600); + + //uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); + DDRB |= (1 << 5); // port B bit 6 = arduino pin 13 + PORTB = (1 << 5); //turn on to start + TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode + TIMSK1 |= (1 << OCIE1A); // Enable CTC interrupt + OCR1A = 1562; // Set CTC compare value to 1Hz at 1MHz AVR clock, with a prescaler of 64 + sei(); // Enable global interrupts + TCCR1B |= ((1<<CS10)|(1 << CS12)); // Set up timer at Fcpu/1024 + //fill_sinewave(); + unsigned int c; + /* while(1) { + c = uart_getc(); + if (!( c & UART_NO_DATA )) + { + uart_putc( (unsigned char)c ); + if ((unsigned char)c=="a") { + uart_puts_P("Welcome to electic"); + enabled=1; + } + } + } + */ +} + +ISR(TIMER1_COMPA_vect) +{ + if (enabled) PORTB ^= (1 << 5); + +} +/* +void fill_sinewave(){ + float pi = 3.141592; + float fcnt=0; + float fd; + float dx=2 * pi / SAMPLES; // fill the 512 byte bufferarry + int bb; +http://www.johnhenryshammer.com/WOW2/pagesHowTo/atmelPage.php#index for (int i = 0; i <= (SAMPLES-1); i++){ // with 50 periods sinewawe + fd= 127*sin(fcnt); // fundamental tone + fcnt=fcnt+dx; // in the range of 0 to 2xpi and 1/512 increments + bb=127+fd; // add dc offset to sinewawe + dd[i]=bb; // write value into array + + } +} +*/ + |
