/*! * @brief ADC channel0 callback for fetching sample data. */ static void adc_chn0_isr_callback(void) { uint16_t temp = 0; //ADC0_SE4b if((ADC0_SC1A & 0x1F) == 0x04) { g_uiAI3_Current = ADC16_DRV_GetConvValueRAW(ADC_INST, 0); g_uiAI3[g_ucAI3Count++] = g_uiAI3_Current; temp = ADC0_SC1A; temp &= ~0x1F; temp|= 0x09; ADC0_SC1A = temp; if(g_ucAI3Count == NR_SAMPLES) { g_ucAI3Count = 0; } } else if((ADC0_SC1A & 0x1F) == 0x09) { g_uiAI1_Current = ADC16_DRV_GetConvValueRAW(ADC_INST, 0); g_uiAI1[g_ucAI1Count++] = g_uiAI1_Current; temp = ADC0_SC1A; temp &= ~0x1F; //temp|= 0x0F; temp|= 0x04; ADC0_SC1A = temp; if(g_ucAI1Count == NR_SAMPLES) { g_ucAI1Count = 0; } } //ADC0_SE15 else if((ADC0_SC1A & 0x1F) == 0x0F) { g_uiAI2_Current = ADC16_DRV_GetConvValueRAW(ADC_INST, 0); g_uiAI2[g_ucAI2Count++] = g_uiAI2_Current; temp = ADC0_SC1A; temp &= ~0x1F; temp|= 0x04; ADC0_SC1A = temp; if(g_ucAI2Count == NR_SAMPLES) { g_ucAI2Count = 0; } } //PC3_T = 1; //PC3 = 0; }
/*! * @brief ADC channel1 callback for fetching sample data. */ static void adc_chn1_isr_callback(void) { static uint8_t j = 0, k = 0; uint32_t temp = 0; //ADC0_SE9 if((ADC0_SC1B & 0x1F) == 0x9) { g_uiAI1[j++] = ADC16_DRV_GetConvValueRAW(ADC_INST, 1); temp = ADC0_SC1B; temp &= ~0x1F; temp|= 0x0F; ADC0_SC1B = temp; if(j == NR_SAMPLES) { j = 0; } } //ADC0_SE15 else if((ADC0_SC1B & 0x1F) == 0xF) { g_uiAI2[k++] = ADC16_DRV_GetConvValueRAW(ADC_INST, 1); temp = ADC0_SC1B; temp &= ~0x1F; temp|= 0x04; ADC0_SC1B = temp; if(k == NR_SAMPLES) { k = 0; } } }
/* User-defined ADC ISR. */ static void ADC_TEST_IRQHandler(uint32_t instance) { uint32_t chnGroup; for (chnGroup = 0U; chnGroup < ADC_SC1_COUNT; chnGroup++) { if ( ADC16_DRV_GetChnFlag(instance, chnGroup, kAdcChnConvCompleteFlag) ) { g_AdcValueInt[instance][chnGroup] = ADC16_DRV_GetConvValueRAW(instance, chnGroup); if ( g_AdcTestCallback[instance][chnGroup] ) { (void)(*(g_AdcTestCallback[instance][chnGroup]))(); } } } }
/*! * Get the temperature pointer * designed for BM version of I2C_RTOS demo * from the ISR context */ uint8_t* get_temp_pointer(void) { uint32_t adcValue; // ADC starts conversion ADC16_DRV_ConfigConvChn(HWADC_INSTANCE, 0U, &tempSnseChannelConfig); // poll to complete status and read back result ADC16_DRV_WaitConvDone(HWADC_INSTANCE, 0U); adcValue = ADC16_DRV_GetConvValueRAW(HWADC_INSTANCE, 0U); adcValue = ADC16_DRV_ConvRAWData(adcValue, false, tempSnseAdcConfig.resolutionMode); // ADC stop conversion ADC16_DRV_PauseConv(HWADC_INSTANCE, 0U); // convert to temperature Temperature = (M1 - (adcValue - VTEMP25_ADC) * M2)/K; return (uint8_t*)&Temperature; }
/*! * @brief Main demo function */ int main(void) { uint8_t cnt; int32_t row; // init the hardware board hardware_init(); PRINTF("\r\nadc_hw_trigger demo running...\r\n\r\n"); #ifdef USE_DAC_OUT_AS_SOURCE // use DAC to generate the sine wave dac_gen_wave(); #else // If no DAC can be use, then a function generator should // be used to generate a signal wave, and connect to ADC input #endif // initialize the ADC if (init_adc(ADC_INST)) { PRINTF("Failed to do the ADC init\r\n"); return -1; } // setup the HW trigger source init_trigger_source(ADC_INST); // init the print chart array sparse_reset(); for (cnt = 0; cnt < NR_SAMPLES; cnt++) { uint16_t result; double tmpRatio; while (gAdcDone != true) { ; } result = ADC16_DRV_GetConvValueRAW(ADC_INST, (uint32_t)gCurChan); gAdcDone = false; // insert the sample data into the sparse matrix tmpRatio = (double)result / RATIO; row = (int32_t)tmpRatio; if (row >= CHART_ROWS) { row = CHART_ROWS - 1; } // fill one samples into sparse matrix sparse_insert(row, cnt); } // print the chart for (row = CHART_ROWS - 1; row >= 0; row --) { sparse_node_ptr p = gChartHead[row]; uint32_t last = 0; while (p) { for (; last < p->value; last++) { PRINTF(" "); } PRINTF("*"); p = p->next; last++; } PRINTF("\r\n"); } // disable the adc0 ADC16_DRV_Deinit(ADC_INST); // disable hw trigger source deinit_trigger_source(ADC_INST); #ifdef USE_DAC_OUT_AS_SOURCE // disable dac source dac_stop_wave(); #endif while(1) {} }
/*FUNCTION********************************************************************* * * Function Name : ADC16_DRV_GetConvValueSigned * Description : Get the latest conversion value with signed. * *END*************************************************************************/ int16_t ADC16_DRV_GetConvValueSigned(uint32_t instance, uint32_t chnGroup) { return (int16_t)ADC16_DRV_GetConvValueRAW(instance, chnGroup); }
void DutVSense::updateADCVal(void) { ADC16_DRV_ConfigConvChn(dut_adc_IDX, SELFADC_CHNGROUP, &adcChConfig); rawADCVal = ADC16_DRV_GetConvValueRAW(dut_adc_IDX, SELFADC_CHNGROUP); floatADCVal.asFloat = (float)rawADCVal*scalingFactor; }