Welcome to the TI Microcontroller projects page! Feel free to share your latest and greatest projects and designs based on TI microcontrollers. Or if you’re not quite ready to contribute, please browse around and rate the your favorite projects! This is a great place to get new design ideas, resources & inspiration.

miniSUMObot

PROJECT NAME: miniSUMObot

TEAM MEMBERS:

  • Miguel Bin
  • Cantu Bot 
  • Raul Hex

PROJECT DESCRIPTION

SUMObot based in MSP430 LaunchPad

PROJECT FEATURES:

  • Simple Code and Electronics
  • Recycled and Cheap Materials
  • UNDER CONSTRUCTION
  • 50% complete
Materials: 2 DC gear motors(the gearmotors were obtained from a pair of bubble guns)
a L293B driver for the gearmotors was used
the wheels are from some car toy
sensors are an couple of IR LED and photodiode (X 5)
2 down
1 right
1 left
1 ahead

http://www.youtube.com/watch?v=RmQE9Xtdxkc

First Tests!

#include  "msp430g2452.h"
 
#define M1_HIGH    P1OUT |= BIT3;
#define M1_LOW    P1OUT &= ~BIT3;
 
#define M2_HIGH    P1OUT |= BIT4;
#define M2_LOW    P1OUT &= ~BIT4;
 
#define M1B_HIGH P1OUT |= BIT6;
#define M1B_LOW     P1OUT &= ~BIT6;
 
#define M2B_HIGH P1OUT |= BIT7;
#define M2B_LOW     P1OUT &= ~BIT7;
 
#define RET 3500
 
#define     ADC_CHANNELS     3  //We will sample 3 channels
 
unsigned int samples[ADC_CHANNELS]={0,0,0};
unsigned int samples_av[ADC_CHANNELS]={0,0,0};
unsigned int t,s1,s2,s3,S1C,S2C,S3C,flag,counter;
 
void read_ADC(void);
 
void inline nop_delay( void )
{
        _NOP();    _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); _NOP();        
}
 
