Changeset - c79b24c96a83
[Not reviewed]
default
0 9 2
ethanzonca@CL-SEC241-08.cedarville.edu - 13 years ago 2012-10-29 19:48:57
ethanzonca@CL-SEC241-08.cedarville.edu
Added afsk code, which is tested and works on the micro
11 files changed with 362 insertions and 20 deletions:
0 comments (0 inline, 0 general)
master/master/lib/afsk.c
Show inline comments
 
new file 100644
 
/*
 
 * fsk.c
 
 *
 
 * Created: 10/29/2012 7:40:34 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
/*
 
 * Master Firmware
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 

	
 
#define F_CPU 11059200
 

	
 
#include <stdint.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h> 
 
#include <util/delay.h>
 
#include <avr/pgmspace.h>
 

	
 
PROGMEM extern const uint8_t afsk_sine_table[512] = {
 
  127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 143, 144, 146, 147, 149, 150, 152, 153, 155, 156, 158, 
 
  159, 161, 163, 164, 166, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, 183, 184, 186, 187, 188, 
 
  190, 191, 193, 194, 195, 197, 198, 199, 200, 202, 203, 204, 205, 207, 208, 209, 210, 211, 213, 214, 215, 
 
  216, 217, 218, 219, 220, 221, 223, 224, 225, 226, 227, 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 
 
  236, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 
 
  249, 250, 250, 251, 251, 251, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 
 
  254, 254, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 253, 253, 253, 253, 252, 252, 252, 251, 
 
  251, 251, 250, 250, 249, 249, 249, 248, 248, 247, 247, 246, 245, 245, 244, 244, 243, 242, 242, 241, 240, 
 
  239, 239, 238, 237, 236, 236, 235, 234, 233, 232, 231, 230, 229, 228, 228, 227, 226, 225, 224, 223, 221, 
 
  220, 219, 218, 217, 216, 215, 214, 213, 211, 210, 209, 208, 207, 205, 204, 203, 202, 200, 199, 198, 197, 
 
  195, 194, 193, 191, 190, 188, 187, 186, 184, 183, 182, 180, 179, 177, 176, 174, 173, 171, 170, 168, 167, 
 
  166, 164, 163, 161, 159, 158, 156, 155, 153, 152, 150, 149, 147, 146, 144, 143, 141, 139, 138, 136, 135, 
 
  133, 132, 130, 129, 127, 125, 124, 122, 121, 119, 118, 116, 115, 113, 111, 110, 108, 107, 105, 104, 102, 
 
  101,  99,  98,  96,  95,  93,  91,  90,  88,  87,  86,  84,  83,  81,  80,  78,  77,  75,  74,  72,  71, 
 
   70,  68,  67,  66,  64,  63,  61,  60,  59,  57,  56,  55,  54,  52,  51,  50,  49,  47,  46,  45,  44, 
 
   43,  41,  40,  39,  38,  37,  36,  35,  34,  33,  31,  30,  29,  28,  27,  26,  26,  25,  24,  23,  22, 
 
   21,  20,  19,  18,  18,  17,  16,  15,  15,  14,  13,  12,  12,  11,  10,  10,   9,   9,   8,   7,   7, 
 
    6,   6,   5,   5,   5,   4,   4,   3,   3,   3,   2,   2,   2,   1,   1,   1,   1,   0,   0,   0,   0, 
 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   1,   1,   1, 
 
    2,   2,   2,   3,   3,   3,   4,   4,   5,   5,   5,   6,   6,   7,   7,   8,   9,   9,  10,  10,  11, 
 
   12,  12,  13,  14,  15,  15,  16,  17,  18,  18,  19,  20,  21,  22,  23,  24,  25,  26,  26,  27,  28, 
 
   29,  30,  31,  33,  34,  35,  36,  37,  38,  39,  40,  41,  43,  44,  45,  46,  47,  49,  50,  51,  52, 
 
   54,  55,  56,  57,  59,  60,  61,  63,  64,  66,  67,  68,  70,  71,  72,  74,  75,  77,  78,  80,  81, 
 
   83,  84,  86,  87,  88,  90,  91,  93,  95,  96,  98,  99, 101, 102, 104, 105, 107, 108, 110, 111, 113, 
 
  115, 116, 118, 119, 121, 122, 124, 125
 
};
 

	
 
inline uint8_t afsk_read_sample(int phase)
 
{
 
  return pgm_read_byte_near(afsk_sine_table + phase);
 
}
 

	
 
volatile uint16_t phase = 10;
 
volatile uint16_t phasedelta = 3300;
 
extern const uint16_t TABLE_SIZE = sizeof(afsk_sine_table);
 

	
 
void afsk_setup() {
 
	
 
  // Source timer2 from clkIO (datasheet p.164)
 
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
 

	
 
  // Set fast PWM mode with TOP = 0xff: WGM22:0 = 3  (p.150)
 
  TCCR2A |= _BV(WGM21) | _BV(WGM20);
 
  TCCR2B &= ~_BV(WGM22);
 

	
 
  // Do non-inverting PWM on pin OC2B (arduino pin 3) (p.159).
 
  // OC2A (arduino pin 11) stays in normal port operation:
 
  // COM2B1=1, COM2B0=0, COM2A1=0, COM2A0=0
 
  TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0));
 

	
 
  // No prescaler (p.162)
 
  TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20);
 
    
 
  // Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163)
 
	//TIMSK2 |= _BV(TOIE2);
 
	TIMSK2 |= 0b00000001;
 

	
 
	// Initialize PORTA
 
	DDRA = 0xff;
 
	PORTA = 0x00;
 
	
 
	DDRD = 0xff;
 
	PORTD = 0xff;
 
	
 
	sei();
 
}
 

	
 
void afsk_test() {	
 
	afsk_timer_start();
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	_delay_ms(3);
 
	phasedelta = 1800;
 
	_delay_ms(3);
 
	phasedelta = 3300;
 
	afsk_timer_stop();
 
	_delay_ms(400);
 
}
 

	
 

	
 
// phase offset of 1800 gives ~1900 Hz
 
// phase offset of 3300 gives ~2200 Hz
 
ISR(TIMER2_OVF_vect) {
 
	phase = (phase + phasedelta);
 
	OCR2B = afsk_read_sample((phase >> 7) & (TABLE_SIZE - 1));
 
	return;
 
}
 

	
 
void afsk_timer_start()
 
{
 
	// Clear the overflow flag, so that the interrupt doesn't go off
 
	// immediately and overrun the next one (p.163).
 
	TIFR2 |= _BV(TOV2);       // Yeah, writing a 1 clears the flag.
 

	
 
	// Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163)
 
	TIMSK2 |= _BV(TOIE2);
 
}
 

	
 
void afsk_timer_stop()
 
{
 
	// Output 0v (after DC coupling)
 
	OCR2B = 0x00;
 

	
 
	// Disable playback interrupt
 
	TIMSK2 &= ~_BV(TOIE2);
 
}
master/master/lib/afsk.h
Show inline comments
 
new file 100644
 
/*
 
 * afsk.h
 
 *
 
 * Created: 10/29/2012 7:43:03 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
 
#ifndef AFSK_H_
 
#define AFSK_H_
 
 
void afsk_setup();
 
void afsk_test();
 
void afsk_timer_start();
 
void afsk_timer_stop();
 
 
#endif /* AFSK_H_ */
 
