专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
MSP430:ADC用TI的官方例程总是转换一两次之后就停了,求可能原因
2019-03-24 09:03
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
11167
19
1296
本帖最后由 火火山 于 2016-8-17 21:23 编辑
ADC用TI的官方例程总是转换一两次之后就停了,求可能原因
转换程序是放在while循环里面的,求指导
程序如图,无论打断点还是串口打印,循环不过3次
谢谢
此帖出自
小平头技术问答
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
19条回答
火火山
2019-03-25 20:41
本帖最后由 火火山 于 2016-8-19 15:59 编辑
littleshrimp 发表于 2016-8-17 23:22
是停了还是全速运行?
看你的代码里明明有休眠
时钟你是怎么配置的
不对呀,while循环中有唤醒的语句啊,会醒来才对
#include <msp430.h>
#include "driverlib.h"
void main(void)
{
// stop watchdog
WDT_A_hold(WDT_A_BASE);
PMM_unlockLPM5();
// 设置内部DCO频率为1MHz
CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
// 设置SMCLK时钟源来自DCO
CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
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_P1,
GPIO_PIN1,
GPIO_TERNARY_MODULE_FUNCTION
);
//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_16_CYCLES,
ADC12_B_CYCLEHOLD_4_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_A1;
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);
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_B_ISR will force exit
__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
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
);
}
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
break; // Clear CPUOFF bit from 0(SR)
case 14: break; // Vector 14: ADC12BMEM1
case 16: break; // Vector 16: ADC12BMEM2
case 18: break; // Vector 18: ADC12BMEM3
case 20: break; // Vector 20: ADC12BMEM4
case 22: break; // Vector 22: ADC12BMEM5
case 24: break; // Vector 24: ADC12BMEM6
case 26: break; // Vector 26: ADC12BMEM7
case 28: break; // Vector 28: ADC12BMEM8
case 30: break; // Vector 30: ADC12BMEM9
case 32: break; // Vector 32: ADC12BMEM10
case 34: break; // Vector 34: ADC12BMEM11
case 36: break; // Vector 36: ADC12BMEM12
case 38: break; // Vector 38: ADC12BMEM13
case 40: break; // Vector 40: ADC12BMEM14
case 42: break; // Vector 42: ADC12BMEM15
case 44: break; // Vector 44: ADC12BMEM16
case 46: break; // Vector 46: ADC12BMEM17
case 48: break; // Vector 48: ADC12BMEM18
case 50: break; // Vector 50: ADC12BMEM19
case 52: break; // Vector 52: ADC12BMEM20
case 54: break; // Vector 54: ADC12BMEM21
case 56: break; // Vector 56: ADC12BMEM22
case 58: break; // Vector 58: ADC12BMEM23
case 60: break; // Vector 60: ADC12BMEM24
case 62: break; // Vector 62: ADC12BMEM25
case 64: break; // Vector 64: ADC12BMEM26
case 66: break; // Vector 66: ADC12BMEM27
case 68: break; // Vector 68: ADC12BMEM28
case 70: break; // Vector 70: ADC12BMEM29
case 72: break; // Vector 72: ADC12BMEM30
case 74: break; // Vector 74: ADC12BMEM31
case 76: break; // Vector 76: ADC12BRDY
default: break;
}
}
复制代码
加载中...
查看其它19个回答
一周热门
更多
>
相关问题
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
不对呀,while循环中有唤醒的语句啊,会醒来才对
- #include <msp430.h>
- #include "driverlib.h"
- void main(void)
- {
- // stop watchdog
- WDT_A_hold(WDT_A_BASE);
- PMM_unlockLPM5();
- // 设置内部DCO频率为1MHz
- CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
- // 设置SMCLK时钟源来自DCO
- CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
- 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_P1,
- GPIO_PIN1,
- GPIO_TERNARY_MODULE_FUNCTION
- );
- //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_16_CYCLES,
- ADC12_B_CYCLEHOLD_4_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_A1;
- 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);
- __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_B_ISR will force exit
- __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
- 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
- );
- }
- __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
- break; // Clear CPUOFF bit from 0(SR)
- case 14: break; // Vector 14: ADC12BMEM1
- case 16: break; // Vector 16: ADC12BMEM2
- case 18: break; // Vector 18: ADC12BMEM3
- case 20: break; // Vector 20: ADC12BMEM4
- case 22: break; // Vector 22: ADC12BMEM5
- case 24: break; // Vector 24: ADC12BMEM6
- case 26: break; // Vector 26: ADC12BMEM7
- case 28: break; // Vector 28: ADC12BMEM8
- case 30: break; // Vector 30: ADC12BMEM9
- case 32: break; // Vector 32: ADC12BMEM10
- case 34: break; // Vector 34: ADC12BMEM11
- case 36: break; // Vector 36: ADC12BMEM12
- case 38: break; // Vector 38: ADC12BMEM13
- case 40: break; // Vector 40: ADC12BMEM14
- case 42: break; // Vector 42: ADC12BMEM15
- case 44: break; // Vector 44: ADC12BMEM16
- case 46: break; // Vector 46: ADC12BMEM17
- case 48: break; // Vector 48: ADC12BMEM18
- case 50: break; // Vector 50: ADC12BMEM19
- case 52: break; // Vector 52: ADC12BMEM20
- case 54: break; // Vector 54: ADC12BMEM21
- case 56: break; // Vector 56: ADC12BMEM22
- case 58: break; // Vector 58: ADC12BMEM23
- case 60: break; // Vector 60: ADC12BMEM24
- case 62: break; // Vector 62: ADC12BMEM25
- case 64: break; // Vector 64: ADC12BMEM26
- case 66: break; // Vector 66: ADC12BMEM27
- case 68: break; // Vector 68: ADC12BMEM28
- case 70: break; // Vector 70: ADC12BMEM29
- case 72: break; // Vector 72: ADC12BMEM30
- case 74: break; // Vector 74: ADC12BMEM31
- case 76: break; // Vector 76: ADC12BRDY
- default: break;
- }
- }
复制代码一周热门 更多>