embedded C programming (motors)

Discussion in 'Embedded Systems and Microcontrollers' started by braddy, Sep 19, 2008.

  1. braddy

    Thread Starter Well-Known Member

    Dec 29, 2004
    I have a question about embedded C programming. I need to program drivers for a robot . I use the microprocessor freescale mc9s12c32.
    the controller for the motor is the SN754410.
    Here is the problem:
    ( I gave the whole problem so that you have an idea. the issue is the function in bold)

    Motor I/O Driver. Write a motor driver module to drive the left and right motors. The module should provide at least the following operations (you may customize/combine/add to these as you see fit):
    - motors_Initialization() – Initialize the PWM channels appropriately for both motors on the robot. After initialization, the motors should both be stopped and braked.
    - Define four symbols: FORWARD, REVERSE, BRAKE, COAST, SAME to integer values of your choice.

    motors_Control(left, dutyLeft, right, dutyRight) – where left and right will each have value FORWARD, REVERSE, BRAKE, COAST, or SAME; and dutyLeft and dutyRight are unsigned 8-bit numbers in the range 0-100, representing the percent PWM duty cycle for that motor. If the value SAME is used for either left or right, then that motor’s direction and duty cycle should remain unchanged (with the dutyLeft or dutyRight argument ignored).

    I have some problems about organizing this function motors_Control(left, dutyLeft, right, dutyRight) .
    I cant figure out how to distinguish left and right while assigning the parameters that will make the motor wok properly.
    can some help me for the general structure of the function?

    Thank you
  2. scubasteve_911

    Senior Member

    Dec 27, 2007
    You cannot distinguish right or left with the variables? You should be testing the parameter with an if statement on the variable. Can we see what you have written thus far?