void Delay( unsigned short in )
{
      volatile unsigned short i;
      volatile unsigned char  k;
    for( i=in; i; --i )
    {
        for( k=10; k; --k )
            nop_delay();
    }
}
 
 
void ConfigureAdc(void)
{
  /* Configure ADC  Channel */
  ADC10CTL1 = INCH_2 + ADC10DIV_0 + CONSEQ_3 + SHS_0;   //Multi-channel repeated conversion starting from channel 2  
  ADC10CTL0 = SREF_0 + ADC10SHT_2 + MSC + ADC10ON + ADC10IE;  
  ADC10AE0 = BIT2 + BIT1 + BIT0;  
  ADC10DTC1 = ADC_CHANNELS;    //ADC_CHANNELS defined to 2    
}
 
 
void main(void)
{
   
   
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT   
   
  P1DIR |= 0xD8; // Set P1.3, P1.4, P1.6, P1.7 to output direction
  P2DIR |= 0x00;
      
  BCSCTL1 = CALBC1_1MHZ;                    // Set range
  DCOCTL = CALDCO_1MHZ;
 
   
    //P1SEL |= BIT5;                             //ADC Input pin P1.5           
    P1OUT &= ~(BIT6 + BIT7);
   
 //   P2SEL &= ~0x00;
//    P2OUT &= ~0x00;
 
/*     
    P2OUT |= BIT0;
    P2REN |= BIT0;
     
    P2IE |= BIT0;                 // P1.0 interrupt enabled
    P2IES |= BIT0;                 // P1.0 Hi/lo edge
    P2IFG &= ~BIT0;             // P1.0 IFG cleared
    
    
    P2OUT |= BIT1;
    P2REN |= BIT1;
     
    P2IE |= BIT1;                 // P1.1 interrupt enabled
    P2IES |= BIT1;                 // P1.1 Hi/lo edge
    P2IFG &= ~BIT1;             // P1.1 IFG cleared
 
*/
 
  P2OUT &= ~BIT0;
  P2OUT &= ~BIT1;
  P2REN |= BIT0;  
  P2REN |= BIT1;  
 
 
  ConfigureAdc();    
  __enable_interrupt();  
   
  flag = 1;
  counter=0;
   
  while(1)
  {  
      counter++;
                                 //Reset counter
      if(counter == 32000){
      counter=0;
      }
                                 //Calibración cada 1000 ciclos
      if(!(counter%1000)){         
      flag=1;
      }
      
      
      
                                 //Entra a calibración
      if(flag){
      read_ADC();
      S1C=s1+10;
      S2C=s2+10;
      S3C=s3+10;
      flag=0;
      continue;
      }
     
     
     
    read_ADC();                //Lee sesores delantero y laterales
     
    M1_HIGH
    M2_HIGH
        
    if (s1>S1C)
    {
           M1_LOW
           //M2_HIGH  
           Delay(3333);    
    }  
//   else{
//       M2_LOW
//   }
     
        if (s2>S2C)
    {
        M2_LOW
           //M1_HIGH
           Delay(3333);
    }    
//    else{
//       M1_LOW
//    }
     
    if (s3>S3C)
    {
           M1_LOW
           M2_LOW
           Delay(1000);
           M1_HIGH
           M2_HIGH
           Delay(1000);
           M1_LOW
           M2_LOW
           Delay(1000);
           M1_HIGH
           M2_HIGH
           Delay(1000);
           M1_LOW
           M2_LOW
           Delay(1000);
           M1_HIGH
           M2_HIGH
           Delay(1000);
           M1_LOW
           M2_LOW
    }       
     
 
      if ((BIT0 & P2IN))     // Hecharse atras
        {
        M1_LOW
           M2_LOW
        M1B_HIGH
        M2B_HIGH
        Delay(6666);
        M1B_LOW
        Delay(6666);
        }
     else
         {
        M1B_LOW
        M2B_LOW
        }
 
 
     if ((BIT1 & P2IN))     // Hecharse atras
        {
        M1_LOW
           M2_LOW
        M1B_HIGH
        M2B_HIGH
        Delay(6666);
        M2B_LOW
        Delay(6666);
        }
     else
         {
        M1B_LOW
        M2B_LOW
        }
      
      
          
    //__delay_cycles(1000);                 // Wait for ADC Ref to settle  
  }
}
 
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
}
 
/*
// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
 
    if(P2IFG & BIT0)
        {    
            M1B_HIGH
            M2B_HIGH
            
             Delay(6666);
             
             M1B_LOW
            M2B_LOW
            //P1OUT ^= 0x40; // P1.6 = toggle        
            P2IFG &= ~BIT0; // P2.0 IFG cleared
            __bic_SR_register_on_exit(CPUOFF);  
        }
    else if(P2IFG & BIT1)
        {    
            M1B_HIGH
            M2B_HIGH
            
             Delay(6666);
             
             M1B_LOW
            M2B_LOW
            //P1OUT ^= 0x40; // P1.6 = toggle        
            P2IFG &= ~BIT1; // P.1 IFG cleared
            __bic_SR_register_on_exit(CPUOFF);  
        }         
        //__bic_SR_register_on_exit(CPUOFF);        // Return to active mode           
}
*/
 
void read_ADC(void)
{
    samples_av[0]=0;
      samples_av[1]=0;
      samples_av[2]=0;
      
      flag=0;
      
      
    //P1OUT ^= 0x40;                            //toggle LED P1.6
     
    for(t=0;t<30;t++){
     
    ADC10CTL0 &= ~ENC;
     while (ADC10CTL1 & BUSY);
     ADC10SA = (unsigned int)samples;        // Aqui se llena el arreglo
                                            // Se tiene que modificar el codigo sig.
                                            // para comparar varios canales.
                                            
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled     
 
 
     samples_av[0]+=samples[0];                // samples_av[0]=samples_av[0]+samples[0];
     samples_av[1]+=samples[1];
     samples_av[2]+=samples[2];
 
    }
   
  s1=samples_av[0]/30;
  s2=samples_av[1]/30;
  s3=samples_av[2]/30;
}

USER'S GUIDE:

"Code 80% complete. 3 ADC channels"

:)

Thanks and Happy Coding! 

Comments