8069 views|3 replies

4

Posts

0

Resources
The OP
 

Extreme point test [Copy link]

Below is my program. The test program can enter interruption, but no data can be collected. Can you help me find the problem?
#include
#define n 36
int ADC_buf[n];
unsigned char j;
unsigned char i=0;
int  g_zhong,ADC_MAX;
float  MAX_true;
void init_TimerA(void)
{
  TA0CTL|=TASSEL_2+TACLR;//选择时钟为SMCLK,清除TAR
  TA0CCTL0|=CCIE;;//CCR0使能中断
  //TA0CCR0=40000;//频率为200Hz 8M/40000=200
  TA0CCR0=20000;//频率为40kHz 8M/200=40k
  TA0CTL|=MC0;//增计数模式
}
void init_ADC(void)
{
  ADC12CTL0&=~ADC12ENC;//允许转换位是零,不允许转换
  ADC12CTL1|=ADC12CSTARTADD_0;//多次转换的地址是ADC12MEM0
  ADC12MCTL0|=ADC12INCH_0;//模拟输入通道为A0
  ADC12CTL0|=ADC12SHT0_8 + ADC12ON;//ADC12ON:ADC12模块转换控制位,为一时打开该模块允许转换,
  ADC12CTL1|=ADC12CONSEQ_2;//单通道多次转换模式
  ADC12CTL1|=ADC12SSEL_2;//ADC12时钟源选择SMCLK
  ADC12CTL1|=ADC12DIV_0;//分频因子是1
  ADC12CTL1|=ADC12SHP;//Sampling signal source comes from timer
ADC12CTL1|=ADC12SHS_1;//Clock source selectionTA
ADC12CTL0|=ADC12ENC;//ENC: Conversion enable bit is temporarily allowed to be converted,
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT[/fontsize][/fontsize] ]
init_TimerA(); //Clock initialization
init_ADC();
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x01;
P1OUT &=~BIT0;[/ align]
P6DIR |= BIT1;
P6OUT |= BIT1;
_EINT();
while (1)
{ ADC_buf=ADC12MEM0;//读取转换结果
       i++;
       i=i%n;
     if(i==0)
     {
      for(j=1;j" color][="" color][color="#7F0055]if(ADC_buf[j-1]" font][="" size][="" {[="">ADC_buf[j])
    {
      g_zhong=ADC_buf[j-1];
      ADC_buf[j-1]=ADC_buf[j];
      ADC_buf[j]=g_zhong;
      }
        ADC_MAX=ADC_buf[n-1];
         }
       MAX_true=ADC_MAX*3.30/4095;
     }
  }
}
#pragmavector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
     P6OUT^= BIT1;
     ADC12CTL0|= ADC12ENC+ADC12SC;
     _bic_SR_register(LPM0_bits);
}

This post is from MCU

Latest reply

Because you didn't get the conversion result in your interrupt.  Details Published on 2019-1-17 14:30
 

7422

Posts

2

Resources
2
 
ADC_MAX = 0 ?
This post is from MCU
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

4005

Posts

0

Resources
3
 
Because you didn't get the conversion result in your interrupt.
This post is from MCU
 
 
 

4

Posts

0

Resources
4
 
Can't read the result in the interrupt
This post is from MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list