1、请问定时中断的几个向量TIMER0_A0,TIMER0_A1,TIMER1_A0,TIMER1_A1的区别?它们分别是起什么作用?对应的是哪个中断?什么时候该用哪个?我读了很多次文档,没搞懂,请老师指点一下。
2、我刚用MSP430G2553,学习一个月了,今天用ADC10做电压采样, 初始化如下:
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_1;
ADC10AE0 |= 0x02;
为什么我P1,1口什么信号都没加,显示的值却不是0?(ADCMEM不是0)但我加上所测电压后,能正常工作?
kqian0327:
1.TIMER0_A0,A1都是定时器A模块下面的两个子模块,他们共用TimeA的时钟计数器,时钟计数器根据CLK计数从0-0xffff,我们可以设置A0中CCR0作为计数器上限,TA计数到CCR0产生定时中断,计数器重新计数,而A1的CCR1一般用作PWM比较输出使用了。
2.你用的是launchpad吗?Launchpad GPIO是悬空的,所以你去读数值不为0,你可以尝试把该引脚接地后再测量,ADC采样值就为0了。如果真正作为ADC采样引脚,我们需要对该引脚下拉一个电阻接地,保证没有信号源时,ADC采样的数据为0。
Hardy Hu:
1.就是TIMER-A的IP内核,在这款MCU上有两个,寄存器名字区别TAX-TA0,TA1
2.注意GPIO的几个寄存器配置,P1SEL.x=1, P1MAP.x=31,INCHx = 0,X为模拟通道号
Hardy Hu:
这是一个P1.1ADC采样的例程,也许对你有帮助
//******************************************************************************
// MSP430G2x33/G2x53 Demo – ADC10, Sample A1, 1.5V Ref, Set P1.0 if > 0.2V
//
// Description: A single sample is made on A1 with reference to internal
// 1.5V Vref. Software sets ADC10SC to start sample and conversion – ADC10SC
// automatically cleared at EOC. ADC10 internal oscillator times sample (16x)
// and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC10
// conversion complete, ADC10_ISR will force exit from any LPMx in Mainloop on
// reti. If A1 > 0.2V, P1.0 set, else reset.
//
// MSP430G2x33/G2x53
// —————–
// /|\| XIN|-
// | | |
// –|RST XOUT|-
// | |
// >—|P1.1/A1 P1.0|–>LED
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL1 = INCH_1; // input A1
ADC10AE0 |= 0x02; // PA.1 ADC option select
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exi
if (ADC10MEM < 0x88) // ADC10MEM = A1 > 0.2V?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}