Translate

Saturday, April 9, 2011

Boba Fett project - lights

This article describe in more detail the firmware that controls the lights for the RangeFinder.
video

The hardware

The hardware is very simple and is based on the MSP430F2012



Basically there are 3 LEDs connected directly to the micro controller.
With the resistors set to 220 Ohm (to increase the brightness) the circuit is consuming an average of 11-12 mA.


The Firmware

Like the servo motor control, the code is based on the PWM generation, one for each LED to control and on some state machines to control the effects.
Here the main state machine that control the lights effects :




States :


  • POSIT
    This state is the default one.
    When in this state, the code acquire the pattern to display (there are three istances of the state machine) and set up the next state, that can be MOVINGUP, MOVINGDOWN, ACTIVATE or RESTING, depending the value read in the pattern and the current value of the ducty cycle
  • MOVINGUP
    This state is reached if the duty cycle need to be increased with a delay.
    From this state is possible to go to the WAITINGUP or RESTING state.
  • MOVINGDOWN
    This state is reached if the duty cycle need to be decreased with a delay.
    From this state is possible to go to the WAITINGDOWN or RESTING state.
  • WAITINGUP
    When in this state the code is waiting for the expiration of a counter decremented in the timer interrupt.
    This state can only go in the MOVINGUP state
  • WAITINGDOWN
    When in this state the code is waiting for the expiration of a counter decremented in the timer interrupt.
    This state can only go in the MOVINGDOWN state
  • ACTIVATE
    This state is reached if the duty cycle need to be adjusted without a delay.
    From this state is possible to go to the RESTING state.
  • RESTING
    When in this state the code is waiting for the expiration of a counter decremented in the timer interrupt.
    This state can only go in the POSIT state


The main flow

The main flow is divided in two places :
  • the main loop
  • the timer interrupt


    The Main Loop

    The main loop handle the lights state machine.



    The Timer interrupt

    The timer interrupt, set to .01 ms, perform some operations, like the decrement of some delay variables (used in the light control state machine) and the PWM generator.

    The pattern

    Each LED is controlled by a "pattern", i.e. a series of numbers that define some characteristic of the effect.
    Each "pattern" is composed by three values :

    1. Duty Cycle
      The first value is the duty cycle to reach.
      The range of this value is between 0 and 2000, where 0 is no PWM output, and 2000 is full PWM output.
    2. Speed
      The second value indicate the "speed" needed to reach the duty cycle.
      Each unit  of speed represent 0.01 ms and the range is between 0 (maximum speed - no delay) and 65535 (delay of 0.6 seconds)
    3. Resting
      The third value indicate for how long the reached duty cycle need to be kept, before to pass to the next pattern.
      Each unit of resting represent 0.1 ms and the range is between 0 (no resting) and 65535 (6 seconds).

    Example

    Here an example of pattern :

    #define VISOR_PATTERN   {DTQT,1,0,DT3QT,1,0, 0xFFFF}

    There are "two" patterns in this example.
    This define is copied into an array at the beginning of the code.
    • DTQT,1,0
      DTQT is a define equal to 500, i.e. a quarter of duty cycle possible.
      1 is the speed
      0 is the resting time (no resting time)
    • DT3QT,1,0
      DT3QT is a define equal to 1500, i.e. a three/quarter of duty cycle possible.
      1 is the speed
      0 is the resting time (no resting time)

    No comments:

    Post a Comment