\ No newline at end of file
master/master/lib/led.c
Show inline comments
 
/*
 
 * led.c
 
 *
 
 * Created: 10/25/2012 3:34:03 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
#include <avr/io.h>
 
 
void led_Configure() {
 
void led_setup() {
 
	// Configure ports/pins for LEDs
 
}
 
 
void led_On(uint8_t led) {
 
	// Turn the specified LED on
 
}
 
 
void led_Off(uint8_t led) {
 
	// Turn the specified LED off
 
}
 
 
void led_Toggle(uint8_t led) {
 
	// Toggle the specified LED 
 
}
 
\ No newline at end of file
master/master/lib/led.h
Show inline comments
 
/*
 
 * led.h
 
 *
 
 * Created: 10/25/2012 3:34:10 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
 
#ifndef LED_H_
 
#define LED_H_
 
 
#define POWER 1
 
#define ERROR 2
 
#define STAT 2
 
#define OK 2
 
 
void led_Configure();
 
void led_setup();
 
void led_On(uint8_t led);
 
void led_Off(uint8_t led);
 
void led_Toggle(uint8_t led);
 
 
 
#endif /* LED_H_ */
master/master/lib/serial.c
Show inline comments
 
/*
 
 * serial.c
 
 *
 
 * Created: 10/25/2012 3:19:49 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
#include <avr/io.h>
 
 
void serial_SendChar( char byte )
 
{
 
	while (!(UCSR0A & (1<<UDRE0)));
 
	UDR0 = byte;
 
}
 
 
void serial_SendCommand( char moduleID, char measureType, uint8_t dataLength, char* data )
 
{
 
	char checkSum = 0x00; //initialize checksum
 
	
 
	serial_SendChar('['); //bracket indicates start of command
 
	serial_SendChar(moduleID);
 
	checkSum+=moduleID;
 
	
 
	serial_SendChar(measureType);
 
	checkSum+=measureType;
 
	
 
	//send each character of data individually
 
	for (int i=0; i<dataLength; i++)
 
	{
 
		serial_SendChar(data[i]);
 
		checkSum+=data[i];
 
	}
 
	
 
	serial_SendChar(checkSum);
 
	serial_SendChar(']'); //bracket indicates end of command
 
}
 
 
void serial_SendResponseData(){
 
	
 
}
 
 
void serial_Configure() {
 
void serial_setup() {
 
	// Set registers!	
 
	
 
	// from mnl
 
	// uart
 
	//UBRRH = (BAUD_PRESCALE >> 8); // 0
 
	//UBRRL = BAUD_PRESCALE; // 8
 
	//UCSRA = 0;
 
	//UCSRB = 0x18;
 
	//UCSRC = 0x06;
 
	//OCR0B = 0xff;
 
	//OCR0A = 0xff;
 
	//OCR1AL = 0xff;
 
	//OCR1BL = 0xff;
 
 
 
 
}
master/master/lib/serial.h
Show inline comments
 
/*
 
 * serial.h
 
 *
 
 * Created: 10/25/2012 3:19:42 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
 
#ifndef SERIAL_H_
 
#define SERIAL_H_
 
 
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1 )
 
 
void serial_SendChar( char byte );
 
void serial_SendCommand( char moduleID, char measureType, uint8_t dataLength, char* data );
 
void serial_SendResponseData();
 
void serial_Configure();
 
void serial_setup();
 
 
#endif /* SERIAL_H_ */
 
