LED Controller – init sequence

Goals

When the controller starts it performs the init sequence. The goals of the init sequence are:

  1. Verify that all LEDs are in working order
  2. Read min/max values from NVRAM
  3. Allow the operator to set the min and max range of the PWM signal
  4. Start normal operation – read the PWM value and set the LEDs

Sequence

The following sections describe the steps of the init sequence. The steps are divided into functional areas.

LED verification

On start up all LEDs should flash for 1.0 second:

  1. Turn all LEDs on with highest intensity (LED State = LEDON)
  2. Enable Timer0
  3. Wait 1000 ms
  4. Disable Timer0
  5. Turn all LEDs off (LED State = LEDOFF)

Load PWM range from NVRAM

  1. Read the min and max values from NVRAM into global variables
  2. If min > max then move to Settings mode
  3. If min > 1023 then move to Settings mode
  4. If max > 1024 then move to Settings mode
  5. If min and max values are sensible then check if settings mode is enabled.

 Check if settings mode is enabled

To enter the settings mode the user should press the push button (SPST switch) during the LED verification stage (1 second).

 Check if the switch is pressed

  1. If the switch is pressed then enter settings mode
  2. If the switch is not pressed then move to normal operation

 Settings mode

Settigs mode allows the user to set the range (max – min) of the PWM value for the LED controller channel

To set the mode the user should move the PWM switch all the way up, wait one second and then all the way down and wait one second.Turn LED 1 on

  1. Start capturing the PWM value.
  2. Enable Timer0
  3. Set counter to 0
  4. While value n+1 is greater than value n set counter to 0
  5. If value n+1 == value n, then check the counter.
  6. If the counter value is 1 secod then:
    1. Store the PWM value as max in NVRAM
    2. Store the PWM value as max in the variable
    3. Turn LED 1 off
    4. Turn LED 2 on
  7. While value n+1 == MAX do nothing
  8. While value n+1 < value n then:
    1. Set counter to 0
  9. If value n+1 == value n then check the counter
  10. If the counter value is 1 second then:
    1. Turn LED2 off
    2. Store the PWM value as min in NVRAM
    3. Store the PWM value as min in the variable
    4. Move to normal operation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s