Shop OBEX P1 Docs P2 Docs Learn Events
C_Newb Asks for Help on PWM Program — Parallax Forums

C_Newb Asks for Help on PWM Program

briank77479briank77479 Posts: 36
edited 2014-04-22 10:03 in Learn with BlocklyProp
I've recently began working with C through the Simple IDE and tutorials. I thought I'd try my hand at creating a program to control two DC motors using the Activity Board connected to two L298 Motor Control boards from Solarbotics. Each board is capable of driving two motors, but for this experiment I connected one motor to one board. Each drive circuit requires 3 pins, two to determine direction and the third to except the PWM signal. I created the "Each Motor Separate" code to check that I could control the motors and I was successful. So I created the "Dual Motor" code to control them simultaneously. Unfortunately when I ran the program only one motor would work; the motor connected through pins 0-2. The direction lights on both boards would light up, But only one motor would ramp up as the code intended. Swapped cables, changed the "channel" in the code, changed the order in which pin group was listed first. It didn't matter it seemed that only the motor board connected through pins 0-2 worked. The only time I could get the motor controlled through pins 4-6 was to comment out any reference to pins 0-2.
I seek guidance on what I'm doing wrong. I feel I'm overlooking something basic.
Thank you in advance for your help.
Brian

Comments

  • SRLMSRLM Posts: 5,045
    edited 2014-04-21 15:15
    Do lines like "low (1), (5);" actually work? I'd think you would have to make it into two statements like "low(1); low(5);".
  • SRLMSRLM Posts: 5,045
    edited 2014-04-21 15:23
    I think that's your problem:
    #include <stdio.h>
    
    void square(int * n){
    	*n = (*n)*(*n);
    }
    
    int main(){
    	int a = 5;
    	int b = 6;
    	square(&a);
    	square(&b);
    	printf("a: %i, b: %i\n", a, b);
    	
    	int c = 5;
    	int d = 6;
    	square(&c), (&d);
    	printf("c: %i, d: %i\n", c, d);
    	
    	return 0;
    }
    

    results in
    a: 25, b: 36
    c: 25, d: 6
    
  • edited 2014-04-21 15:38
    I'd also recommend calling pwm_start just once at the beginning of your main routine.

    Not sure if you've already tried the example here, but in case not...

    ...Documents\SimpleIDE\Learn\Examples\Devices\Motor\DC\Two DC Motors 60 Percent.side
  • briank77479briank77479 Posts: 36
    edited 2014-04-22 10:03
    Guys,
    That was a big help!! Separating the Low statements was correct. Will try the project mentioned by Andy.
    Again, Thank you very much for this!!

    Brian
Sign In or Register to comment.