Digital Power Starter Kit 3 Firmware  DM330017-3, Rev.3.0
dsPIC33C Buck Converter Peak Current 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 volatile uint16_t tgl_on = 0; // local indicator of LED status (on/off)
15 
16 #define TGL_INTERVAL 5000 // LED toggle interval of 5000 x 100usec = 500ms
17 #define TGL_INTERVAL_ERR 1000 // LED toggle interval of 1000 x 100usec = 100ms
18 
19 #define TGL_INTERVAL_ERRLATCH_ON 1000 // LED toggle interval of 1000 x 100usec = 100ms
20 #define TGL_INTERVAL_ERRLATCH_OFF 19000 // LED toggle interval of 19000 x 100usec = 1900ms
21 
22 volatile DEBUGGING_LED_t debug_led;
23 
24 
35 volatile uint16_t appLED_Initialize(void)
36 {
37  volatile uint16_t retval = 1;
38 
39  if(debug_led.on_time == 0)
40  debug_led.on_time = TGL_INTERVAL;
41 
42  if(debug_led.off_time == 0)
43  debug_led.off_time = TGL_INTERVAL;
44 
45  DBGLED_Init();
46 
47  return(retval);
48 }
49 
50 
61 volatile uint16_t appLED_Execute(void)
62 {
63  volatile uint16_t retval = 1;
64 
65  // Change LED toggle frequency when power supply is in fault state
66  if (buck.status.bits.fault_latch)
67  {
68  debug_led.on_time = TGL_INTERVAL_ERRLATCH_ON;
69  debug_led.off_time = TGL_INTERVAL_ERRLATCH_OFF;
70  }
71  else if (buck.status.bits.fault_active)
72  {
73  debug_led.on_time = TGL_INTERVAL_ERR;
74  debug_led.off_time = TGL_INTERVAL_ERR;
75  }
76  else
77  {
78  debug_led.on_time = TGL_INTERVAL;
79  debug_led.off_time = TGL_INTERVAL;
80  }
81 
82  // increment toggle counter
83  tgl_cnt++;
84 
85  // Toggle LED, refresh LCD and reset toggle counter
86  if ((tgl_cnt > debug_led.on_time) && (tgl_on)) { // Count n loops until LED on-time interval is exceeded
87  DBGLED_Clear();
88  tgl_cnt = 0;
89  tgl_on = 0;
90  }
91  else if ((tgl_cnt > debug_led.off_time) && (!tgl_on)) { // Count n loops until LED on-time interval is exceeded
92  DBGLED_Set();
93  tgl_cnt = 0;
94  tgl_on = 1;
95  }
96 
97  return(retval);
98 }
99 
100 
111 volatile uint16_t appLED_Dispose(void)
112 {
113  volatile uint16_t retval = 1;
114 
115  debug_led.on_time = 0;
116  debug_led.off_time = 0;
117  DBGLED_Dispose();
118 
119  return(retval);
120 }
121 
122 // end of file
#define DBGLED_Dispose()
Macro instruction initializing the specified GPIO as input.
#define DBGLED_Clear()
Macro instruction to set a pin state to logic LOW.
#define DBGLED_Init()
Macro instruction initializing the specified GPIO as output.
#define DBGLED_Set()
Macro instruction to set a pin state to logic HIGH.
volatile uint16_t appLED_Dispose(void)
Frees the resources of the debugging LED driver.
Definition: app_led.c:111
volatile uint16_t appLED_Initialize(void)
Initializes the LED driving GPIO.
Definition: app_led.c:35
volatile uint16_t appLED_Execute(void)
Executes the debugging LED driver.
Definition: app_led.c:61
volatile struct BUCK_CONVERTER_s buck
Global data object for a BUCK CONVERTER.
Debugging LED settings data object.
Definition: app_led.h:55
volatile uint16_t off_time
Definition: app_led.h:57
volatile uint16_t on_time
Definition: app_led.h:56
struct BUCK_CONVERTER_STATUS_s::@126::@128 bits
data structure for single bit addressing operations
volatile struct BUCK_CONVERTER_STATUS_s status
BUCK operation status bits.