Implemented variable VREF for DAC and ADC
This commit is contained in:
parent
cf186ba64a
commit
8b2e66eb57
2
Makefile
2
Makefile
|
@ -28,7 +28,7 @@ FORMAT = ihex
|
||||||
|
|
||||||
# List C source files here. (C dependencies are automatically generated.)
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
#SRC = $(TARGET).c
|
#SRC = $(TARGET).c
|
||||||
SRC = main.c hardware/Serial.c hardware/AFSK.c util/CRC-CCIT.c protocol/AX25.c protocol/KISS.c
|
SRC = main.c hardware/Serial.c hardware/AFSK.c hardware/VREF.c util/CRC-CCIT.c protocol/AX25.c protocol/KISS.c
|
||||||
|
|
||||||
# If there is more than one source file, append them above, or modify and
|
# If there is more than one source file, append them above, or modify and
|
||||||
# uncomment the following:
|
# uncomment the following:
|
||||||
|
|
8
device.h
8
device.h
|
@ -8,9 +8,13 @@
|
||||||
#define F_CPU 20000000UL
|
#define F_CPU 20000000UL
|
||||||
#define FREQUENCY_CORRECTION 0
|
#define FREQUENCY_CORRECTION 0
|
||||||
|
|
||||||
// ADC settings
|
// Voltage references
|
||||||
|
// TODO: Determine best defaults
|
||||||
|
#define CONFIG_ADC_REF 128
|
||||||
|
#define CONFIG_DAC_REF 255
|
||||||
|
|
||||||
|
// Demodulator settings
|
||||||
#define OPEN_SQUELCH true
|
#define OPEN_SQUELCH true
|
||||||
#define ADC_REFERENCE REF_3V3
|
|
||||||
|
|
||||||
// Serial settings
|
// Serial settings
|
||||||
#define BAUD 115200
|
#define BAUD 115200
|
||||||
|
|
|
@ -22,7 +22,6 @@ int afsk_putchar(char c, FILE *stream);
|
||||||
|
|
||||||
// ADC and clock setup
|
// ADC and clock setup
|
||||||
void AFSK_hw_init(void) {
|
void AFSK_hw_init(void) {
|
||||||
|
|
||||||
// Set Timer1 to normal operation
|
// Set Timer1 to normal operation
|
||||||
TCCR1A = 0;
|
TCCR1A = 0;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ inline static uint8_t sinSample(uint16_t i) {
|
||||||
#define CONFIG_AFSK_TRAILER_LEN 25UL
|
#define CONFIG_AFSK_TRAILER_LEN 25UL
|
||||||
#define BIT_STUFF_LEN 5
|
#define BIT_STUFF_LEN 5
|
||||||
|
|
||||||
#define BITRATE 2400
|
#define BITRATE 1200
|
||||||
|
|
||||||
#if BITRATE == 1200
|
#if BITRATE == 1200
|
||||||
#define CONFIG_SAMPLERATE 9600UL
|
#define CONFIG_SAMPLERATE 9600UL
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "VREF.h"
|
||||||
|
|
||||||
|
uint8_t adcReference = CONFIG_ADC_REF;
|
||||||
|
uint8_t dacReference = CONFIG_DAC_REF;
|
||||||
|
|
||||||
|
void VREF_init(void) {
|
||||||
|
//DDRD |= _BV(7);
|
||||||
|
DDRD = 0xFF;
|
||||||
|
|
||||||
|
TCCR2A = _BV(WGM20) |
|
||||||
|
_BV(WGM21) |
|
||||||
|
_BV(COM2A1)|
|
||||||
|
_BV(COM2B1);
|
||||||
|
|
||||||
|
TCCR2B = _BV(CS20);
|
||||||
|
|
||||||
|
OCR2A = adcReference;
|
||||||
|
OCR2B = dacReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vref_setADC(uint8_t value) {
|
||||||
|
adcReference = value;
|
||||||
|
OCR2A = adcReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vref_setDAC(uint8_t value) {
|
||||||
|
dacReference = value;
|
||||||
|
OCR2B = dacReference;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef VREF_H
|
||||||
|
#define VREF_H
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
void VREF_init(void);
|
||||||
|
void vref_setADC(uint8_t value);
|
||||||
|
void vref_setDAC(uint8_t value);
|
||||||
|
|
||||||
|
#endif
|
2
main.c
2
main.c
|
@ -2,6 +2,7 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "hardware/VREF.h"
|
||||||
#include "hardware/AFSK.h"
|
#include "hardware/AFSK.h"
|
||||||
#include "hardware/Serial.h"
|
#include "hardware/Serial.h"
|
||||||
#include "protocol/AX25.h"
|
#include "protocol/AX25.h"
|
||||||
|
@ -25,6 +26,7 @@ void init(void) {
|
||||||
stdout = &serial.uart0;
|
stdout = &serial.uart0;
|
||||||
stdin = &serial.uart0;
|
stdin = &serial.uart0;
|
||||||
|
|
||||||
|
VREF_init();
|
||||||
AFSK_init(&modem);
|
AFSK_init(&modem);
|
||||||
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
|
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue