专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
TI
ADC用TI的官方例程总是转换一两次之后就停了
2019-07-21 18:04
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
11771
7
914
ADC用TI的官方例程总是转换一两次之后就停了,求可能原因
转换程序是放在while循环里面的,求指导,无论打断点还是串口打印,循环不过3次
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答
火山LF
2019-07-22 01:36
本帖最后由 火山LF 于 2016-8-24 08:25 编辑
恭喜你,跟我情况一样,刚看到这帖子的时候,我还以为是我发的那个呢
可能的原因:
1、 没有配置低速时钟造成休眠后无法唤醒的情况
2、 单步调试遇到进入低功耗状态,还有延时循环等等,不要和编译器耗着,该跳过跳过,或者注释掉
3、 调试的时候你可以把进入低功耗状态注释掉,或者用几个NOP指令代替
下面是我修改的例程,你要是不行的话,用用我的(MSP430RF5969)我的板子是这块
#include "driverlib.h"
uint16_t Value_AD = 0;
uint16_t ADC_Get_Value = 0; // ADC采到的原始数据
uint16_t ADV_Get_Aver_Value = 0; //用于计算采ADC100次的平均值
void main(void)
{
// Stop WDT
WDT_A_hold(WDT_A_BASE);
//Set P1.0 as an output pin.
/*
* Select Port 1
* Set Pin 0 as output
*/
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN0
);
//Set P1.0 as Output Low.
/*
* Select Port 1
* Set Pin 0 to output Low.
*/
GPIO_setOutputLowOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
//Set P1.1 as Ternary Module Function Output.
/*
* Select Port 1
* Set Pin 1 to output Ternary Module Function, (A1, C1, VREF+, VeREF+).
*/
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN0,
GPIO_TERNARY_MODULE_FUNCTION
);
/*
* Disable the GPIO power-on default high-impedance mode to activate
* previously configured port settings
*/
PMM_unlockLPM5();
//Initialize the ADC12B Module
/*
* Base address of ADC12B Module
* Use internal ADC12B bit as sample/hold signal to start conversion
* USE MODOSC 5MHZ Digital Oscillator as clock source
* Use default clock divider/pre-divider of 1
* Not use internal channel
*/
ADC12_B_initParam initParam = {0};
initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
initParam.internalChannelMap = ADC12_B_NOINTCH;
ADC12_B_init(ADC12_B_BASE, &initParam);
//Enable the ADC12B module
ADC12_B_enable(ADC12_B_BASE);
/*
* Base address of ADC12B Module
* For memory buffers 0-7 sample/hold for 64 clock cycles
* For memory buffers 8-15 sample/hold for 4 clock cycles (default)
* Disable Multiple Sampling
*/
ADC12_B_setupSamplingTimer(ADC12_B_BASE,
ADC12_B_CYCLEHOLD_64_CYCLES,
ADC12_B_CYCLEHOLD_64_CYCLES,
ADC12_B_MULTIPLESAMPLESDISABLE);
//Configure Memory Buffer
/*
* Base address of the ADC12B Module
* Configure memory buffer 0
* Map input A1 to memory buffer 0
* Vref+ = AVcc
* Vref- = AVss
* Memory buffer 0 is not the end of a sequence
*/
ADC12_B_configureMemoryParam configureMemoryParam = {0};
configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A12;
configureMemoryParam.refVoltageSourceSelect =
ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
configureMemoryParam.windowComparatorSelect =
ADC12_B_WINDOW_COMPARATOR_DISABLE;
configureMemoryParam.differentialModeSelect =
ADC12_B_DIFFERENTIAL_MODE_DISABLE;
ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
ADC12_B_clearInterrupt(ADC12_B_BASE,
0,
ADC12_B_IFG0
);
//Enable memory buffer 0 interrupt
ADC12_B_enableInterrupt(ADC12_B_BASE,
ADC12_B_IE0,
0,
0);
while(1)
{
__delay_cycles(5000);
//Enable/Start sampling and conversion
/*
* Base address of ADC12B Module
* Start the conversion into memory buffer 0
* Use the single-channel, single-conversion mode
*/
ADC12_B_startConversion(ADC12_B_BASE,
ADC12_B_MEMORY_0,
ADC12_B_SINGLECHANNEL);
__no_operation(); // For debugger
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(ADC12_VECTOR)))
#endif
void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,12))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC12BMEMx Overflow
case 4: break; // Vector 4: Conversion time overflow
case 6: break; // Vector 6: ADC12BHI
case 8: break; // Vector 8: ADC12BLO
case 10: break; // Vector 10: ADC12BIN
case 12: // Vector 12: ADC12BMEM0 Interrupt
Value_AD = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
ADC_Get_Value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
if (ADV_Get_Aver_Value == 0) {
ADV_Get_Aver_Value = ADC_Get_Value;
}
ADC_Get_Value = (ADV_Get_Aver_Value + ADC_Get_Value) / 2;
ADV_Get_Aver_Value = ADC_Get_Value;
if(ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0) >= 0x7ff)
{
//Set P1.0 LED on
/*
* Select Port 1
* Set Pin 0 to output high.
*/
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
}
else
{
//Set P1.0 LED off
/*
* Select Port 1
* Set Pin 0 to output high.
*/
GPIO_setOutputLowOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
}
复制代码
后面我发现其实有低功耗的模式也是可以的,你也可以尝试把你的CCS关闭,重新打开再试一试,之前不可以,过了一天发现又可以了
你所选择的通道外接了电压没有?
加载中...
查看其它7个回答
一周热门
更多
>
相关问题
CPLD的方波输出
4 个回答
11个版本Quartus II 软件下载,安装包网盘合集,附教程,47G!
20 个回答
请大家帮忙到21IC发展大家谈支持我申请新版面
20 个回答
【通知】21ic中国电子网服务条款 (所有人员必读)
1 个回答
满载而归乙亥年,大展鸿途庚子年---集签赢好礼
20 个回答
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
TI
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
恭喜你,跟我情况一样,刚看到这帖子的时候,我还以为是我发的那个呢
可能的原因:
1、 没有配置低速时钟造成休眠后无法唤醒的情况
2、 单步调试遇到进入低功耗状态,还有延时循环等等,不要和编译器耗着,该跳过跳过,或者注释掉
3、 调试的时候你可以把进入低功耗状态注释掉,或者用几个NOP指令代替
下面是我修改的例程,你要是不行的话,用用我的(MSP430RF5969)我的板子是这块
- #include "driverlib.h"
- uint16_t Value_AD = 0;
- uint16_t ADC_Get_Value = 0; // ADC采到的原始数据
- uint16_t ADV_Get_Aver_Value = 0; //用于计算采ADC100次的平均值
- void main(void)
- {
- // Stop WDT
- WDT_A_hold(WDT_A_BASE);
- //Set P1.0 as an output pin.
- /*
- * Select Port 1
- * Set Pin 0 as output
- */
- GPIO_setAsOutputPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- //Set P1.0 as Output Low.
- /*
- * Select Port 1
- * Set Pin 0 to output Low.
- */
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- //Set P1.1 as Ternary Module Function Output.
- /*
- * Select Port 1
- * Set Pin 1 to output Ternary Module Function, (A1, C1, VREF+, VeREF+).
- */
- GPIO_setAsPeripheralModuleFunctionOutputPin(
- GPIO_PORT_P3,
- GPIO_PIN0,
- GPIO_TERNARY_MODULE_FUNCTION
- );
- /*
- * Disable the GPIO power-on default high-impedance mode to activate
- * previously configured port settings
- */
- PMM_unlockLPM5();
- //Initialize the ADC12B Module
- /*
- * Base address of ADC12B Module
- * Use internal ADC12B bit as sample/hold signal to start conversion
- * USE MODOSC 5MHZ Digital Oscillator as clock source
- * Use default clock divider/pre-divider of 1
- * Not use internal channel
- */
- ADC12_B_initParam initParam = {0};
- initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
- initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
- initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
- initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
- initParam.internalChannelMap = ADC12_B_NOINTCH;
- ADC12_B_init(ADC12_B_BASE, &initParam);
- //Enable the ADC12B module
- ADC12_B_enable(ADC12_B_BASE);
- /*
- * Base address of ADC12B Module
- * For memory buffers 0-7 sample/hold for 64 clock cycles
- * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
- * Disable Multiple Sampling
- */
- ADC12_B_setupSamplingTimer(ADC12_B_BASE,
- ADC12_B_CYCLEHOLD_64_CYCLES,
- ADC12_B_CYCLEHOLD_64_CYCLES,
- ADC12_B_MULTIPLESAMPLESDISABLE);
- //Configure Memory Buffer
- /*
- * Base address of the ADC12B Module
- * Configure memory buffer 0
- * Map input A1 to memory buffer 0
- * Vref+ = AVcc
- * Vref- = AVss
- * Memory buffer 0 is not the end of a sequence
- */
- ADC12_B_configureMemoryParam configureMemoryParam = {0};
- configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
- configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A12;
- configureMemoryParam.refVoltageSourceSelect =
- ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
- configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
- configureMemoryParam.windowComparatorSelect =
- ADC12_B_WINDOW_COMPARATOR_DISABLE;
- configureMemoryParam.differentialModeSelect =
- ADC12_B_DIFFERENTIAL_MODE_DISABLE;
- ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
- ADC12_B_clearInterrupt(ADC12_B_BASE,
- 0,
- ADC12_B_IFG0
- );
- //Enable memory buffer 0 interrupt
- ADC12_B_enableInterrupt(ADC12_B_BASE,
- ADC12_B_IE0,
- 0,
- 0);
- while(1)
- {
- __delay_cycles(5000);
- //Enable/Start sampling and conversion
- /*
- * Base address of ADC12B Module
- * Start the conversion into memory buffer 0
- * Use the single-channel, single-conversion mode
- */
- ADC12_B_startConversion(ADC12_B_BASE,
- ADC12_B_MEMORY_0,
- ADC12_B_SINGLECHANNEL);
- __no_operation(); // For debugger
- }
- }
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector=ADC12_VECTOR
- __interrupt
- #elif defined(__GNUC__)
- __attribute__((interrupt(ADC12_VECTOR)))
- #endif
- void ADC12_ISR(void)
- {
- switch(__even_in_range(ADC12IV,12))
- {
- case 0: break; // Vector 0: No interrupt
- case 2: break; // Vector 2: ADC12BMEMx Overflow
- case 4: break; // Vector 4: Conversion time overflow
- case 6: break; // Vector 6: ADC12BHI
- case 8: break; // Vector 8: ADC12BLO
- case 10: break; // Vector 10: ADC12BIN
- case 12: // Vector 12: ADC12BMEM0 Interrupt
- Value_AD = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
- ADC_Get_Value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
- if (ADV_Get_Aver_Value == 0) {
- ADV_Get_Aver_Value = ADC_Get_Value;
- }
- ADC_Get_Value = (ADV_Get_Aver_Value + ADC_Get_Value) / 2;
- ADV_Get_Aver_Value = ADC_Get_Value;
- if(ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0) >= 0x7ff)
- {
- //Set P1.0 LED on
- /*
- * Select Port 1
- * Set Pin 0 to output high.
- */
- GPIO_setOutputHighOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
- else
- {
- //Set P1.0 LED off
- /*
- * Select Port 1
- * Set Pin 0 to output high.
- */
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
复制代码后面我发现其实有低功耗的模式也是可以的,你也可以尝试把你的CCS关闭,重新打开再试一试,之前不可以,过了一天发现又可以了
你所选择的通道外接了电压没有?
一周热门 更多>