Hi,
I have written a simple ADC program for getting the raw count. But somehow the program is not working according to my expectations. The program does not go in CC_Callback when i run it for the first time, When i run it again i get the raw count as 3????. Can someone help me with this. //////////////////////////////////////////////////////////////////// #include "stdio.h" #include "stdlib.h" #include "port.h" #include "arch.h" #include "io.h" #include "string.h" #include "fcntl.h" #include "assert.h" #include "adc.h" #include "led.h" #include "periph.h" #include "gpio.h" #include "types.h" #include "quadraturetimer.h" #include "appconst.h" #include "bsp.h" #include "dspfunc.h" int zeroCnt; /* sero crossing counter */ void ADC_Zero_Crossing_CallBack_ISR( adc_eCallbackType type, adc_tSampleMask causedSampleMask ); int CCFlag; /* synchronization flag */ int CCFlag_B; /* synchronization flag for ADC B */ int AdcVal[8]; unsigned int AdcFd[8]; int DataLen[8]; int iLoop; const adc_sState sadc0 = { /* AnalogChannel = */ ADC_CHANNEL_0, /* SampleMask = */ 0x01, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ ADC_ZC_ANY, }; const adc_sState sadc4 = { /* AnalogChannel = */ ADC_CHANNEL_4, /* SampleMask = */ 0x10, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc1 = { /* AnalogChannel = */ ADC_CHANNEL_1, /* SampleMask = */ 0x02, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc5 = { /* AnalogChannel = */ ADC_CHANNEL_5, /* SampleMask = */ 0x20, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc2 = { /* AnalogChannel = */ ADC_CHANNEL_2, /* SampleMask = */ 0x04, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc6 = { /* AnalogChannel = */ ADC_CHANNEL_6, /* SampleMask = */ 0x40, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc3 = { /* AnalogChannel = */ ADC_CHANNEL_3, /* SampleMask = */ 0x08, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; const adc_sState sadc7 = { /* AnalogChannel = */ ADC_CHANNEL_7, /* SampleMask = */ 0x80, /* OffsetRegister = */ FRAC16(0.0), /* LowLimitRegister = */ 0, /* HighLimitRegister = */ 0, /* ZeroCrossing = */ 0, }; void CC_CallBack_ADC_A( adc_eCallbackType type, adc_tSampleMask causedSampleMask ); //void CC_CallBack_B( adc_eCallbackType type, adc_tSampleMask causedSampleMask ); void main (void) { //---- Open the spacific Adc channel; AdcFd[0] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc0 ); AdcFd[1] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc1 ); AdcFd[2] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc2 ); AdcFd[3] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc3 ); AdcFd[4] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc4 ); AdcFd[5] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc5 ); AdcFd[6] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc6 ); AdcFd[7] = open(BSP_DEVICE_NAME_ADC_0, 0, &sadc7 ); //-----Start scanning of ADC channels; CCFlag = 0; ioctl( AdcFd[0], ADC_START, 0 ); //--- When the scan is over read the data from ADC. } /********************************************************************* ******** * * Module: ZeroCallBack * * Description: Zero call back example * * Returns: none * * Arguments: none * * Range Issues: * * Special Issues: * * Test Method: * ********************************************************************** *******/ void ADC_Zero_Crossing_CallBack_ISR( adc_eCallbackType type, adc_tSampleMask causedSampleMask ) { zeroCnt++; } /********************************************************************* ******** * * Module: CC_CallBack * * Description: CC call back example * * Returns: none * * Arguments: none * * Range Issues: * * Special Issues: * * Test Method: * ********************************************************************** *******/ void CC_CallBack_ADC_A( adc_eCallbackType type, adc_tSampleMask causedSampleMask ) { CCFlag = 1; for (iLoop = 0; iLoop < 8; iLoop++) { DataLen[iLoop] = adcRead (AdcFd[iLoop], &AdcVal [iLoop], sizeof (AdcVal[iLoop])); // read (AdcFd[iLoop], &AdcVal [iLoop], sizeof (AdcVal [iLoop])); } } //////////////////////////////////////////////////////////////////// |
Why the following program is not working?
Started by ●July 22, 2003