mfpek 0 Posted December 8, 2014 Share Posted December 8, 2014 @@enl i tried to put together my code and RobG's. #include "io430.h" #include "in430.h" #define Button_forward P1IN_bit.P0 #define Button_reverse P1IN_bit.P1 #define Button_Stop P1IN_bit.P2 #define IN_1 P2OUT_bit.P0 #define IN_2 P2OUT_bit.P1 #define EN_A P2OUT_bit.P2 #define EN_B P2OUT_bit.P3 #define SWITCH1_BIT P1IN_bit.P3 #define SWITCH2_BIT P1IN_bit.P4 void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL=CALDCO_1MHZ; BCSCTL1=CALBC1_1MHZ; P1DIR |= BIT3+BIT4; P1SEL |= BIT3+BIT4; CCR0 = 1000-1; CCTL1 = OUTMOD_7; CCR1 = 50; TACTL = TASSEL_2 + MC_1; P1DIR &= ~(BIT0 + BIT1 + BIT2); P2OUT = 0x00; P2DIR |= BIT0 + BIT1 + BIT2 + BIT3; EN_A = 1; EN_B = 0; for(; { if(Button_forward) { IN_1 = 1; IN_2 = 0; } else if(Button_reverse) { IN_1 = 0; IN_2 = 1; } else if(Button_Stop) { IN_1 = 0; IN_2 = 0; } } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { if (P1IFG & SWITCH1_BIT) { //faster if(CCR1 < 1000) // CCR1 < CCR0 CCR1++; P1IFG &= ~SWITCH1_BIT; } if (P1IFG & SWITCH2_BIT) { //slower if(CCR1 > 0) CCR1--; P1IFG &= ~SWITCH2_BIT; } } } is this code any good? Quote Link to post Share on other sites
enl 227 Posted December 8, 2014 Share Posted December 8, 2014 What pin are you using for the PWM output? Is the timer you are using configured to modulate that pin? Also, what OUTMOD do you want? The sample used 3 (for S-R behaviour) Do you want 7? Quote Link to post Share on other sites
mfpek 0 Posted December 8, 2014 Share Posted December 8, 2014 I checked l293d's datasheet and enable1(pin 1 on l293d) must be pwm input. So pwm out from msp430 should be p2.0. but how can i set both pwm out and enable1 out on a single pin? and yes i do want outmod_7. i forgot that some how. Quote Link to post Share on other sites
mfpek 0 Posted December 11, 2014 Share Posted December 11, 2014 @@RobG Sir, i am trying to put your code to in my code. but i couldn't able to work them together. i posted my code and my circuit schema. i am willing to use p1.3 for acceleration and p1.4 for slowing down, with pwm of course. Would you mind to take a look at the code and add this buttons.i am really appreciated for former code part but as i said i couldn't make it work. i am sincerely thankfull for your helps. Quote Link to post Share on other sites
RobG 1,892 Posted December 11, 2014 Author Share Posted December 11, 2014 @@mfpek, took a quick look at your code and I see that your pins are not configured properly. PxDIR has to be 0 for input, 1 for output. PxSEL is used for other functions, so leave it as is. Configure pull-up resistors and interrupts using PxIE, PxIFG, PxIES, PxREN, PxOUT. Also, Timer's output is not configured as it should be. Quote Link to post Share on other sites
RobG 1,892 Posted December 13, 2014 Author Share Posted December 13, 2014 Have you figured this out yet? You monitor switches 2 different ways in your code, while loop and ISR. Pick one, it will make things a lot easier. Disconnect ENB and SENSB, those belong to the second bridge. Connect ENA to P2.3 (where ENB was connected before.) Configure P2.3 as timer output TA0.1 (P2SEL.) I am using TA0.1 in my code, but on pin P1.2 BTW, which processor are you using? F2132? mfpek 1 Quote Link to post Share on other sites
mfpek 0 Posted December 13, 2014 Share Posted December 13, 2014 @@RobG i am using g2553 and trying to configure pins again at the moment. . Quote Link to post Share on other sites
mfpek 0 Posted December 13, 2014 Share Posted December 13, 2014 @@RobG i couldn't catch why my timer output is wrong. where is the mistake? it is CCTL1 = OUTMOD_7; #include "io430.h" #include "in430.h" #define Button_forward P1IN_bit.P0 #define Button_reverse P1IN_bit.P1 #define Button_Stop P1IN_bit.P2 #define IN_1 P2OUT_bit.P0 #define IN_2 P2OUT_bit.P1 #define EN_A P2OUT_bit.P2 #define EN_B P2OUT_bit.P3 #define Button_faster P1IN_bit.P3 #define Button_slower P1IN_bit.P4 void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL=CALDCO_1MHZ; BCSCTL1=CALBC1_1MHZ; CCR0 = 1000-1; CCTL1 = OUTMOD_7; CCR1 = 500; TACTL = TASSEL_2 + MC_1; P1DIR &= ~(BIT0 + BIT1 + BIT2+ BIT3 + BIT4); P2SEL |= BIT0+BIT1; P2OUT = 0x00; P2DIR |= BIT0 + BIT1 + BIT2 + BIT3; EN_A = 1; EN_B = 0; for(; { if(Button_forward) { IN_1 = 1; IN_2 = 0; } else if(Button_reverse) { IN_1 = 0; IN_2 = 1; } else if(Button_Stop) { IN_1 = 0; IN_2 = 0; } } while(CCR1<1000||CCR1>299) { if(Button_faster) { CCR1++; if(CCR1>999) { CCR1=999; } } else if(Button_slower) { CCR1--; if(CCR1<300) { CCR1=300; } } } } i configured timer's output to input pins beacause i had tried to enable pins for pwm before but it didn't work. i think it is about l293d pin configuration. Quote Link to post Share on other sites
RobG 1,892 Posted December 13, 2014 Author Share Posted December 13, 2014 I don't have F2132 or io430.h so I cannot test your code, but try the code below. All switches are connected the same way, ENA is connected to P2.3 instead of P2.2 Code removed, see later posts mfpek 1 Quote Link to post Share on other sites
mfpek 0 Posted December 13, 2014 Share Posted December 13, 2014 @@RobG i set the circuit all over again. p2.3 to l293d's enable1 p2.0 to input1 p2.1 to input2 output1 to motor (-) output2 to motor (+) But motor didn't run with this way. i checked enable1's pin voltage with a voltmeter and it's 0. so i put motor's one pin to input1 and the other one to input 2. by this way motor turns both ways and stops with button control. but pwm buttons make no changes. How and why can those be? Quote Link to post Share on other sites
RobG 1,892 Posted December 13, 2014 Author Share Posted December 13, 2014 Input pins are used to control direction. Enable pin is used to control the speed by turning both drivers (in1 & in2 ) on and off. You should see PWM signal on P2.3, to verify, connect LED (with resistor) to P2.3 and GND and you should see it dim. mfpek 1 Quote Link to post Share on other sites
mfpek 0 Posted December 13, 2014 Share Posted December 13, 2014 @@RobG i did what you said. i think p2.3 acting like a ground because when i put the led+resistor's one pin to ground it didn't even lighten up a bit. but when put it to vcc, led turned on. but no dim or brighten up of course. Quote Link to post Share on other sites
RobG 1,892 Posted December 13, 2014 Author Share Posted December 13, 2014 Which processor do you have? mfpek 1 Quote Link to post Share on other sites
mfpek 0 Posted December 13, 2014 Share Posted December 13, 2014 @@RobG msp430 g2553 Quote Link to post Share on other sites
RobG 1,892 Posted December 13, 2014 Author Share Posted December 13, 2014 Ah, that makes big difference, your schematic says F2132. Connect EN_A to P2.6 instead of P2.3 (BTW, there was a mistake in my previous post, it was ENA instead on EN_A.) Also, added little delay to the loop. Otherwise you would not be able to adjust speed, it would just go up to 100% and down to 0% with a single press. #include "msp430g2553" // I don't have io430.h, so I will use standard defines #define Button_forward BIT0 //P1IN_bit.P0 #define Button_reverse BIT1 //P1IN_bit.P1 #define Button_stop BIT2 //P1IN_bit.P2 #define Button_fast BIT3 //P1IN_bit.P3 #define Button_slow BIT4 //P1IN_bit.P4 #define IN_1 BIT0 //P2OUT_bit.P0 #define IN_2 BIT1 //P2OUT_bit.P1 #define EN_A BIT6 //P2OUT_bit.P2 void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; // we need to use P2.6 which by default are xtal pins, clear SELs P2SEL = 0; P2SEL2 = 0; //configure timer CCR0 = 99; // we use smaller number so that you don't have to press fast/slow 1000 times CCTL1 = OUTMOD_3; CCR1 = 50; TACTL = TASSEL_2 + MC_1; // configure outputs P2OUT = 0x00; P2DIR |= IN_1 + IN_2; //configure timer's output P2DIR |= EN_A; P2SEL |= EN_A; // configure inputs (all pins are inputs by default, so this is not really necessary) // I am assuming fast & slow switches are connected to P1.3 & P1.4 same way as the other 3 are, with resistors. P1DIR &= ~(Button_forward + Button_reverse + Button_stop + Button_fast + Button_slow); while (1) { _delay_cycles(200000); if (P1IN & Button_forward) { // again, no io430.h, so I will use standard way P2OUT |= IN_1; P2OUT &= ~IN_2; } else if (P1IN & Button_reverse) { P2OUT &= ~IN_1; P2OUT |= IN_2; } else if (P1IN & Button_stop) { P2OUT &= ~IN_1; P2OUT &= ~IN_2; } else if (P1IN & Button_fast) { if (CCR1 < CCR0) { CCR1++; } } else if (P1IN & Button_slow) { if (CCR1 > 0) { CCR1--; } } } } mfpek 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.