I am trying to use the ADC to read a particular voltage. The ADCs that have been set up are the follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
void HAL_setupAdcs(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *)handle; // disable the ADCs ADC_disable(obj->adcHandle); // power up the bandgap circuit ADC_enableBandGap(obj->adcHandle); // set the ADC voltage reference source to internal ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int); // enable the ADC reference buffers ADC_enableRefBuffers(obj->adcHandle); // power up the ADCs ADC_powerUp(obj->adcHandle); // enable the ADCs ADC_enable(obj->adcHandle); // set the ADC interrupt pulse generation to prior ADC_setIntPulseGenMode(obj->adcHandle,ADC_IntPulseGenMode_Prior); // set the temperature sensor source to external ADC_setTempSensorSrc(obj->adcHandle,ADC_TempSensorSrc_Ext); // configure the interrupt sources ADC_disableInt(obj->adcHandle,ADC_IntNumber_1); ADC_setIntMode(obj->adcHandle,ADC_IntNumber_1,ADC_IntMode_ClearFlag); ADC_setIntSrc(obj->adcHandle,ADC_IntNumber_1,ADC_IntSrc_EOC7); //configure the SOCs for boostxldrv8305evm_revA // sample the first sample twice due to errata sprz342f // ISEN_A ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,ADC_SocChanNumber_B1); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_0,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ADC_SocSampleDelay_7_cycles); // ISEN_A ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,ADC_SocChanNumber_B1); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_1,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ADC_SocSampleDelay_7_cycles); // ISEN_B ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,ADC_SocChanNumber_B3); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_2,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ADC_SocSampleDelay_7_cycles); // ISEN_C ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,ADC_SocChanNumber_B7); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_3,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ADC_SocSampleDelay_7_cycles); // VSEN_A ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,ADC_SocChanNumber_A7); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_4,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ADC_SocSampleDelay_7_cycles); // VSEN_B ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,ADC_SocChanNumber_A3); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_5,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ADC_SocSampleDelay_7_cycles); // VSEN_C ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,ADC_SocChanNumber_A1); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_6,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ADC_SocSampleDelay_7_cycles); // V_PVDD ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,ADC_SocChanNumber_A0); ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_7,ADC_SocTrigSrc_EPWM1_ADCSOCA); ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ADC_SocSampleDelay_7_cycles); //ADC for switch ADC_setSocChanNumber (obj->adcHandle, ADC_SocNumber_8, ADC_SocChanNumber_A4); //set SOC0 channel select to ADCINA4 ADC_setSocChanNumber (obj->adcHandle, ADC_SocNumber_9, ADC_SocChanNumber_A4); ADC_setSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 ADC_setSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_8, ADC_SocSampleDelay_7_cycles); //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_9, ADC_SocSampleDelay_7_cycles); //set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) // //SWITCH // ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_8,ADC_SocChanNumber_A2); // ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_8,ADC_SocTrigSrc_EPWM1_ADCSOCA); // ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ADC_SocSampleDelay_7_cycles); return ; } // end of HAL_setupAdcs() function |
In my main I have created an interrupt to get the voltage counts at the ADC using the following function achieved from the ADC example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
__interrupt void adc_isr( void ) { //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0 Voltage1[ConversionCount] = ADC_readResult(myAdc, ADC_ResultNumber_8); Voltage2[ConversionCount] = ADC_readResult(myAdc, ADC_ResultNumber_9); // If 10 conversions have been logged, start over if (ConversionCount == 9) { ConversionCount = 0; } else { ConversionCount++; } // Clear ADCINT1 flag reinitialize for next SOC ADC_clearIntFlag(myAdc, ADC_IntNumber_1); // Acknowledge interrupt to PIE PIE_clearInt(myPie, PIE_GroupNumber_10); return ; } |
I am getting some random values which are above 4096 which is supposed to be between 0-3.3 V. The voltage at my ADC pin is almost 1 V .
I have a motor driver 8305 with the 28027 as the controller.
I am not sure if this is the right way of setting up an ADC but if possible can someone refer me to a document if there is on setting up an ADC.
Regards,
Rajan Joshi