Arduino PWM, Timer2 prescaler and Varible use.

Discussion in 'Programmer's Corner' started by Redstone2, Feb 7, 2011.

  1. Redstone2

    Thread Starter Member

    Oct 21, 2010
    20
    0
    Hello All,
    I’m working on a bi-directional DC motor controller for my telescope. The motors are Pittman GM8000 series brush-commutated 24-volt and, based upon rough approximations for application, ~1.5 peak amperes.

    Controller criteria:
    · Manual motor control of telescope. No computer. Small size. Efficient use of battery.
    · Two motors, altitude and azimuth. Motor speed and direction independent of one another.
    · Widest possible duty cycle
    · 24 VDC
    · 555 or Arduino generated PWM. Looking into the Arduino at this time. Given my zero programming knowledge, I’m putting the claim that the Arduino is easy to program to the test. If it does not pan out, the 555 should be up to the task.

    I have a few questions I hope someone could help with:
    · Two L6203 will be used for each motor H-Bridge. Can the ENABLE pin be controlled with PWM? My guess (and hope) is yes, looking at the block diagram the ENABLE feeds AND (?) gates. If so, then flicking the ENABLE or IN1 / IN2 would not matter.
    · I have found a simple sketch to change Arduino’s Timer2 to 31.3 KHz. Is it possible to use a variable to adjust the duty cycle as follows:


    int inputAltitudeVariable = 0; // Alt Motor assigns value of 0
    inputAltitudeVariable = analogRead(2); // set variable to value of //analog pin 2
    int inputAzimuthVariable = 0; // Az Motor assigns value of 0
    inputAzimuthVariable = analogRead(1); // set variable to value of //analog pin 1

    int pinA = 3; // pins 3 11 are PWM output controlled by Timer2
    int pinB = 11; // connect pinA/B to H-Bridge

    void setup(){

    TCCR2B |= (0<<CS22) | (0<<CS21) | (1<<CS20); // same as TCCR2B |= B00000001; TCCR2B is now xxxxx001

    //__pinmode
    pinMode(pinA,OUTPUT);
    pinMode(pinB,OUTPUT);

    //
    analogWrite(pinA,inputAltitudeVariable); // Alt PWM output
    analogWrite(pinB,inputAzimuthVariable); //Az PWM output

    }

    void loop(){
    }


    I’m betting you are thinking it is simpler to try it than to type and post the question. Sorry to ask this question; my wife got me a new work bench as a present and the workshop is upside down. I’m not complaining but just doing thought experiments without being able to test is driving me nuts.

    If the above sketch works out, next thing is to solve bi-direction.

    Thanks to Tom Pawlofsky for making Timer2 frequency change easy. He stekch is below:

    /**
    * Version: 00 - Mai 2010
    * Author: Tom Pawlofsky www.caad.arch.ethz.ch tom-DOT-pawlofsky-AT-arch-DOT-ethz-DOT-ch
    **/


    int pinA = 3; // pin 3 and 11 are PWM output controled by Timer2
    int pinB = 11; // connect pinA/B to H-Bridge

    void setup(){

    TCCR2B |= (0<<CS22) | (0<<CS21) | (1<<CS20); // same as TCCR2B |= B00000001; TCCR2B is now xxxxx001

    //__pinmode
    pinMode(pinA,OUTPUT);
    pinMode(pinB,OUTPUT);

    //
    analogWrite(pinA,128); // 50% Duty
    analogWrite(pinB,32); //12.5 % Duty
    }

    void loop(){
    }


    Thanks for any ideas/help.

    Best Regards,
    Tom
     
Loading...