Electronic Load 1.0 Programmable Constant Current Sink

Data Structures | Macros | Typedefs | Functions | Variables
led.h File Reference

Provides inline Functions for controlling the LEDs. More...

Include dependency graph for led.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
union | LED_DATA_t

## Macros
#define | LED_USE_TIMER
| Enables timer controlled blinking. More...
#define | LEDREDMASK 0b00000001
#define | LEDREDPORT PORTC

## Typedefs
typedef uint8_t | LED_FLASH_t
| Typedef for LED flashing. More...

## Functions
static void | ClearOvertempError (void)
| Clears the Overtemp Error Flag and the LED. More...
static void | ClearSOAError (void)
| Clears the SOA Error Flag and the LED. More...
static void | LEDRedOff (void)
| Switches the red LED off. More...
static void | LEDRedOn (void)
| Switches the red LED on. More...
void | LedTimerCallback (void)
| Timer Callback Function. More...
static void | SetOvertempError (void)
| Sets the Overtemp Error Flag and the LED. More...
static void | SetSOAError (void)
| Sets the SOA Error Flag and the LED. More...

## Variables
static const LED_FLASH_t | LED_BLINK_BEACON = 0b00000001
| short pulse, 200ms on, 1.4s off More...
static const LED_FLASH_t | LED_BLINK_FAST = 0b01010101
| fast blinking, period=0.4s More...
static const LED_FLASH_t | LED_BLINK_NORMAL = 0b00110011
| normal speed blinking, period=0.8s More...
static const LED_FLASH_t | LED_BLINK_OFF = 0b00000000
| always off More...
static const LED_FLASH_t | LED_BLINK_ON = 0b11111111
| always on More...
static const LED_FLASH_t | LED_BLINK_SLOW = 0b00001111
| slow blinking, period=1.6s More...
static const uint8_t | LED_TIMER_SLOWDOWN =20
| Determines how many Timer Callbacks advance to the next bit. More...
LED_DATA_t | ledData
| This is the pattern the eight leds should blink. Every '1'-bit means the LED is on. Cycled in 200ms intervals from low to high. More...
LED_FLASH_t | ledRedData
| This is the pattern the debug led should blink. More...

## Detailed Description

Provides inline Functions for controlling the LEDs.

Copyright
  Copyright (C) 2013 Robert Loos http://www.loosweb.de

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Eight LEDs are possible via a cheap shift register controlled by the SPI bus. It is really cheap, especially cheaper than choosing the next larger controller. For additional ~20 cents you could add even eight LEDs more...

They indicate normal operation states as well as error conditions. The color is defined as follows:

- RED means DANGER and is reserved for error messages or critical states of the cirquit. If you see a red LED, the circuit is experiencing problems and you should consider immediate shutdown to avoid damage if it is not already too late.
- Green generally means O.K.
- Yellow indicates something but also is an O.K. situation.
- Blue is meant to be the same as yellow but may be used to easily distinguish it from a yellow LED even if the circuit is a few meters away. Additional colors are possible of course... nowadays you can get turquoise or violet LEDs as well as different shades of green, yellow or orange...

The LEDs are set within the SPI interrupt sequence and show any changes without noticeable delay. led_state can be changed any time according to the situation and will be reflected within the next SPI interrupt cycle.

Each LED normally is controlled via 10ms timer callback and generates a repetitive blinking sequence. This can be up to 32 bits long, just as you typedef the LED_BLINK_t.
uint8_t seems enough to generate three different blink rates (plus 'off') but if you want to send debug blink codes uint16_t seems the minimum (you need a recognizable pause at the end of each code!)
This behavior can be disabled by commenting out the definition of LED_USE_TIMER. You can then switch the LED on or off via the inline functions LEDRedOn() and LEDRedOff().

## Macro Definition Documentation

## ◆ LED_USE_TIMER

#define LED_USE_TIMER

Enables timer controlled blinking.

## ◆ LEDREDPORT

#define LEDREDPORT PORTC

## ◆ LEDREDMASK

#define LEDREDMASK 0b00000001

## Typedef Documentation

## ◆ LED_FLASH_t

typedef uint8_t LED_FLASH_t

Typedef for LED flashing.

Every LED_TIMER_SLOWDOWN timer interrupt (i.e. 20x10ms=200ms), the next bit is selected to switch the LED on or off.

## Function Documentation

## ◆ LEDRedOn()

static void LEDRedOn | ( | void |  | ) |
| inlinestatic

Switches the red LED on.

Here is the caller graph for this function:

## ◆ LEDRedOff()

static void LEDRedOff | ( | void |  | ) |
| inlinestatic

Switches the red LED off.

Here is the caller graph for this function:

## ◆ SetSOAError()

static void SetSOAError | ( | void |  | ) |
| inlinestatic

Sets the SOA Error Flag and the LED.

Here is the caller graph for this function:

## ◆ ClearSOAError()

static void ClearSOAError | ( | void |  | ) |
| inlinestatic

Clears the SOA Error Flag and the LED.

Here is the caller graph for this function:

## ◆ SetOvertempError()

static void SetOvertempError | ( | void |  | ) |
| inlinestatic

Sets the Overtemp Error Flag and the LED.

Here is the caller graph for this function:

## ◆ ClearOvertempError()

static void ClearOvertempError | ( | void |  | ) |
| inlinestatic

Clears the Overtemp Error Flag and the LED.

Here is the caller graph for this function:

## ◆ LedTimerCallback()

void LedTimerCallback | ( | void |  | ) |

Timer Callback Function.

Should be called every 10ms to achieve the desired timing.

Here is the call graph for this function:

## Variable Documentation

## ◆ LED_TIMER_SLOWDOWN

const uint8_t LED_TIMER_SLOWDOWN =20
| static

Determines how many Timer Callbacks advance to the next bit.

## ◆ ledData

LED_DATA_t ledData

This is the pattern the eight leds should blink. Every '1'-bit means the LED is on. Cycled in 200ms intervals from low to high.

## ◆ ledRedData

LED_FLASH_t ledRedData

This is the pattern the debug led should blink.