Changeset - 02b6a488f4ee
[Not reviewed]
default
0 5 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-01 14:53:54
ethanzonca@CL-SEC241-08.cedarville.edu
Work on AFSK, minor mods to slave
5 files changed with 113 insertions and 97 deletions:
0 comments (0 inline, 0 general)
master/master/lib/afsk.c
Show inline comments
 
@@ -2,24 +2,12 @@
 
 * 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 <stdbool.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h> 
 
@@ -52,66 +40,21 @@ PROGMEM extern const uint8_t afsk_sine_t
 
   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)
 
static 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;
 
	
 
	// todo: init radio, maybe in main
 
	
 
	sei();
 
}
 

	
 

	
 
void afsk_test() {	
 
	uint8_t flap[26] = {"abcdefghijklmnopqrstuvwxyz"};
 
	afsk_send(flap, sizeof(flap)*8);
 
	afsk_start();
 
	while(afsk_busy());
 
	_delay_ms(500);
 
}
 

	
 

	
 

	
 

	
 
// constants
 
#define MODEM_CLOCK_RATE F_CPU
 
#define PLAYBACK_RATE MODEM_CLOCK_RATE / 256  // Fast PWM
 

	
 
#define BAUD_RATE 1200
 
//#define SAMPLES_PER_BAUD PLAYBACK_RATE / BAUD_RATE // = 36
 
@@ -133,47 +76,28 @@ volatile unsigned int packet_pos;       
 

	
 

	
 
volatile unsigned int afsk_packet_size = 10;
 
volatile const uint8_t *afsk_packet;
 

	
 

	
 
void afsk_send(const uint8_t *buffer, int len)
 
{
 
	afsk_packet_size = len;
 
	afsk_packet = buffer;
 
}
 

	
 

	
 

	
 
int afsk_busy()
 
{
 
	return go;
 

	
 
void afsk_ptt_off() {
 
	// turn ptt off
 
}
 

	
 
void afsk_start()
 
{
 
	phasedelta = PHASE_DELTA_1200;
 
	phase = 0;
 
	packet_pos = 0;
 
	current_sample_in_baud = 0;
 
	go = true;
 

	
 
	// Key the radio
 
	afsk_ptt_on();
 

	
 
	// Start transmission
 
	afsk_timer_start();
 
void afsk_ptt_on() {
 
	// turn the ptt on... possibly delay based on spec
 
}
 

	
 

	
 

	
 
afsk_ptt_off() {
 
	
 
}
 

	
 
afsk_ptt_on() {
 
	
 
}
 

	
 

	
 
ISR(TIMER2_OVF_vect) 
 
{
 
	if (go) {
 

	
 
@@ -232,6 +156,81 @@ void afsk_timer_stop()
 
	// Output 0v (could be 255/2, which is 0v after coupling... doesn't really matter)
 
	OCR2B = 0x80;
 

	
 
	// Disable playback interrupt
 
	TIMSK2 &= ~_BV(TOIE2);
 
}
 

	
 

	
 

	
 

	
 

	
 
// External
 

	
 
void afsk_start()
 
{
 
	phasedelta = PHASE_DELTA_1200;
 
	phase = 0;
 
	packet_pos = 0;
 
	current_sample_in_baud = 0;
 
	go = true;
 

	
 
	// Key the radio
 
	afsk_ptt_on();
 

	
 
	// Start transmission
 
	afsk_timer_start();
 
}
 

	
 
int afsk_busy()
 
{
 
	return go;
 
}
 

	
 
void afsk_send(const uint8_t *buffer, int len)
 
{
 
	afsk_packet_size = len;
 
	afsk_packet = buffer;
 
}
 

	
 

	
 
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;
 
	
 
	// todo: init radio, maybe in main
 
	
 
	sei();
 
}
 

	
 

	
 
void afsk_test() {
 
	uint8_t flap[26] = {"abcdefghijklmnopqrstuvwxyz"};
 
	afsk_send(flap, sizeof(flap)*8);
 
	afsk_start();
 
	while(afsk_busy());
 
	_delay_ms(500);
 
}
master/master/lib/afsk.h
Show inline comments
 
@@ -8,10 +8,11 @@
 
 
#ifndef AFSK_H_
 
#define AFSK_H_
 
 
void afsk_setup();
 
void afsk_test();
 
void afsk_send(const uint8_t *buffer, int len);
 
int afsk_busy();
 
void afsk_start();
 
void afsk_stop();
 
 
#endif /* AFSK_H_ */
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
/*
 
 * master.c
 
 * Master Firmware
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 *
 
 * Created: 10/25/2012 2:48:04 PM
 
 *  Author: mkanning
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */ 
 
 
 
#include "config.h"
 
 
#include <avr/io.h>
master/master/master.cproj
Show inline comments
 
@@ -117,12 +117,18 @@
 
    <Compile Include="lib\afsk.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\afsk.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\ax25.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\ax25.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
slave2/slave/slave/slave.c
Show inline comments
 
/*
 
 * slave.c
 
 * Slave Firmware
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 *
 
 * Created: 10/25/2012 9:59:40 PM
 
 *  Author: mkanning
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
 #include "config.h"
 
 
 #include <avr/io.h>
 
 #include <util/delay.h>
 
 
 #include "lib/serial.h"
 
 
#include "lib/led.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
 
	 
 
	 while(1)
 
	 {
 
		 serial_SendCommand('0','A',0,0);
 
        //serial_SendCommand('0','A',0,0);
 
	 }
 
 }
 
\ No newline at end of file
0 comments (0 inline, 0 general)