\ No newline at end of file
master/master/lib/serparser.c
Show inline comments
 
/*
 
 * serparser.c
 
 *
 
 * Created: 10/25/2012 8:11:43 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
 
// ************* Macros ***************
 
#define SERIAL_RX_HASBYTES UCSRA & _BV(RXC)
 
#define SERIAL_RX_HASBYTES UCSR0A & _BV(RXC0)
 
#define MAX_CMD_LEN 8
 
#define BROADCAST_ADDR 0
 
 
//#define DEBUG
 
 
// ************* Command Definitions ***************
 
 
// Serial Commands
 
enum luma_cmd {  // CMD ID#
 
	BOARDTEMP = 0, // 0
 
	PRESSURE,      // 1
 
};
 
 
// Data length of each command, in bytes
 
uint8_t cmd_len[] = {
 
	2, // BOARDTEMP_LEN
 
	0, // PRESSURE_LEN
 
};
 
 
// Incoming command buffer
 
uint8_t buffer[MAX_CMD_LEN+2];
 
 
// Current buffer location
 
uint8_t buffercount = 0;
 
 
 
 
/* Get char from UART */
 
uint8_t uart_getchar(void)
 
{
 
	// Wait for chars
 
	while (!(UCSRA & (1<<RXC))){
 
		idle();
 
	while (!(UCSR0A & (1<<RXC0))){
 
		//idle
 
	}
 
	return UDR;
 
	return UDR0;
 
}
 
 
 
 
/* Process incoming serial data */
 
int uart_machine(void) {
 
 
	char byte;
 
 
	// Only process data if buffer has a byte
 
	if(SERIAL_RX_HASBYTES) {
 
		#ifdef DEBUG
 
		redflash();
 
		#endif
 
		
 
		// Pull byte off of the buffer
 
		byte = uart_getchar();
 
		buffer[buffercount] = byte;
 
 
		
 
		// Start byte
 
		if(buffercount == 0) {
 
			if(byte == '[') {
 
				// If this is a start byte, we're OK. Keep reading.
 
				buffercount++;
 
			}
 
			else {
 
				// Not a start byte that we're expecting. Reset to initial state.
 
				buffercount = 0;
 
			}
 
		}
 
		
 
		
 
	}
 
	else {
 
		return 0; // serial data not available
 
	}
 
}
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
/*
 
 * master.c
 
 *
 
 * Created: 10/25/2012 2:48:04 PM
 
 *  Author: mkanning
 
 */ 
 
 
 
#include "config.h"
 
 
#include <avr/io.h>
 
#include <util/delay.h>
 
 
#include "lib/serial.h"
 
#include "lib/afsk.h"
 
 
 
void micro_Configure() {
 
void micro_setup() {
 
	// Generic microcontroller config options
 
}
 
 
int main(void)
 
{
 
	// Initialize
 
	micro_Configure();
 
	led_Configure();
 
	serial_Configure(); // Config serial ports
 
	micro_setup();
 
	led_setup();
 
	serial_setup(); // Config serial ports
 
	afsk_setup();
 
	
 
    while(1)
 
    {
 
        serial_SendCommand('0','A',0,0);
 
		afsk_test();
 
        //serial_SendCommand('0','A',0,0);
 
    }
 
}
 
\ No newline at end of file
master/master/master.cproj
Show inline comments
 
<?xml version="1.0" encoding="utf-8"?>
 
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <PropertyGroup>
 
    <SchemaVersion>2.0</SchemaVersion>
 
    <ProjectVersion>6.0</ProjectVersion>
 
    <ToolchainName>com.Atmel.AVRGCC8</ToolchainName>
 
    <ProjectGuid>{8579ec2d-5815-40db-84e0-1d14239c7aea}</ProjectGuid>
 
    <avrdevice>ATmega644P</avrdevice>
 
    <avrdevice>ATmega324P</avrdevice>
 
    <avrdeviceseries>none</avrdeviceseries>
 
    <OutputType>Executable</OutputType>
 
    <Language>C</Language>
 
    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
 
    <OutputFileExtension>.elf</OutputFileExtension>
 
    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
 
    <AssemblyName>master</AssemblyName>
 
    <Name>master</Name>
 
    <RootNamespace>master</RootNamespace>
 
    <ToolchainFlavour>Native</ToolchainFlavour>
 
    <KeepTimersRunning>true</KeepTimersRunning>
 
    <OverrideVtor>false</OverrideVtor>
 
    <OverrideVtorValue />
 
    <eraseonlaunchrule>0</eraseonlaunchrule>
 
    <AsfVersion>3.1.3</AsfVersion>
 
    <avrtool>com.atmel.avrdbg.tool.simulator</avrtool>
 
    <avrtoolinterface />
 
    <avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
 
    <avrtoolinterface>ISP</avrtoolinterface>
 
    <com_atmel_avrdbg_tool_simulator>
 
      <ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
 
      <ToolName xmlns="">AVR Simulator</ToolName>
 
      <ToolNumber xmlns="">
 
      </ToolNumber>
 
      <KeepTimersRunning xmlns="">true</KeepTimersRunning>
 
      <OverrideVtor xmlns="">false</OverrideVtor>
 
      <OverrideVtorValue xmlns="">
 
      </OverrideVtorValue>
 
      <Channel xmlns="">
 
        <host>127.0.0.1</host>
 
        <port>52692</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
    </com_atmel_avrdbg_tool_simulator>
 
    <com_atmel_avrdbg_tool_ispmk2>
 
      <ToolType>com.atmel.avrdbg.tool.ispmk2</ToolType>
 
      <ToolName>AVRISP mkII</ToolName>
 
      <ToolNumber>000200131077</ToolNumber>
 
      <KeepTimersRunning>true</KeepTimersRunning>
 
      <OverrideVtor>false</OverrideVtor>
 
      <OverrideVtorValue>
 
      </OverrideVtorValue>
 
      <Channel>
 
        <host>127.0.0.1</host>
 
        <port>61309</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
      <ToolOptions>
 
        <InterfaceName>ISP</InterfaceName>
 
        <InterfaceProperties>
 
          <JtagDbgClock>249000</JtagDbgClock>
 
          <JtagProgClock>1000000</JtagProgClock>
 
          <IspClock>2010000</IspClock>
 
          <JtagInChain>false</JtagInChain>
 
          <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession>
 
          <JtagDevicesBefore>0</JtagDevicesBefore>
 
          <JtagDevicesAfter>0</JtagDevicesAfter>
 
          <JtagInstrBitsBefore>0</JtagInstrBitsBefore>
 
          <JtagInstrBitsAfter>0</JtagInstrBitsAfter>
 
        </InterfaceProperties>
 
      </ToolOptions>
 
    </com_atmel_avrdbg_tool_ispmk2>
 
    <preserveEEPROM>True</preserveEEPROM>
 
  </PropertyGroup>
 
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 
    <ToolchainSettings>
 
      <AvrGcc>
 
        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
 
        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
 
        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
 
        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
 
        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
 
        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
 
        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
 
        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
 
        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
 
        <avrgcc.linker.libraries.Libraries>
 
          <ListValues>
 
            <Value>m</Value>
 
          </ListValues>
 
        </avrgcc.linker.libraries.Libraries>
 
      </AvrGcc>
 
    </ToolchainSettings>
 
  </PropertyGroup>
 
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
 
    <ToolchainSettings>
 
      <AvrGcc>
 
        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
 
        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
 
        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
 
        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
 
        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
 
        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
 
        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
 
        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
 
        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
 
        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
 
        <avrgcc.linker.libraries.Libraries>
 
          <ListValues>
 
            <Value>m</Value>
 
          </ListValues>
 
        </avrgcc.linker.libraries.Libraries>
 
        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
 
      </AvrGcc>
 
    </ToolchainSettings>
 
  </PropertyGroup>
 
  <ItemGroup>
 
    <Compile Include="config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\afsk.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\afsk.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serial.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serial.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serparser.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\serparser.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="master.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
  </ItemGroup>
 
  <ItemGroup>
 
    <Folder Include="lib" />
 
  </ItemGroup>
 
  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
 
</Project>
 
\ No newline at end of file
slave/Makefile
Show inline comments
 
# Hey Emacs, this is a -*- makefile -*-
 
#----------------------------------------------------------------------------
 
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
 
#
 
# Released to the Public Domain
 
#
 
# Additional material for this makefile was written by:
 
# Peter Fleury
 
# Tim Henigan
 
# Colin O'Flynn
 
# Reiner Patommel
 
# Markus Pfaff
 
# Sander Pool
 
# Frederik Rouleau
 
# Carlos Lama
 
# Ethan Zonca
 
#
 
#----------------------------------------------------------------------------
 
# On command line:
 
#
 
# make all = Make software.
 
#
 
# make clean = Clean out built project files.
 
#
 
# make coff = Convert ELF to AVR COFF.
 
#
 
# make extcoff = Convert ELF to AVR Extended COFF.
 
#
 
# make program = Download the hex file to the device, using avrdude.
 
#                Please customize the avrdude settings below first!
 
#
 
# make debug = Start either simulavr or avarice as specified for debugging, 
 
#              with avr-gdb or avr-insight as the front end for debugging.
 
#
 
# make filename.s = Just compile filename.c into the assembler code only.
 
#
 
# make filename.i = Create a preprocessed source file for use in submitting
 
#                   bug reports to the GCC project.
 
#
 
# To rebuild project do "make clean" then "make all".
 
#----------------------------------------------------------------------------
 

	
 
AVRDUDE_PORT = usb
 

	
 

	
 
# Target file name (without extension).
 
TARGET = main
 

	
 

	
 
# List C source files here. (C dependencies are automatically generated.)
 
SRC =	$(TARGET).c
 

	
 
# MCU name, you MUST set this to match the board you are using
 
# type "make clean" after changing this, so all files will be rebuilt
 
#
 
MCU = atmega328p
 
MCU = atmega324p
 

	
 

	
 
# Processor frequency.
 
#   Normally the first thing your program should do is set the clock prescaler,
 
#   so your program will run at the correct speed.  You should also set this
 
#   variable to same clock speed.  The _delay_ms() macro uses this, and many
 
#   examples use this variable to calculate timings.  Do not add a "UL" here.
 
F_CPU = 16000000
 

	
 
F_CPU = 11059200
 
		
 

	
 
# Output format. (can be srec, ihex, binary)
 
FORMAT = ihex
 

	
 

	
 
# Object files directory
 
#     To put object files in current directory, use a dot (.), do NOT make
 
#     this an empty or blank macro!
 
OBJDIR = .
 

	
 

	
 
# List C++ source files here. (C dependencies are automatically generated.)
 
CPPSRC = 
 

	
 

	
 
# List Assembler source files here.
 
#     Make them always end in a capital .S.  Files ending in a lowercase .s
 
#     will not be considered source files but generated files (assembler
 
#     output from the compiler), and will be deleted upon "make clean"!
 
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
 
#     it will preserve the spelling of the filenames, and gcc itself does
 
#     care about how the name is spelled on its command-line.
 
ASRC =
 

	
 

	
 
# Optimization level, can be [0, 1, 2, 3, s]. 
 
#     0 = turn off optimization. s = optimize for size.
 
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
 
OPT = s
 

	
 

	
 
# Debugging format.
 
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
 
#     AVR Studio 4.10 requires dwarf-2.
 
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
 
DEBUG = dwarf-2
 

	
 

	
 
# List any extra directories to look for include files here.
 
#     Each directory must be seperated by a space.
 
#     Use forward slashes for directory separators.
 
#     For a directory that has spaces, enclose it in quotes.
 
EXTRAINCDIRS = 
 

	
 

	
 
# Compiler flag to set the C Standard level.
 
#     c89   = "ANSI" C
 
#     gnu89 = c89 plus GCC extensions
 
#     c99   = ISO C99 standard (not yet fully implemented)
 
#     gnu99 = c99 plus GCC extensions
 
CSTANDARD = -std=gnu99
 

	
 

	
 
# Place -D or -U options here for C sources
 
CDEFS = -DF_CPU=$(F_CPU)UL
 

	
 

	
 
# Place -D or -U options here for ASM sources
 
ADEFS = -DF_CPU=$(F_CPU)
 

	
 

	
 
# Place -D or -U options here for C++ sources
 
CPPDEFS = -DF_CPU=$(F_CPU)UL
 
#CPPDEFS += -D__STDC_LIMIT_MACROS
 
#CPPDEFS += -D__STDC_CONSTANT_MACROS
 

	
 

	
 

	
 
#---------------- Compiler Options C ----------------
 
#  -g*:          generate debugging information
 
#  -O*:          optimization level
 
#  -f...:        tuning, see GCC manual and avr-libc documentation
 
#  -Wall...:     warning level
 
#  -Wa,...:      tell GCC to pass this to the assembler.
 
#    -adhlns...: create assembler listing
 
CFLAGS = -g$(DEBUG)
 
CFLAGS += $(CDEFS)
 
CFLAGS += -O$(OPT)
 
CFLAGS += -funsigned-char
 
CFLAGS += -funsigned-bitfields
 
CFLAGS += -ffunction-sections
 
CFLAGS += -fpack-struct
 
CFLAGS += -fshort-enums
 
CFLAGS += -Wall
 
CFLAGS += -Wstrict-prototypes
 
#CFLAGS += -mshort-calls
 
#CFLAGS += -fno-unit-at-a-time
 
#CFLAGS += -Wundef
 
#CFLAGS += -Wunreachable-code
 
#CFLAGS += -Wsign-compare
 
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
 
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 
CFLAGS += $(CSTANDARD)
 

	
 

	
 
#---------------- Compiler Options C++ ----------------
 
#  -g*:          generate debugging information
 
#  -O*:          optimization level
 
#  -f...:        tuning, see GCC manual and avr-libc documentation
 
#  -Wall...:     warning level
 
#  -Wa,...:      tell GCC to pass this to the assembler.
 
#    -adhlns...: create assembler listing
 
CPPFLAGS = -g$(DEBUG)
 
CPPFLAGS += $(CPPDEFS)
 
CPPFLAGS += -O$(OPT)
 
CPPFLAGS += -funsigned-char
 
CPPFLAGS += -funsigned-bitfields
 
CPPFLAGS += -fpack-struct
 
CPPFLAGS += -fshort-enums
 
CPPFLAGS += -fno-exceptions
 
CPPFLAGS += -Wall
 
CPPFLAGS += -Wundef
 
#CPPFLAGS += -mshort-calls
 
#CPPFLAGS += -fno-unit-at-a-time
 
#CPPFLAGS += -Wstrict-prototypes
 
#CPPFLAGS += -Wunreachable-code
 
#CPPFLAGS += -Wsign-compare
 
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
 
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 
#CPPFLAGS += $(CSTANDARD)
 

	
 

	
 
#---------------- Assembler Options ----------------
 
#  -Wa,...:   tell GCC to pass this to the assembler.
 
#  -adhlns:   create listing
 
#  -gstabs:   have the assembler create line number information; note that
 
#             for use in COFF files, additional information about filenames
 
#             and function names needs to be present in the assembler source
 
#             files -- see avr-libc docs [FIXME: not yet described there]
 
#  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
 
#       dump that will be displayed for a given single line of source input.
 
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
 

	
 

	
 
#---------------- Library Options ----------------
 
# Minimalistic printf version
 
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
 

	
 
# Floating point printf version (requires MATH_LIB = -lm below)
 
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
 

	
 
# If this is left blank, then it will use the Standard printf version.
 
PRINTF_LIB = 
 
#PRINTF_LIB = $(PRINTF_LIB_MIN)
 
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
 

	
 

	
 
# Minimalistic scanf version
 
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
 

	
 
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
 
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
 

	
 
# If this is left blank, then it will use the Standard scanf version.
 
SCANF_LIB = 
 
#SCANF_LIB = $(SCANF_LIB_MIN)
 
#SCANF_LIB = $(SCANF_LIB_FLOAT)
 

	
 

	
 
MATH_LIB = -lm
 

	
 

	
 
# List any extra directories to look for libraries here.
 
#     Each directory must be seperated by a space.
 
#     Use forward slashes for directory separators.
 
#     For a directory that has spaces, enclose it in quotes.
 
EXTRALIBDIRS = 
 

	
 

	
 

	
 
#---------------- External Memory Options ----------------
 

	
 
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
 
# used for variables (.data/.bss) and heap (malloc()).
 
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
 

	
 
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
 
# only used for heap (malloc()).
 
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
 

	
 
EXTMEMOPTS =
 

	
 

	
 

	
 
#---------------- Linker Options ----------------
 
#  -Wl,...:     tell GCC to pass this to linker.
 
#    -Map:      create map file
 
#    --cref:    add cross reference to  map file
 
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
 
LDFLAGS += -Wl,--relax
 
LDFLAGS += -Wl,--gc-sections
 
LDFLAGS += $(EXTMEMOPTS)
 
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
 
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
 
#LDFLAGS += -T linker_script.x
 

	
 

	
 

	
 
#---------------- Programming Options (avrdude) ----------------
 

	
 
# Programming hardware
 
# Type: avrdude -c ?
 
# to get a full listing.
 
#
 
AVRDUDE_PROGRAMMER = usbasp
 

	
 
# com1 = serial port. Use lpt1 to connect to parallel port.
 
#AVRDUDE_PORT = com1    # programmer connected to serial device
 

	
 
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
 
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 

	
 

	
 
# Uncomment the following if you want avrdude's erase cycle counter.
 
# Note that this counter needs to be initialized first using -Yn,
 
# see avrdude manual.
 
#AVRDUDE_ERASE_COUNTER = -y
 

	
 
# Uncomment the following if you do /not/ wish a verification to be
 
# performed after programming the device.
 
#AVRDUDE_NO_VERIFY = -V
 

	
 
# Increase verbosity level.  Please use this when submitting bug
 
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
 
# to submit bug reports.
 
#AVRDUDE_VERBOSE = -v -v
 

	
 
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
 
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
 
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
 

	
 

	
 

	
 
#---------------- Debugging Options ----------------
 

	
 
# For simulavr only - target MCU frequency.
 
DEBUG_MFREQ = $(F_CPU)
 

	
 
# Set the DEBUG_UI to either gdb or insight.
 
# DEBUG_UI = gdb
 
DEBUG_UI = insight
 

	
 
# Set the debugging back-end to either avarice, simulavr.
 
DEBUG_BACKEND = avarice
 
#DEBUG_BACKEND = simulavr
 

	
 
# GDB Init Filename.
 
GDBINIT_FILE = __avr_gdbinit
 

	
 
# When using avarice settings for the JTAG
 
JTAG_DEV = /dev/com1
 

	
 
# Debugging port used to communicate between GDB / avarice / simulavr.
 
DEBUG_PORT = 4242
 

	
 
# Debugging host used to communicate between GDB / avarice / simulavr, normally
 
#     just set to localhost unless doing some sort of crazy debugging when 
 
#     avarice is running on a different computer.
 
DEBUG_HOST = localhost
 

	
 

	
 

	
 
#============================================================================
 

	
 

	
 
# Define programs and commands.
 
SHELL = sh
 
CC = avr-gcc
 
OBJCOPY = avr-objcopy
 
OBJDUMP = avr-objdump
 
SIZE = avr-size
 
AR = avr-ar rcs
 
NM = avr-nm
 
AVRDUDE = avrdude
 
REMOVE = rm -f
 
REMOVEDIR = rm -rf
 
COPY = cp
 
WINSHELL = cmd
 

	
 

	
 
# Define Messages
 
# English
 
MSG_ERRORS_NONE = Errors: none
 
MSG_BEGIN = -------- begin --------
 
MSG_END = --------  end  --------
 
MSG_SIZE_BEFORE = Size before: 
 
MSG_SIZE_AFTER = Size after:
 
MSG_COFF = Converting to AVR COFF:
 
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
 
MSG_FLASH = Creating load file for Flash:
 
MSG_EEPROM = Creating load file for EEPROM:
 
MSG_EXTENDED_LISTING = Creating Extended Listing:
 
MSG_SYMBOL_TABLE = Creating Symbol Table:
 
MSG_LINKING = Linking:
 
MSG_COMPILING = Compiling C:
 
MSG_COMPILING_CPP = Compiling C++:
 
MSG_ASSEMBLING = Assembling:
 
MSG_CLEANING = Cleaning project:
 
MSG_CREATING_LIBRARY = Creating library:
 

	
 

	
 

	
 

	
 
# Define all object files.
 
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) 
 

	
 
# Define all listing files.
 
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) 
 

	
 

	
 
# Compiler flags to generate dependency files.
 
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
 

	
 

	
 
# Combine all necessary flags and optional flags.
 
# Add target processor to flags.
 
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
 
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
 
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 

	
 

	
 
# Default target.
 
all: begin gccversion sizebefore build sizeafter end
 

	
 
# Change the build target to build a HEX file or a library.
 
build: elf hex eep lss sym
 
	avrdude -P $(AVRDUDE_PORT) -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -q -e -U flash:w:$(TARGET).hex
 

	
 
#build: lib
 

	
 
elf: $(TARGET).elf
 
hex: $(TARGET).hex
 
eep: $(TARGET).eep
 
lss: $(TARGET).lss
 
sym: $(TARGET).sym
 
LIBNAME=lib$(TARGET).a
 
lib: $(LIBNAME)
 

	
 

	
 

	
 
# Eye candy.
 
# AVR Studio 3.x does not check make's exit code but relies on
 
# the following magic strings to be generated by the compile job.
 
begin:
 
	@echo
 
	@echo $(MSG_BEGIN)
 

	
 
end:
 
	@echo $(MSG_END)
 
	@echo
 

	
 

	
 
# Display size of file.
 
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
 
#ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
 
ELFSIZE = $(SIZE) $(TARGET).elf
 

	
 
