Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 63898

Forum Post: RE: Launchpad acts differently when in debug mode vs battery powered

$
0
0
So I've made adjustments to my code per the suggestions above and I am running into the same, original issue. To restate that issue, powered via battery with the motors running, the code will constantly enter the if statement for ADC10MEM, even when no object is in front of it. It will do this very fast over and over. Here is my code now: #include #define AIN1 BIT4 //Input 1 for motor A, PORT 1 #define AIN2 BIT5 //Input 2 for motor A, PORT 1 #define BIN1 BIT4 //Input 1 for motor B, PORT 2 #define BIN2 BIT5 //Input 2 for motor B, PORT 2 #define stdby BIT2 //Stand by to release motor, PORT 2 void GPIO_Setup() { /*** GPIO Set-Up ***/ P1DIR |= AIN1 | AIN2 | BIT7 | BIT2; //Inputs for direction/mode control P1SEL |= BIT2; //PWM for motor A P2DIR |= stdby | BIN1 | BIN2; //Release motor by pulling high } void Timer0A_Setup() { /*** Timer0_A Set-Up ***/ TA0CTL |= SREF_1 | REFON| TASSEL_2 | MC_1; // | ID_3; TA0CCR0 |= 1000; TA0CCTL1 |= OUTMOD_7; TA0CCR1 |= 750; } void ADC_Setup() { ADC10CTL0 = SREF_1 + REFON + ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled ADC10CTL1 = INCH_0; // input P1.0 A0 ADC10AE0 |= BIT0; // PA.0 ADC option select } void motorStartUp() { //This just makes the motor go straight from the start //Set motor conditions CCW Motor A P1OUT &= ~AIN1; //AIN1 LOW P1OUT |= AIN2; //AIN2 HIGH //Set motor conditions CCW Motor B P2OUT &= ~BIN1; //AIN1 LOW P2OUT |= BIN2; //AIN2 HIGH } void shortBrake() { P1OUT |= AIN1 | AIN2; P2OUT |= stdby; } int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT int i; ADC_Setup(); Timer0A_Setup(); GPIO_Setup(); motorStartUp(); P1DIR |= BIT7; while(1) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit //Moving Algorithm if(ADC10MEM > 400) { // shortBrake(); P1OUT |= BIT7; } else { // motorStartUp(); P1OUT &= ~BIT7; } } } // ADC10 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void) #else #error Compiler not supported! #endif { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) } I do believe this is something to do with the motors which are causing the ADC to act so sporadically. If I comment out all code related to the motors, then the adc works fine, powered via usb or battery. If I then uncomment the motor code, the adc works fine powered via usb but not battery. I have tried disconnecting the emulator power using J6 and that didn't work. Its a strange problem indeed. Again, just to reiterate, the system works like a charm when powered via USB. The robot acts exactly as expected. Does anyone have any thoughts as to why powering via battery AND turning on the motors would cause the ADC to freak out? Thanks!

Viewing all articles
Browse latest Browse all 63898

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>