Exemple #1
0
//*****************************************************************************
//
// File Name	: 'a2d.c'
// Title		: Analog-to-digital converter functions
// Author		: Pascal Stang - Copyright (C) 2002
// Created		: 2002-04-08
// Revised		: 2002-09-30
// Version		: 1.1
// Target MCU	: Atmel AVR series
// Editor Tabs	: 4
//
// Modified by  : Markus Joos ([email protected])
//
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//*****************************************************************************

#include <avr/io.h>
#include <avr/interrupt.h>
#include "global.h"
#include "a2d.h"


// initialize a2d converter
//***************/
void a2dInit(void)    //Called from sdr.c
//***************/
{
	sbi(ADCSR, ADEN);				        // enable ADC (turn on ADC power)
	sbi(ADCSR, ADFR);				        // free running mode
	a2dSetPrescaler(ADC_PRESCALE);	        // set default prescaler
	a2dSetReference(ADC_REFERENCE_AREF);	// set default reference
	sbi(ADMUX, ADLAR);				        // set to left-adjusted result
}
Exemple #2
0
// Now create any global variables such as motors, servos, sensors etc
// This routine is called once only and allows you to do set up the hardware
// Dont use any 'clock' functions here - use 'delay' functions instead
void appInitHardware(void){
	a2dSetPrescaler(ADC_PRESCALE_DIV128);

	cyrf6936_Initialise_hard();


	// Initialise SPI bus as master. (RF modules connected to hardware SPI)
    spiBusInit(&bus, TRUE);
	spiDeviceSelect(&cyrf_0, TRUE);
	spiDeviceSelect(&cyrf_0, FALSE);
	spiDeviceSelect(&cyrf_1, TRUE);
	spiDeviceSelect(&cyrf_1, FALSE);

	// set I/O pins for RF module(s).
	pin_make_input(D4, FALSE);		// set PACTL pin to input. (module on connector J1)
	pin_make_input(D5, FALSE);		// set PACTLn pin to input. (module on connector J1)
	pin_make_input(D6, FALSE);		// set PACTL pin to input. (module on connector J2)
	pin_make_input(D7, FALSE);		// set PACTLn pin to input. (module on connector J2)

#ifdef RF_MODULE_ARTAFLEX
	//
	pin_make_output(D4, FALSE);			// set RXPA pin to output. (module on connector J1)
	pin_make_output(D5, FALSE);			// set TXPA pin to output. (module on connector J1)
	pin_make_output(D6, FALSE);			// set RXPA pin to output. (module on connector J2)
	pin_make_output(D7, FALSE);			// set TXPA pin to output. (module on connector J2)
#endif

	pin_make_input(E7, TRUE);		// set UNIGEN RF module IRQ pin to input. (module on connector J1)
	pin_make_input(E6, TRUE);		// set UNIGEN RF module IRQ pin to input. (module on connector J2)
	pin_make_output(G3, FALSE);			// set UNIGEN RF module RST pin to output. (both modules)
	//pin_low(G3);					// don't reset yet.

	// set I/O pins for status LEDs
	pin_make_output(C0, TRUE);			// set LED pin for output
	pin_make_output(C1, TRUE);			// set LED pin for output
	pin_make_output(C2, FALSE);			// set LED pin for output
	//pin_high(C0);					// LED off
	//pin_high(C1);					// LED off
	//pin_low(C2);					// LED on


	// Set UART1 to 19200 baud
    uartInit(UART1, 38400);
    // Tell rprintf to output to UART1
    rprintfInit(&uart1SendByte);


    // Initialise the servo controller using Hardware PWM
    servoPWMInit(&bank1);


    // Initialise WatchDog Timer
    wdt_enable( WDTO_500MS );

}
Exemple #3
0
//----- Begin Code ------------------------------------------------------------
int main(void)
{
	u16 a=0;
	u08 i=0;

	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// make all rprintf statements use uart for output
	rprintfInit(uartSendByte);
	// initialize the timer system
	timerInit();
	// turn on and initialize A/D converter
	a2dInit();

	// print a little intro message so we know things are working
	vt100ClearScreen();
	vt100SetCursorPos(1,1);
	rprintf("Welcome to the a2d test!\r\n");
	
	// configure a2d port (PORTA) as input
	// so we can receive analog signals
	DDRA = 0x00;
	// make sure pull-up resistors are turned off
	PORTA = 0x00;

	// set the a2d prescaler (clock division ratio)
	// - a lower prescale setting will make the a2d converter go faster
	// - a higher setting will make it go slower but the measurements
	//   will be more accurate
	// - other allowed prescale values can be found in a2d.h
	a2dSetPrescaler(ADC_PRESCALE_DIV32);

	// set the a2d reference
	// - the reference is the voltage against which a2d measurements are made
	// - other allowed reference values can be found in a2d.h
	a2dSetReference(ADC_REFERENCE_AVCC);

	// use a2dConvert8bit(channel#) to get an 8bit a2d reading
	// use a2dConvert10bit(channel#) to get a 10bit a2d reading

	while(1)
	{
		// sample all a2d channels and print them to the terminal
		vt100SetCursorPos(2,1);
		for(i=0; i<8; i++)
		{
			rprintf("Channel %d: %d   \r\n", i, a2dConvert8bit(i));
		}
		// print the sample number so far
		rprintf("Sample # : %d   \r\n", a++);
	}
	
	return 0;
}
// initialize a2d converter
void a2dInit(void)
{
	sbi(ADCSR, ADEN);				// enable ADC (turn on ADC power)
	cbi(ADCSR, ADFR);				// default to single sample convert mode
	a2dSetPrescaler(ADC_PRESCALE);	// set default prescaler
	a2dSetReference(ADC_REFERENCE);	// set default reference
	cbi(ADMUX, ADLAR);				// set to right-adjusted result

	sbi(ADCSR, ADIE);				// enable ADC interrupts

	a2dCompleteFlag = FALSE;		// clear conversion complete flag
}
Exemple #5
0
Fichier : a2d.c Projet : borand/AVR
// initialize a2d converter
void a2dInit(void)
{
	sbi(ADCSR, ADEN);				// enable ADC (turn on ADC power)
#ifndef atmega328P
	//cbi(PRR,PRADC);
#endif
	cbi(ADCSR, ADFR);				// default to single sample convert mode
	a2dSetPrescaler(ADC_PRESCALE);	// set default prescaler
	a2dSetReference(ADC_REFERENCE);	// set default reference
	cbi(ADMUX, ADLAR);				// set to right-adjusted result

	sbi(ADCSR, ADIE);				// enable ADC interrupts

	a2dCompleteFlag = FALSE;		// clear conversion complete flag
	sei();							// turn on interrupts (if not already on)
}
int main(void) {
	configure_ports(); 
    a2dInit();  
	a2dSetPrescaler(ADC_PRESCALE_DIV32);  
	a2dSetReference(ADC_REFERENCE_AVCC); 
    
    init_servos();
	LED_on();
    
    neutral();
    hold_pos();
    
    while (1) {
        move_forward();
    //    sustain_pos();
    }
    
	return 0;
}
void setup() {

  uart0Init();
  uartSetBaudRate(0, 9600);
  rprintfInit(uart0SendByte);
  rprintf("$Id$");

  // this goes to the switch common
  sbi(DDRA, DDA0); // output on PA0
  sbi(PORTA, PA0); // take it high

  cbi(DDRA, DDA1); 
  cbi(DDRA, DDA2);
  cbi(DDRA, DDA3);
  cbi(DDRA, DDA4);
  cbi(DDRA, DDA5);

  a2dInit();
  a2dSetReference(ADC_REFERENCE_AVCC);
  a2dSetPrescaler(ADC_PRESCALE_DIV128);

  sbi(DDRB, PB3); // output for the LED
  sbi(PORTB, PB3);
 }