sizebefore:
 
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
 
	2>/dev/null; echo; fi
 

	
 
sizeafter:
 
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
 
	2>/dev/null; echo; fi
 

	
 

	
 

	
 
# Display compiler version information.
 
gccversion : 
 
	@$(CC) --version
 

	
 

	
 

	
 
# Program the device.  
 
program: $(TARGET).hex $(TARGET).eep
 
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 

	
 

	
 
# Generate avr-gdb config/init file which does the following:
 
#     define the reset signal, load the target file, connect to target, and set 
 
#     a breakpoint at main().
 
gdb-config: 
 
	@$(REMOVE) $(GDBINIT_FILE)
slave/main.c
Show inline comments
 
/*
 
 * Slave Firmware
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 

	
 
#include <stdint.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h> 
 
#include <util/delay.h>
 
#include <avr/pgmspace.h>
 

	
 

	
 
PROGMEM extern const prog_uchar afsk_sine_table[512] = {
 
  127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 143, 144, 146, 147, 149, 150, 152, 153, 155, 156, 158, 
 
  159, 161, 163, 164, 166, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, 183, 184, 186, 187, 188, 
 
  190, 191, 193, 194, 195, 197, 198, 199, 200, 202, 203, 204, 205, 207, 208, 209, 210, 211, 213, 214, 215, 
 
  216, 217, 218, 219, 220, 221, 223, 224, 225, 226, 227, 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 
 
  236, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 
 
  249, 250, 250, 251, 251, 251, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 
 
  254, 254, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 253, 253, 253, 253, 252, 252, 252, 251, 
 
  251, 251, 250, 250, 249, 249, 249, 248, 248, 247, 247, 246, 245, 245, 244, 244, 243, 242, 242, 241, 240, 
 
  239, 239, 238, 237, 236, 236, 235, 234, 233, 232, 231, 230, 229, 228, 228, 227, 226, 225, 224, 223, 221, 
 
  220, 219, 218, 217, 216, 215, 214, 213, 211, 210, 209, 208, 207, 205, 204, 203, 202, 200, 199, 198, 197, 
 
  195, 194, 193, 191, 190, 188, 187, 186, 184, 183, 182, 180, 179, 177, 176, 174, 173, 171, 170, 168, 167, 
 
  166, 164, 163, 161, 159, 158, 156, 155, 153, 152, 150, 149, 147, 146, 144, 143, 141, 139, 138, 136, 135, 
 
  133, 132, 130, 129, 127, 125, 124, 122, 121, 119, 118, 116, 115, 113, 111, 110, 108, 107, 105, 104, 102, 
 
  101,  99,  98,  96,  95,  93,  91,  90,  88,  87,  86,  84,  83,  81,  80,  78,  77,  75,  74,  72,  71, 
 
   70,  68,  67,  66,  64,  63,  61,  60,  59,  57,  56,  55,  54,  52,  51,  50,  49,  47,  46,  45,  44, 
 
   43,  41,  40,  39,  38,  37,  36,  35,  34,  33,  31,  30,  29,  28,  27,  26,  26,  25,  24,  23,  22, 
 
   21,  20,  19,  18,  18,  17,  16,  15,  15,  14,  13,  12,  12,  11,  10,  10,   9,   9,   8,   7,   7, 
 
    6,   6,   5,   5,   5,   4,   4,   3,   3,   3,   2,   2,   2,   1,   1,   1,   1,   0,   0,   0,   0, 
 
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   1,   1,   1, 
 
    2,   2,   2,   3,   3,   3,   4,   4,   5,   5,   5,   6,   6,   7,   7,   8,   9,   9,  10,  10,  11, 
 
   12,  12,  13,  14,  15,  15,  16,  17,  18,  18,  19,  20,  21,  22,  23,  24,  25,  26,  26,  27,  28, 
 
   29,  30,  31,  33,  34,  35,  36,  37,  38,  39,  40,  41,  43,  44,  45,  46,  47,  49,  50,  51,  52, 
 
   54,  55,  56,  57,  59,  60,  61,  63,  64,  66,  67,  68,  70,  71,  72,  74,  75,  77,  78,  80,  81, 
 
   83,  84,  86,  87,  88,  90,  91,  93,  95,  96,  98,  99, 101, 102, 104, 105, 107, 108, 110, 111, 113, 
 
  115, 116, 118, 119, 121, 122, 124, 125
 
};
 

	
 
inline uint8_t afsk_read_sample(int phase)
 
{
 
  return pgm_read_byte_near(afsk_sine_table + phase);
 
}
 

	
 
volatile uint16_t state = 0;
 
volatile uint8_t up = 1;
 

	
 
int main(void)
 
{
 
  _delay_ms(4);
 

	
 
  // Source timer2 from clkIO (datasheet p.164)
 
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
 

	
 
  // Set fast PWM mode with TOP = 0xff: WGM22:0 = 3  (p.150)
 
  TCCR2A |= _BV(WGM21) | _BV(WGM20);
 
  TCCR2B &= ~_BV(WGM22);
 

	
 
  // Do non-inverting PWM on pin OC2B (arduino pin 3) (p.159).
 
  // OC2A (arduino pin 11) stays in normal port operation:
 
  // COM2B1=1, COM2B0=0, COM2A1=0, COM2A0=0
 
  TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0));
 

	
 
  // No prescaler (p.162)
 
  //TCCR2B = (TCCR2B & ~(_BV(CS22) | _BV(CS21))) | _BV(CS20);
 
  TCCR2B = CS22 | CS21 |  CS20;
 
    
 
  // Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163)
 
	//TIMSK2 |= _BV(TOIE2);
 
	TIMSK2 |= 0b00000111;
 

	
 
	
 
	
 
	
 

	
 
	// Initialize PORTA
 
	DDRA = 0xff;
 
	PORTA = 0x00;
 
	
 
	DDRD = 0xff;
 
	PORTD = 0xff;
 
	
 
	sei();
 

	
 
		
 
	while(1) {
 
		//PORTA ++;
 
		/*
 
		if(state < 512) {
 
			OCR2B = afsk_sine_table[state];
 
		}
 
		else {
 
			state = 0;
 
			OCR2B = afsk_sine_table[state];
 
		}
 
			*/
 
		/*
 
		OCR2B = afsk_sine_table[state];
 
		
 

	
 
		if(up==1)
 
			state++;
 
		else
 
			state--;
 

	
 
		if(state <= 0)
 
			up = 1;
 
		else if(state >= 254)
 
			up = 0;
 
			*/
 
		_delay_us(10);
 
	}
 
}
 

	
 

	
 
volatile uint8_t meh = 1;
 

	
 
void frick() {
 
	meh = meh + 5;
 
	//OCR2B = 0x09;
 
	OCR2B += meh;// = meh;// = afsk_read_sample(meh);
 
}
 

	
 
ISR(TIMER2_OVF_vect) {
 
/*
 
	PORTA = 0xff;
 
	_delay_ms(500);
 
	PORTA = 0x00;
 
	_delay_ms(500);  */
 
	frick();
 
	//meh++;
 
	//OCR2B = 0x90;
 
	/*
 
  // [...] load the next sample
 
  if(state < 512) {
 
	OCR2B = afsk_sine_table[state];
 
	}
 
	else {
 
		state = 0;
 
	}*/
 

	
 

	
 
			
 
	return;
 
}
0 comments (0 inline, 0 general)