summaryrefslogtreecommitdiff
path: root/electic_streaming328p/main.c
blob: 5cdf3a6601b1286995cea18a9a5f29b893cd7265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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

  }
}
*/