Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

MSP430G2553 ADC/DC motors

$
0
0

Hello chaps,

 

I ended up struggling doing something that seems not so hard after all. The idea is to drive DC motors based on what Sharp IR 'sees' yes this is supposed to be a robot. 

 

I have the sensors plugged into P1.0 and P1.1. Using ADC10 the MSP430 allows max value 1023 and min 0 and I was thinking at let say around 350-400 to stop the motors wait a bit and then either turn or go back but what I struggle is reading the ADC.

 

Here is my code

 

#include <msp430g2553.h>
unsigned int adc[2] = {0};
unsigned int sens1 = 0;
unsigned int sens2 = 0;
 
 
void main()
{
 
BCSCTL1 = CALBC1_8MHZ;   // Set range
DCOCTL  = CALDCO_8MHZ;   // Set DCO step + modulation
WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_1 + ADC10DIV_0 + CONSEQ_3; //
ADC10DTC1 = 0x2;                         // 2 conversions
ADC10AE0 |= BIT1 + BIT0;             //A.1 and PA.0 ADC option select
P1DIR |= BIT1 + BIT0; // make it output
__enable_interrupt();
 for(;;)
 {
   ADC10CTL0 &= ~ENC;
   while (ADC10CTL1 & BUSY);               // Wait if ADC10 core is active
   ADC10SA = (unsigned int)adc;            // Copies data in ADC10SA to unsigned int adc array
   ADC10CTL0 |= ENC + ADC10SC;         // Sampling and conversion start
   sens1 = adc[0]; //
   sens2 = adc[1]; //
   __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
 
 P2DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5;
 P2OUT &= ~BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5;
 
 if  (sens1 && sens2 < 330)
  {
   P2OUT |= BIT0;
  P2OUT |= BIT5;
/// forward ///
  P2OUT &= ~BIT1;
  P2OUT |= BIT2;
 
  P2OUT |= BIT3;
  P2OUT &= ~BIT4;
  }
  else if (sens1 && sens2 < 310)
 
  {
///stop///
  P2OUT &= ~BIT0;
  P2OUT &= ~BIT5;
  }
 }
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}
 
Now behold what my debugger says (check the attachment). So seems that my conversion is happening very good but ONLY on my A0 or at least putting object in front of sens 2 changes the value significantly.
 
ANY assistance will be appreciated.
 
 
 
 

Attached Thumbnails

  • Capture.PNG

Viewing all articles
Browse latest Browse all 2077

Trending Articles