硬體使用的是 LAUNCHXL-F280049C LaunchPad Kit
目前參考的文件為SPRUI33C
參考的程式範例為
"C2000ware_2_00_00_02/driverlib/f28004x/examples/adc/adc_ex1_soc_software"
"C2000ware_2_00_00_02/driverlib/f28004x/examples/adc/adc_ex2_soc_epwm"
"C2000ware_2_00_00_02/driverlib/f28004x/examples/adc/adc_ex3_temp_sensor"
讀取的值會有亂跳的現象,以及當我同時使用ADCA, ADCB, ADCC BASE 會有一些通道並沒有辦法讀取資料
可否請教有人可以教教我讀取ADC
程式碼如下:
voidinitADCs(void)
{
//
// Setup VREF as internal
//
ADC_setVREF(ADCA_BASE,ADC_REFERENCE_INTERNAL,ADC_REFERENCE_3_3V);
ADC_setVREF(ADCB_BASE,ADC_REFERENCE_INTERNAL,ADC_REFERENCE_3_3V);
ADC_setVREF(ADCC_BASE,ADC_REFERENCE_INTERNAL,ADC_REFERENCE_3_3V);
//
// Set ADCCLK divider to /4
//
ADC_setPrescaler(ADCA_BASE,ADC_CLK_DIV_1_0);
ADC_setPrescaler(ADCB_BASE,ADC_CLK_DIV_1_0);
ADC_setPrescaler(ADCC_BASE,ADC_CLK_DIV_1_0);
//
// Set pulse positions to late
//
ADC_setInterruptPulseMode(ADCA_BASE,ADC_PULSE_END_OF_CONV);
ADC_setInterruptPulseMode(ADCB_BASE,ADC_PULSE_END_OF_CONV);
ADC_setInterruptPulseMode(ADCC_BASE,ADC_PULSE_END_OF_CONV);
//
// Power up the ADC and then delay for 1 ms
//
ADC_enableConverter(ADCA_BASE);
ADC_enableConverter(ADCB_BASE);
ADC_enableConverter(ADCC_BASE);
DEVICE_DELAY_US(1000);
}
voidinitADCSOCs(void)
{
//
// Configure SOC0 of ADCA to convert pin A0 with a sample window of 10
// SYSCLK cycles. The EPWM1SOCA signal will be the trigger.
//
ADC_setupSOC(ADCA_BASE,ADC_SOC_NUMBER0,ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN0, 10);
ADC_setupSOC(ADCA_BASE,ADC_SOC_NUMBER0,ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN2, 10);
//
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
//
ADC_setInterruptSource(ADCA_BASE,ADC_INT_NUMBER1,ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCA_BASE,ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE,ADC_INT_NUMBER1);
ADC_setupSOC(ADCB_BASE,ADC_SOC_NUMBER0,ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN2, 10);
ADC_setupSOC(ADCB_BASE,ADC_SOC_NUMBER0,ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN3, 10);
//
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
//
ADC_setInterruptSource(ADCB_BASE,ADC_INT_NUMBER1,ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCB_BASE,ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCB_BASE,ADC_INT_NUMBER1);
}
ADC_forceSOC(ADCA_BASE,ADC_SOC_NUMBER0);
ADC_forceSOC(ADCA_BASE,ADC_SOC_NUMBER2);
ADC_forceSOC(ADCB_BASE,ADC_SOC_NUMBER2);
ADC_forceSOC(ADCB_BASE,ADC_SOC_NUMBER3);
ADC_forceSOC(ADCC_BASE,ADC_SOC_NUMBER4);
adcBResult3 = (AdcbResultRegs.ADCRESULT3);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcAResult0 = (AdcaResultRegs.ADCRESULT0);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcAResult2 = (AdcaResultRegs.ADCRESULT2);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcAResult6 = (AdcaResultRegs.ADCRESULT6);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcBResult2 = (AdcbResultRegs.ADCRESULT2);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcCResult0 = (AdccResultRegs.ADCRESULT0);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
adcCResult2 = (AdccResultRegs.ADCRESULT2);
for(Delay_FOR_ANY=0; Delay_FOR_ANY<1; Delay_FOR_ANY++){}
//AdcbRegs.ADCOFFTRIM.bit.OFFTRIM = addoffset;
adcAResult0 = ADC_readResult(ADCARESULT_BASE,ADC_SOC_NUMBER0);
adcAResult2 = ADC_readResult(ADCARESULT_BASE,ADC_SOC_NUMBER2);
adcAResult6 = ADC_readResult(ADCARESULT_BASE,ADC_SOC_NUMBER6);
adcBResult2 = ADC_readResult(ADCBRESULT_BASE,ADC_SOC_NUMBER2);
adcBResult3 = ADC_readResult(ADCBRESULT_BASE,ADC_SOC_NUMBER3);
adcCResult0 = ADC_readResult(ADCCRESULT_BASE,ADC_SOC_NUMBER0);
adcCResult2 = ADC_readResult(ADCCRESULT_BASE,ADC_SOC_NUMBER2);
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
Susan Yang:
“讀取的值會有亂跳的現象,以及當我同時使用ADCA, ADCB, ADCC BASE 會有一些通道並沒有辦法讀取資料”
能否详细说明一下?
另外若是可以的话,请上传或者私信给我您的整个工程?我明天拿板子测试一下,谢谢
user4310360:
回复 Susan Yang:
請問我該私信到哪個信箱呢?
在線等~
Susan Yang:
回复 user4310360:
点击我的头像到我的个人页面,而后点击右面的 连接 按钮
user4310360:
回复 Susan Yang:
已經在信了,是否有收到呢?
在線等~
Susan Yang:
回复 user4310360:
刚刚收到了,我会在下载后测试
Susan Yang:
回复 Susan Yang:
我测试了一下,结果如下
不知道您的结果是否也是这样?
我现在的输入信号是0-2V的正弦波,当不加任何信号input时,也是这样的结果
根据现象看的话,应该是您现在的程序中存在问题,导致了没有实际采集到input
Susan Yang:
回复 Susan Yang:
要是测量A0 内部温度传感器的话,例程内是需要加外部参考电压 3.3V的
能否告知下您现在的测试结果?
user4310360:
回复 Susan Yang:
對,其結果並沒有實際採集到輸入源
user4310360:
回复 Susan Yang:
A0的通道是否也可以把其當作一般的ADC通道?我並沒有要測量內部溫度傳感器
Susan Yang:
回复 user4310360:
可以的,在例程adc_ex1_soc_software中就是使用的A0