/******************************************************************************* * Function Name: adc_Start ******************************************************************************** * * Summary: * Performs all required initialization for this component * and enables the power. The power will be set to the appropriate * power based on the clock frequency. * * Parameters: * None. * * Return: * None. * * Global variables: * The adc_initVar variable is used to indicate when/if initial * configuration of this component has happened. The variable is initialized to * zero and set to 1 the first time ADC_Start() is called. This allows for * component Re-Start without re-initialization in all subsequent calls to the * adc_Start() routine. * If re-initialization of the component is required the variable should be set * to zero before call of adc_Start() routine, or the user may call * adc_Init() and adc_Enable() as done in the * adc_Start() routine. * *******************************************************************************/ void adc_Start(void) { /* If not Initialized then initialize all required hardware and software */ if(adc_initVar == 0u) { adc_Init(); adc_initVar = 1u; } adc_Enable(); }
int main(void) { // set gpio as outputs DDR_SHUNT_EN1 |= (1 << BIT_SHUNT_EN1); DDR_SHUNT_EN2 |= (1 << BIT_SHUNT_EN2); DDR_SHUNT_SEL |= (1 << BIT_SHUNT_SEL); DDR_GPIO3 |= (1 << BIT_GPIO3); DDR_MODE_A |= (1 << BIT_MODE_A); DDR_MODE_B |= (1 << BIT_MODE_B); DDR_ANALOG_MUX |= (1 << BIT_ANALOG_MUX); adc_Init(); spi_Init(); sei(); uint8_t ports = 0; uint8_t resultCounter = 0; uint16_t resultSum = 0; while (1) { if (!(ADCSRA & (1 << ADSC))) { // ADC has finished a conversion if (resultCounter >= 17) { resultSum += ADC; // save result and switch to next channel adc.channels[adc.currentChannel] = resultSum / 16; // increase current channel adc.currentChannel = (adc.currentChannel + 1) % 9; // set next conversion channel if (adc.currentChannel != 8) { // select next channel ADMUX = adc.currentChannel | (1 << REFS0); } else { // select 1.1V bandgap as eighth channel ADMUX = 0x0E | (1 << REFS0); } resultCounter = 0; } else { if (resultCounter == 0) { resultSum = 0; } else { resultSum += ADC; } resultCounter++; } // start next conversion ADCSRA |= (1 << ADSC); } } }
int main() { // This is needed for FreeRTOS. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); InitDebug(); cfg_Init( ); PolePosition_Init(); // This MUST be initialized before fullCAN MotorPosition_Init(FEEDBACK_POLE_POSITION); fullCAN_Init( 1000000, cfg_GetControllerID() ); if ( cfg_GetControllerID() == 0) { fullCAN_SetTerminationState(ENABLE); } else { fullCAN_SetTerminationState(DISABLE); } d1k_STDIO_CAN_Init( CAN2, fullCAN_GetControllerId() + FULLCAN_IDBASE_STDIO_TX, fullCAN_GetControllerId() + FULLCAN_IDBASE_STDIO_RX ); d1k_portal_Init( ); ControlLoopInit(); InitLEDs( ); adc_Init( 100000 ); motor_Init( ); fault_Init( ); diag_Init( ); fan_Init( ); fan_SetDutyCycle( 1.0f ); printf("fullStartup! Controller: %u\r\n", (uint16)fullCAN_GetControllerId()); vTaskStartScheduler( ); }
void zclEnergyHarvester_Init( byte task_id ) { zclEnergyHarvester_TaskID = task_id; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleLight_SimpleDesc ); // Register for a test endpoint afRegister( &testEp ); zcl_registerPlugin( ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT, ZCL_CLUSTER_ID_MS_ALL, zclEnergyHarvester_HdlIncoming ); ZDO_RegisterForZDOMsg( zclEnergyHarvester_TaskID, End_Device_Bind_rsp ); #if DEV_TYPE == COORDINATOR ZDO_RegisterForZDOMsg( zclEnergyHarvester_TaskID, Device_annce ); #else adc_Init(); // Configure signal from off-chip timer to be wake-up signal GPIODirModeSet( GPIO_B_BASE, GPIO_PIN_3 , GPIO_DIR_MODE_IN ); // Configure deep sleep in power mode 3, woken up by off-chip timer SysCtrlDeepSleepSetting(); SysCtrlPowerModeSet( SYS_CTRL_PM_3 ); GPIODirModeSet( GPIO_B_BASE, GPIO_PIN_4 , GPIO_DIR_MODE_IN ); HWREG( SYS_CTRL_IWE ) = 0x02; GPIOPowIntTypeSet( GPIO_B_BASE, GPIO_PIN_4, GPIO_POW_RISING_EDGE ); GPIOPowIntClear( GPIO_B_BASE, GPIO_PIN_4 ); GPIOPowIntEnable( GPIO_B_BASE, GPIO_PIN_4 ); // Done with off-chip timer acknowledge GPIOPinWrite( GPIO_B_BASE, GPIO_PIN_5, GPIO_PIN_5 ); #endif }