8455 views|2 replies

4

Posts

0

Resources
The OP
 

Help with the sine wave extreme point sampling program based on MSP430 [Copy link]

I need to make a sine wave extreme point sampling program. The following is my peak sampling program. How can I modify it? My idea is to multiply the array number of the sampled number by the sampling interval time to get the horizontal coordinate of the corresponding point. I don't know if it will work. I am a novice and don't know how to determine the sampling interval. . . #include
#define n 255
int ADC_buf[n];
unsigned char j;
unsigned char i=0;
int  g_zhong,ADC_MAX;
float  MAX_true;
float ADC_true;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC12CTL0 = ADC12SHT0_2 + ADC12ON;         // Sampling time, ADC12 on
  ADC12CTL1 = ADC12SHP;                     // Use sampling timer
  ADC12IE = 0x01;                           // Enable interrupt
  ADC12CTL0 |=ADC12ENC;
  P6SEL |= 0x01;                            // P6.0 ADC option select
  //P1DIR |= 0x1C;                            // P1.0 output
  P1DIR |= 0x01;

  while (1)
  {
    ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion
    __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit
    //__no_operation();                       // For debugger
    while(i==0)
     {

         for(j=1;jADC_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;
       P1OUT |= BIT0;
     }
     }

}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
        if(ADC12MEM0>=0)
                {//P1OUT|=0x1C;
            P1OUT |= BIT0;
            ADC_buf[i]=ADC12MEM0;
            i++;
                i%=n;}

         __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU
}


This post is from MCU

Latest reply

This depends on how you trigger AD. In the case of continuous conversion, the AD conversion time is the soft trigger interval, which is the trigger interval. This is a routine program.  Details Published on 2018-11-14 13:54
 

4005

Posts

0

Resources
2
 
This depends on how you trigger AD. In the case of continuous conversion, the AD conversion time is the soft trigger interval, which is the trigger interval. This is a routine program.
This post is from MCU
 
 

4

Posts

0

Resources
3
 
The following is my modified program. The continuous sampling of the extreme points of the sine wave can collect data, but the extreme point MAX_true cannot be obtained. #include
#define n 100
int ADC_buf[n];
unsigned char j;
unsigned char i=0;
int  ADC_MAX;
float  MAX_true;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P6SEL |= 0x01;                            // P6.0 ADC option select
  ADC12CTL0 = ADC12SHT0_8 + ADC12ON+ADC12MSC;         // Sampling time, ADC12 on
  ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;                     // Use sampling timer
  ADC12IE = 0x01;                          // Enable interrupt
  ADC12CTL0 |=ADC12ENC;
  P1DIR |= 0x01;

  while (1)
  {
    ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion
    __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit
    while(i==0)
     {

         for(j=1;j=ADC_buf[j])
           {
                   ADC_MAX=ADC_buf[j-1];
                   MAX_true=ADC_MAX*3.30/4095;
                   P1OUT |= BIT0;
                   j=1;
           }
           P1OUT &=~ BIT0;
         }

     }
     }

}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
        if(ADC12MEM0>=0)
                {

            ADC_buf[i]=ADC12MEM0;
            i++;
                i%=n;}

         __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU
}
This post is from MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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