这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » ZOGLAB 一个实用的 A/D 例子 ZOGLAB

共2条 1/1 1 跳转至

ZOGLAB 一个实用的 A/D 例子 ZOGLAB

院士
2006-09-17 18:14:16     打赏
ZOGLAB 一个实用的 A/D 例子 ZOGLAB



关键词: ZOGLAB     一个     用的     例子    

院士
2006-12-22 22:43:00     打赏
2楼
问 void timer_init(void){ //定时器初始化
TACTL = TACLR+TASSEL_1+ID1+ID0; // start TIMER_A continous mode, ACLK as input clock
CCR0 = timerA0_offset; // DIV by 8 to give 16 seconds maximum duration
CCTL0 = CCIE;
CCR1 = timerA1_offset;
//CCTL1 = CCIE;
//TIMER_B sample timing setting
TBCCR0=SAMPLE_PERIOD; //CCR0 determines the sample period = 9
TBCCR1=RESULT_READY_TIME; //give enough time for the ADC12 to work and then start = 7
//processing
TBCCTL0=CCIE; //enables interrupt at CCR0 equ
TBCCTL1=OUTMOD_3; //EQU1 sets OUT1, EQU0 resets OUT1
TBCTL=TBCLR+MC_1+TBSSEL_1; //0x0214;
// start TIMER_B up mode, ACLK as input clock */
}
/*
***************************************************************************************
* ADC12采样型号为TIMEB OUT1,3276.8HZ,转换时钟为4MHz,
***************************************************************************************
*/
void adc12_init(void){
P6SEL = 0xFF;
ADC12CTL0 &=~ ENC; // Disable conversion before changing
ADC12CTL0 = ADC12ON+REFON+MSC+REF2_5V; //
ADC12CTL1 = SHS_3+CONSEQ_3+ADC12SSEL_2+ADC12DIV_1; //
ADC12MCTL0 = VREF+INCH_0;
ADC12MCTL1 = VREF+INCH_1;
ADC12MCTL2 = VREF+INCH_2;
ADC12MCTL3 = VREF+INCH_3;
ADC12MCTL4 = VREF+INCH_4;
ADC12MCTL5 = VREF+INCH_5;
ADC12MCTL6 = VREF+INCH_6;
ADC12MCTL7 = VREF+INCH_7;
ADC12MCTL8 = VREF+INCH_8;
ADC12MCTL9 = VREF+INCH_9;
ADC12MCTL10 = VREF+INCH_10;
ADC12MCTL11 = VREF+INCH_11+EOS;
ADC12IE = 0x0800; // Enable ADC12IFG.11
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC;
}

unsigned int adc12_results[adc_channel][Num_of_Results];
interrupt[ADC_VECTOR] void ADC12ISR (void)
{
adc12_results[0][index] = ADC12MEM0;
adc12_results[1][index] = ADC12MEM1;
adc12_results[2][index] = ADC12MEM2;
adc12_results[3][index] = ADC12MEM3;
adc12_results[4][index] = ADC12MEM4;
adc12_results[5][index] = ADC12MEM5;
adc12_results[6][index] = ADC12MEM6;
adc12_results[7][index] = ADC12MEM7;
adc12_results[8][index] = ADC12MEM8;
adc12_results[9][index] = ADC12MEM9;
adc12_results[10][index] = ADC12MEM10;
adc12_results[11][index] = ADC12MEM11;
index = (index+1)&(Num_of_Results-1); // Increment results index,
adc_isr_signal = 1;
}
//计算AD结果,去极值,然后加权平均
void cap_adc_results(void)
{
INT16U i = 0;
clear_WDG;

for(i = 0;i<12;i++){
clear_WDG;
copy_int(adc12_results,buf,8);
shell(buf,8);
//adc_results = (buf[2] + buf[3] + buf[4] + buf[5])>>2;
if(ABS(adc_results - buf[2]) > 30) adc_results = buf[2];
adc_results = (double)((double)GAIN*adc_results + buf[2] + buf[3] + buf[4] + buf[5])/(double)(GAIN + 4);
adc_results = adc_results*(double)ADC_VREF/(double)4096;
clear_WDG;
}
}

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]