請問如何用TA0來 triger ADC ,我想用Sequence-of-Channels Mode,而不是用Repeat-Sequence-of-Channels Mode ,我希望每次sample的時間間隔都一樣,而Repeat Mode感覺是sample + convert完後直接在sample + convert,不確定這樣是否我信號每一點之間是等距的,所以我用Sequence-of-Channels Mode ,
但ADC只會convert一次後就不在sample 了,必須要在程式中重複加上 ADC12ENC;他才會再次sample,
所以我想問有沒有不用ADC12SC ,且不用在ADC interrupt中加上ADC12ENC就可以用timer triger ADC做等時間距的取樣。
以下是我的程式碼,可以不用ADC12SC來開始轉換,但是下次取樣要加上ADC12ENC,跟想像中啟動TA0後隨著PWM
自動sampleing不一樣。
拜託了各位大神們
#include"msp430x54xA.h"
#include "math.h"
#include "stdlib.h"
#include "stdio.h"
#include "clock_12M.h"
#include "Delay.h"
#include "Delay2.h"
#define Num_of_Results 1000
void Time_A0_Init(void);
double M_sin=0,M_cos=0,S_sin=0,S_cos=0,N_sin=0,N_cos=0;
double MsubN=0,MsubS=0,Low_Master=0;
double total_degree=0,resolution[Num_of_Results]={0};
int i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;//關閉看門狗
clock_12M();//設定主晶振12MHZ
__no_operation();
__no_operation();
_EINT();//全局中斷致能
Time_A0_Init();
// P6SEL =BIT1 + BIT0; // 選擇A1~A0通道;
P6SEL = BIT5 +BIT4 +BIT3 +BIT2 +BIT6 + BIT0; // 選擇A6,A5,A4,A3,A2,A0通道 ;
ADC12CTL0 = ADC12ON + ADC12REFON + ADC12SHT0_2 + ADC12MSC; //
UCSCTL6 &= ~XT1OFF; //啟動晶振XT1,XT1頻率32768Hz,ADC12CLK頻率為32768Hz,
ADC12CTL1 = ADC12DIV_0 + ADC12SSEL_2 + ADC12CONSEQ_1 + ADC12CSTARTADD_0 + ADC12SHS_1;
ADC12CTL1 |= ADC12SHP ; //Pulse Sample Mode
ADC12MCTL0 = ADC12INCH_0 + ADC12SREF_0; //ADC12MCTL1的輸入通道為A0 , VR+ = AVCC and VR- = AVSS
ADC12MCTL2 = ADC12INCH_2 + ADC12SREF_0; //ADC12MCTL2的輸入通道為A2 , VR+ = AVCC and VR- = AVSS
ADC12MCTL3 = ADC12INCH_3 + ADC12SREF_0; //ADC12MCTL3的輸入通道為A3 , VR+ = AVCC and VR- = AVSS
ADC12MCTL4 = ADC12INCH_4 + ADC12SREF_0; //ADC12MCTL4的輸入通道為A4 , VR+ = AVCC and VR- = AVSS
ADC12MCTL5 = ADC12INCH_5 + ADC12SREF_0; //ADC12MCTL5的輸入通道為A5 , VR+ = AVCC and VR- = AVSS
ADC12MCTL6 = ADC12INCH_6 + ADC12SREF_0 + ADC12EOS; //ADC12MCTL1的輸入通道為A6 , VR+ = AVCC and VR- = AVSS
ADC12CTL2 &= ~BIT3; //Binary unsigned. 0000h~0FFFh
ADC12CTL2 = ADC12RES_2;//ADC12_A resolution bit4,5 00=8bit 10=12bit
ADC12CTL0 &= ~ADC12SC;
ADC12CTL0 |= ADC12ENC; //允許轉換
ADC12IE |= BIT6; //test
while(1)
{
while((ADC12IE&0x040)!=0);
__no_operation();
//==================================================
ADC12IE |= BIT6;
// ADC12CTL0 |= ADC12ENC; //允許轉換
//==================================================
__no_operation();
}
}
void Time_A0_Init(void)
{
//TA0CCTL0 |= CCIE; // TACCR0 Int16errupt enabled
TA0CCTL0 |= OUTMOD_3; // Trigger ADC conversion mode
TA0EX0 |= TAIDEX_4; //T/5
TA0CTL |= TASSEL_2 + TACLR + MC_1 ; //SMCLK,upmode, clear TAR, TA enable
TA0CCR0 = 3276;
TA0CCR1 = 5;
}
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
//-----------------------------------AD中斷事件取樣------------------------------------
//-------------------------------------------------------------------------------------
#pragma vector = ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
int A0result=0,A1result=0,A2result=0,A3result=0,A4result=0,A5result=0;
//sin,cos measure
if(ADC12IV==0x012
{
__no_operation();
A0result = ADC12MEM0 ; // Move A0 results, IFG is cleared
A1result = ADC12MEM2 ; // Move A1 results, IFG is cleared
A2result = ADC12MEM3 ; // Move A2 results, IFG is cleared
A3result = ADC12MEM4 ; // Move A3 results, IFG is cleared
A4result = ADC12MEM5 ; // Move A4 results, IFG is cleared
A5result = ADC12MEM6; // Move A5 results, IFG is cleared
ADC12CTL0 |= ADC12ENC; //允許轉換
ADC12IE = 0x00;
__no_operation();
}
}
此帖出自
小平头技术问答
这条语句中ADC12MSC=0x00,还是0x01;按照你说的应该是0;每次采样都需要一个SHI信号,不知道你文件中的定义是啥。
MSP430F149的ADC触发信号有四类 ADC12SC TA1 TB1 TB0 根据ADC转换的状态图 配置相关的内容就好 尤其注意
When any other trigger source is used, ENC must be toggled between each conversion
while(1)
{
ADC12CTL0 |= ENC;
_NOP();
ADC12CTL0 &= ~ENC;
} 保证有一个上升沿 这样子才会去等待触发信号
你说的这种情况在DSP中很好实现 DSP有单独的事件管理器 匹配事件发生就会产生SOC
恩,我ADC12MSC是設定為1沒錯,
所以我的ENC必須要在每次轉換完後再給他設定為1囉?
我目前的做法是在ADC中斷裡加上ADC12CTL0 |= ENC;
他才會轉換,只是怕它取樣不是定速才想說有沒有辦法不用去設ENC=1。
一周热门 更多>