/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); USB_Init(); // // Setup sensor power pins // DDRD = 0; PORTD = 0; // Configure ADC ADC_Init(ADC_PRESCALE_32 | ADC_FREE_RUNNING); // Setup sensor read pins ADC_SetupChannel(0); ADC_SetupChannel(1); ADC_SetupChannel(4); ADC_SetupChannel(5); ADC_SetupChannel(6); ADC_SetupChannel(7); ADC_SetupChannel(12); ADC_SetupChannel(13); }
uint16_t hardware_analogRead(uint8_t ch) { uint32_t buf = 0; // Initialize the ADC driver before first use ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); // Must setup the ADC channel to read beforehand if(ch < 15) ADC_SetupChannel(ch); if(ch > 7) ch = (1 << 8 | ((ch - 8) << MUX0)); else ch = ch << MUX0; // Perform a single conversion of the ADC channel 1 // buf = ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ch); // Start reading ADC channel 1 in free running (continuous conversion) mode ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ch); for(uint8_t i = 0; i < ADC_READINGS; i++) { while (!(ADC_IsReadingComplete())); buf += ADC_GetResult(); } // Leave ADC Disabled to save power ADC_Disable(); return (uint16_t)(buf / ADC_READINGS); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ inline static void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ LEDs_Init(); Buttons_Init(); //button HWB Joystick_Init(); //gate driving output - PORTC.6 / PWM-A Timer3 DDRC |= (1<<PC6); PORTC &= ~(1<<PC6); Init_PWM_timer(); /* conversion mode (free running or single) and prescaler masks * ACDSRA: start ADC, clock prescaler, interrupt, trigger enable, start single conv */ ADC_Init( ADC_SINGLE_CONVERSION | ADC_PRESCALE_128); /* Must setup the ADC channel to read beforehand */ ADC_SetupChannel(3); ADC_SetupChannel(4); /* Start the ADC conversion in free running mode * ADMUX and Vref, adjust, sel mux channel with gain * */ //ADC_StartReading(ADC_REFERENCE_INT2560MV | ADC_RIGHT_ADJUSTED | ADC_1100MV_BANDGAP); //Temperature_Init(); //Dataflash_Init(); SerialStream_Init(9600, false); }
/** Initializes the hardware and software associated with the V2 protocol command handling. */ void V2Protocol_Init(void) { #if defined(ADC) /* Initialize the ADC converter for VTARGET level detection on supported AVR models */ ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); ADC_SetupChannel(VTARGET_ADC_CHANNEL); ADC_StartReading(VTARGET_REF_MASK | ADC_RIGHT_ADJUSTED | VTARGET_ADC_CHANNEL_MASK); #endif V2Params_LoadNonVolatileParamValues(); #if defined(ENABLE_ISP_PROTOCOL) ISPTarget_ConfigureRescueClock(); #endif }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ LEDs_Init(); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_SetupChannel(MIC_IN_ADC_CHANNEL); USB_Init(); /* Start the ADC conversion in free running mode */ ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK); }
/** Initialises the hardware and software associated with the V2 protocol command handling. */ void V2Protocol_Init(void) { #if defined(ADC) /* Initialize the ADC converter for VTARGET level detection on supported AVR models */ ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); ADC_SetupChannel(VTARGET_ADC_CHANNEL); ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | VTARGET_ADC_CHANNEL_MASK); #endif /* Timeout timer initialization (10ms period) */ OCR0A = (((F_CPU / 1024) / 100) - 1); TCCR0A = (1 << WGM01); TIMSK0 = (1 << OCIE0A); V2Params_LoadNonVolatileParamValues(); #if defined(ENABLE_ISP_PROTOCOL) ISPTarget_ConfigureRescueClock(); #endif }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ Serial_Init(9600, false); LEDs_Init(); Buttons_Init(); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_SetupChannel(MIC_IN_ADC_CHANNEL); USB_Init(); /* Create a stdio stream for the serial port for stdin and stdout */ Serial_CreateStream(NULL); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Hardware Initialization */ Serial_Init(9600, false); Buttons_Init(); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_SetupChannel(MIC_IN_ADC_CHANNEL); LEDs_Init(); USB_Init(); /* Create a stdio stream for the serial port for stdin and stdout */ Serial_CreateStream(NULL); /* Start the ADC conversion in free running mode */ ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_GET_CHANNEL_MASK(MIC_IN_ADC_CHANNEL)); }