Exemple #8
0
int main(void)
{
  /****************INITIALIZATIONS*******************/
  //other stuff Im experimenting with for SoR
  uartInit();  // initialize the UART (serial port)
  uartSetBaudRate(0, 9600); // set UARTE speed, for Bluetooth
  uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it
  uartSetBaudRate(2, 57600); // set UARTH speed
  uartSetBaudRate(3, 57600); // set UARTJ speed, for Blackfin
  //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

  // initialize rprintf system and configure uart1 (USB) for rprintf
  rprintfInit(uart1SendByte);

  configure_ports(); // configure which ports are analog, digital, etc.

  LED_on();

  rprintf("\r\nSystem Warming Up");

  // initialize the timer system (comment out ones you don't want)
  init_timer0(TIMER_CLK_1024);
  init_timer1(TIMER_CLK_64);
  init_timer2(TIMER2_CLK_64);
  init_timer3(TIMER_CLK_64);
  init_timer4(TIMER_CLK_64);
  init_timer5(TIMER_CLK_1024);
  //timer5Init();

  a2dInit(); // initialize analog to digital converter (ADC)
  a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
  a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

  int i = 0, j = 0;
  //let system stabelize for X time
  for(i=0;i<16;i++)
  {
    j=a2dConvert8bit(i);//read each ADC once to get it working accurately
    delay_cycles(5000); //keep LED on long enough to see Axon reseting
    rprintf(".");
  }

  LED_off();

  rprintf("Initialization Complete \r\n");

  reset_timer0();
  reset_timer1();
  reset_timer2();
  reset_timer3();
  reset_timer4();
  reset_timer5();

  while(1)
  {
    control();
    delay_cycles(100);
    //an optional small delay to prevent crazy oscillations
  }

  return 0;
}
Exemple #9
0
void prvSetupHardware(){

	int i, j;

	//add 1.7s delay for potential power issues
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	delay_cycles(65535);
	
	

	uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
    uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work
    uartSetBaudRate(2, 38400); // set UARTH speed
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
	//G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

	rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

	configure_ports(); // configure which ports are analog, digital, etc.

	LED_on();

	//rprintf("\r\nSystem Warmed Up");

	// initialize the timer system
 	init_timer0(TIMER_CLK_1024);
// 	init_timer1(TIMER_CLK_64); // Timer 1 is initialized by FreeRTOS
 	init_timer2(TIMER2_CLK_64);
 	init_timer3(TIMER_CLK_64);
 	init_timer4(TIMER_CLK_64);
 	init_timer5(TIMER_CLK_64);

	a2dInit(); // initialize analog to digital converter (ADC)
	a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
	a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

	//let system stabelize for X time
	for(i=0;i<16;i++)
		{
		j=a2dConvert8bit(i);//read each ADC once to get it working accurately
		delay_cycles(5000); //keep LED on long enough to see Axon reseting
		rprintf(".");
		}

	LED_off();

	rprintf("Initialization Complete \r\n");

	//reset all timers to zero
	reset_timer0();
	reset_timer1();
	reset_timer2();
	reset_timer3();
	reset_timer4();
	reset_timer5();



	/********PWM Setup***********/
	prvPWMSetup();

}