Author Topic: MSP430(ADC, timer and UART)  (Read 4847 times)

0 Members and 2 Guests are viewing this topic.

Offline Lidiya ThomasTopic starter

  • Newbie
  • Posts: 2
  • Country: in
MSP430(ADC, timer and UART)
« on: May 27, 2016, 04:51:39 am »
Hi all,
I am a beginner in MSP coding. I am trying to integrate adc, timer and UART. I need 10 ADC values after running the code. But it is showing only one value. Can someone help me in solving this.



#include <msp430g2553.h>
#define     TXD                   BIT2      // TXD on P1.2
#define     RXD                   BIT1      // RXD on P1.1
#define LED_0 BIT0
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
#define TIMER_COUNT 12000

unsigned int value[10],n=0,i;
unsigned int adc;
void serial_init(void);

void main(void)
{

   WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

   // config clock
    BCSCTL1 = CALBC1_1MHZ;                    // Set range
    DCOCTL = CALDCO_1MHZ;      // SMCLK = DCO = 1MHz

    // config timer

    TACCTL0 |= CCIE;
    TACTL |= TASSEL_2 + MC_2; // Set the timer A to SMCLCK, Continuous

    //config adc

    ADC10CTL0 &= ~ENC;            // Disable conversion
    ADC10CTL1 = INCH_5 + ADC10SSEL_3 + ADC10DIV_3 + CONSEQ_2;   // p1.5 analog signal, Clock = ADC10CLK/4
    ADC10CTL0 = SREF_1 + ADC10SHT_0 + REFON + ADC10ON + ADC10IE;
    ADC10AE0 |= BIT5;

    //Configure Hardware UART */
           P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
          P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
           UCA0CTL1|=UCSWRST;
           UCA0CTL0=0x00;
           UCA0CTL1 |= UCSSEL_2; // SMCLK
           UCA0BR0 = 104; // Set Baud rate (1MHz CPU clock)/(9600 baud) (lower byte)
            UCA0BR1 = 0; // Set Baud rate to (1MHz CPU clock)/(9600 baud) (upper byte)
           UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
           IE2 |= UCA0TXIE;
           UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**



    while(n<10)
   {
    __enable_interrupt();
    __bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled
 n++;
    }
void serial_charTx(int adc)
   {

                //adc=ADC10MEM;
                value[n-1]=adc;
                while (!(IFG2&UCA0TXIFG)); // Wait until TX buffer ready?
                UCA0TXBUF = adc >> 8; // Send MSB first
                while (!(IFG2&UCA0TXIFG)); // Wait until TX buffer ready?
                UCA0TXBUF = (adc & 0x00FF); // Send LSB

    }
//}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
  {

   P1OUT ^= 0x01;
   ADC10CTL0 |= ENC + ADC10SC;

   __bic_SR_register_on_exit(CPUOFF);        // Return to active mode

  }
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
  {
      adc = ADC10MEM;
      serial_charTx(value);
      //value[n-1]=adc;
      P1OUT ^= BIT6;
      TACCR0 += TIMER_COUNT;
      ADC10CTL0&=~ADC10IFG;

        //Set timer count
    __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
   // ADC10CTL0&=~ADC10IFG;
  }
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: MSP430(ADC, timer and UART)
« Reply #1 on: May 27, 2016, 09:32:46 am »
Welcome to the forum!

There are a couple of issues with the code, but perhaps some are there because you didn't copy all of it. As is, it shouldn't compile.

One of the most glaring issue is maybe this:


Code: [Select]
unsigned int value[10]; ...

...
void serial_charTx(int adc) {...}

...
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
  adc = ADC10MEM;
  serial_charTx(value);
  ...
}

Instead of passing the recorded ADC value to the serial_charTx function, you're passing the name of the array. Without the [ ] an array name is the memory address of its first element, so what you're printing is the memory location of value[0], not its value. That memory address doesn't change, of course. Is that what you mean by "But it is showing only one value."?

You probably also don't want to end main with the while loop you have. What happens after n is no longer less than 10?


(BTW, please try to use the "code" tags: http://wiki.simplemachines.org/smf/Code )
my random ramblings mind-dump.net
 
The following users thanked this post: Lidiya Thomas

Offline Lidiya ThomasTopic starter

  • Newbie
  • Posts: 2
  • Country: in
Re: MSP430(ADC, timer and UART)
« Reply #2 on: May 28, 2016, 03:50:58 am »



Thanks for the reply..but my issue is different, rather than getting 10 values, only one value is getting printed..that might be the value[0]. For n=0, everything is running smooth. But for n=1,it is not at al entering to the second pragma(i.e, adc pragma)
 

Offline casinada

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: us
Re: MSP430(ADC, timer and UART)
« Reply #3 on: May 28, 2016, 06:21:15 am »
I know that you're a beginner but there is a dedicated section of the forum for Micro-controllers.
There is a dedicated site for MSP430: 43oh.com
There are dedicated forums for TI support:
https://e2e.ti.com/support/microcontrollers/msp430/f/166
I hope this helps to post the question on a more appropriate place  :)
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: MSP430(ADC, timer and UART)
« Reply #4 on: May 28, 2016, 10:40:18 am »
Like I said in my previous post, there are multiple issues, and the code you posted shouldn't even compile. Judging by the various commented lines in the code, you probably have tried all kinds of things already, so perhaps the code you posted wasn't the version that compiled and ran. If you post the full code that actually compiled and if possible any compiler warnings, I'm happy to have another look.  Please use the "code" feature (button with the  #  in it) this time, though!

However, having looked at the "intent" of your code more closely now (and after chasing a few dead ends), there is nothing obvious (to me) why you only get 1 value printed. There are a few non-ideal ways of coding this, with potential timing issues, but some values should still be transmitted. Are you getting a full 2-byte (16-bit) value, or only a single byte? If you pause the execution in debug mode after "only one value is getting printed", which line of the code does it stop? Does the timer continue to trigger its interrupt (i.e. does P1.0 continue to toggle)?
my random ramblings mind-dump.net
 

Offline mayor

  • Frequent Contributor
  • **
  • Posts: 250
  • Country: ca
Re: MSP430(ADC, timer and UART)
« Reply #5 on: May 29, 2016, 12:20:01 pm »
Without digging any deeper in your code, it appears you are not specifying the number you want. You need to set ADC10DTC1 = 10. That's a starting point.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->