Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
app_led.c
1 /*
2  * File: lcd.c
3  * Author: M91406
4  *
5  * Created on March 12, 2020, 12:10 PM
6  */
7 
8 
9 #include "config/apps.h"
10 #include "config/hal.h"
11 
12 // PRIVATE VARIABLE DELARATIONS
13 volatile uint16_t tgl_cnt = 0; // local counter of LED toggle loops
14 #define TGL_INTERVAL 4999 // LED toggle interval of (4999 + 1) x 100usec = 500ms
15 #define TGL_INTERVAL_ERR 999 // LED toggle interval of ( 999 + 1) x 100usec = 100ms
16 
17 volatile DEBUGGING_LED_t debug_led;
18 
19 
30 volatile uint16_t appLED_Initialize(void)
31 {
32  volatile uint16_t retval = 1;
33 
34  if(debug_led.period == 0)
35  debug_led.period = TGL_INTERVAL;
36 
37  DBGLED_Init();
38 
39  return(retval);
40 }
41 
42 
53 volatile uint16_t appLED_Execute(void)
54 {
55  volatile uint16_t retval = 1;
56 
57  // Change LED toggle frequency when power supply is in fault state
58  if (buck.status.bits.fault_active)
59  debug_led.period = TGL_INTERVAL_ERR;
60  else
61  debug_led.period = TGL_INTERVAL;
62 
63  // Toggle LED, refresh LCD and reset toggle counter
64  if (tgl_cnt++ > debug_led.period) { // Count n loops until LED toggle interval is exceeded
65  DBGLED_Toggle();
66  tgl_cnt = 0;
67  }
68 
69  return(retval);
70 }
71 
72 
83 volatile uint16_t appLED_Dispose(void)
84 {
85  volatile uint16_t retval = 1;
86 
87  debug_led.period = 0;
89 
90  return(retval);
91 }
92 
93 // end of file
appLED_Initialize
volatile uint16_t appLED_Initialize(void)
Initializes the LED driving GPIO.
Definition: app_led.c:30
BUCK_CONVERTER_s::status
volatile struct BUCK_CONVERTER_STATUS_s status
BUCK operation status bits.
Definition: dev_buck_typedef.h:502
BUCK_CONVERTER_STATUS_s::fault_active
volatile bool fault_active
Bit #5: Flag bit indicating system is in enforced shut down mode (usually due to a fault condition)
Definition: dev_buck_typedef.h:213
appLED_Dispose
volatile uint16_t appLED_Dispose(void)
Frees the resources of the debugging LED driver.
Definition: app_led.c:83
DBGLED_Init
#define DBGLED_Init()
Macro instruction initializing the specified GPIO as output.
Definition: dpsk3_hwdescr.h:224
appLED_Execute
volatile uint16_t appLED_Execute(void)
Executes the debugging LED driver.
Definition: app_led.c:53
DBGLED_Dispose
#define DBGLED_Dispose()
Macro instruction initializing the specified GPIO as input.
Definition: dpsk3_hwdescr.h:225
DEBUGGING_LED_s
Debugging LED settings data object.
Definition: app_led.h:55
DEBUGGING_LED_s::period
volatile uint16_t period
Definition: app_led.h:56
buck
volatile struct BUCK_CONVERTER_s buck
Global data object for a BUCK CONVERTER.
Definition: app_power_control.c:28
DBGLED_Toggle
#define DBGLED_Toggle()
Macro instruction to toggle most recent pin state.
Definition: dpsk3_hwdescr.h:223