Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
app_lcd.c
1 /*
2  * File: app_lcd.c
3  * Author: M91406
4  *
5  * Created on March 12, 2020, 12:10 PM
6  */
7 
8 #include "lcd/app_lcd.h"
9 #include <math.h>
10 
11 // Additional header files required by this task
12 #include "config/apps.h"
13 #include "config/hal.h"
14 
15 // PRIVATE VARIABLE DELARATIONS
16 
17 volatile struct LCD_s lcd; // declare one LCD data object
18 
19 
35 volatile uint16_t lcd_cnt = 0;
36  // end of group app-layer-lcd-properties-private
38 
39 
47 #define LCD_STARTUP 30000
48 
49  // end of group app-layer-lcd-properties-private
50 
51 
59 #define LCD_REFRESH 2000
60 
61  // end of group app-layer-lcd-properties-private
62 
63 
72 #define LCD_NO_OF_SCREENS 3
73 
74  // end of group app-layer-lcd-properties-private
75 
76 
88 volatile uint16_t appLCD_Initialize(void)
89 {
90  volatile uint16_t retval = 1;
91 
92  if (lcd.refresh == 0)
93  lcd.refresh = LCD_STARTUP;
94 
96 
98  dev_Lcd_WriteStringXY(0,0,"==== DPSK-3 ====");
99  dev_Lcd_WriteStringXY(0,1,"BUCK VMC EXAMPLE");
100 
101  lcd_cnt = 0;
102  lcd.enabled = true;
103 
104  return(retval);
105 }
106 
107 
120 volatile uint16_t appLCD_Execute(void)
121 {
122  volatile uint16_t retval = 1;
123  volatile float vi=0.0, vo=0.0, isns=0.0, temp=0.0;
124 
125  // IF LCD output is disabled, exit here
126  if(!lcd.enabled)
127  return(retval);
128 
129  // Refresh LCD and reset refresh counter
130  lcd_cnt++;
131 
132  // If REFRESH period has expired, update LCD contents
133  if(lcd_cnt == lcd.refresh) {
134 
135  // Calculate output values
136  vi = ((buck.data.v_in << 3) * ADC_GRANULARITY); // Scale ADC value to physical unit
137  vi = (float)(int)(100.0 * vi); // Rounding operation required to prevent display
138  vi /= 100.0; // rounding issues around 9.99 and 10.0 ° C
139 
140  // Input voltage display
141  if((double)vi < 10.000)
142  PrintLcd(0, "VIN = %2.2f V", (double)vi);
143  else
144  PrintLcd(0, "VIN = %2.1f V", (double)vi);
145 
146  switch (lcd.screen)
147  {
148  case 1: // Show Temperature Output
149 
150  temp = ((float)(buck.data.temp - TEMP_FB_ZERO) / TEMP_FB_SLOPE); // Scale ADC value to physical unit
151  temp = (float)(int)(100.0 * temp); // Rounding operation required to prevent display
152  temp /= 100.0; // rounding issues around 9.99 and 10.0 V
153 
154  if((double)temp < 10.000)
155  PrintLcd(1, "TEMP = %2.2f C", (double)temp);
156  else
157  PrintLcd(1, "TEMP = %2.1f C", (double)temp);
158  break;
159 
160  case 2: // Show Current Output
161 
162  isns = ((buck.data.i_out * ADC_GRANULARITY) / BUCK_ISNS_FEEDBACK_GAIN); // Scale ADC value to physical unit
163 
164  if((double)isns < 1.000)
165  {
166  isns *= 1000.0;
167  PrintLcd(1, "ISNS = %3d mA", (int)isns);
168  }
169  else
170  {
171  PrintLcd(1, "ISNS = %1.2f A", (double)isns);
172  }
173  break;
174 
175  case 3: // Firmware Version Number
176  PrintLcd(1, "Firmware: %s", FIRMWARE_VERSION_STRING);
177  break;
178 
179  default: // Output voltage display
180 
181  vo = ((buck.data.v_out << 1) * ADC_GRANULARITY); // Scale ADC value to physical unit
182 
183  if((double)vo < 10.000)
184  PrintLcd(1, "VOUT = %2.2f V", (double)vo);
185  else
186  PrintLcd(1, "VOUT = %2.1f V", (double)vo);
187 
188  break;
189  }
190 
191  // Add Error Indicators
192  if ((lcd.screen<lcd.screens) && (buck.status.bits.fault_active))
193  {
195  dev_Lcd_WriteStringXY(4, 1, "(UV)");
196  else if (fltobj_BuckOVLO.Status.bits.FaultStatus)
197  dev_Lcd_WriteStringXY(4, 1, "(OV)");
198  else if (fltobj_BuckRegErr.Status.bits.FaultStatus)
199  dev_Lcd_WriteStringXY(4, 1, "(RE)");
200  else if (fltobj_BuckOCP.Status.bits.FaultStatus)
201  dev_Lcd_WriteStringXY(4, 1, "(OC)");
202  else
203  dev_Lcd_WriteStringXY(4, 1, "(LA)");
204  }
205 
206  // Trigger LCD Refresh
207  lcd.refresh = LCD_REFRESH;
208  lcd_cnt = 0; // Reset internal interval counter
209  }
210 
211  return(retval);
212 }
213 
214 
227 volatile uint16_t appLCD_Dispose(void)
228 {
229  volatile uint16_t retval = 1;
230 
231  /* PLACE DISPOSE CODE HERE */
232 
233  return(retval);
234 }
235 
236 // end of file
appLCD_Initialize
volatile uint16_t appLCD_Initialize(void)
Initializes the LC display.
Definition: app_lcd.c:88
TEMP_FB_ZERO
#define TEMP_FB_ZERO
Conversion macros of temperature feedback parameters.
Definition: dpsk3_hwdescr.h:1556
BUCK_ISNS_FEEDBACK_GAIN
#define BUCK_ISNS_FEEDBACK_GAIN
Current Gain in V/A.
Definition: dpsk3_hwdescr.h:577
lcd_cnt
volatile uint16_t lcd_cnt
Local counter used to trigger LCD refresh event.
Definition: app_lcd.c:35
LCD_s::enabled
volatile bool enabled
Definition: app_lcd.h:55
fltobj_BuckRegErr
volatile struct FAULT_OBJECT_s fltobj_BuckRegErr
Regulation Error Fault Object.
Definition: app_fault_monitor.c:53
LCD_NO_OF_SCREENS
#define LCD_NO_OF_SCREENS
Number of screens which can be selected.
Definition: app_lcd.c:72
LCD_s
Declaration of public LC display data object.
Definition: app_lcd.h:54
BUCK_CONVERTER_DATA_s::v_in
volatile uint16_t v_in
BUCK input voltage.
Definition: dev_buck_typedef.h:300
fltobj_BuckUVLO
volatile struct FAULT_OBJECT_s fltobj_BuckUVLO
Under Voltage Lock Out Fault Object.
Definition: app_fault_monitor.c:50
BUCK_CONVERTER_s::status
volatile struct BUCK_CONVERTER_STATUS_s status
BUCK operation status bits.
Definition: dev_buck_typedef.h:502
PrintLcd
#define PrintLcd(LINE,...)
Writes a complete line to the LC display.
Definition: dev_lcd.h:45
FAULT_OBJECT_s::Status
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
Definition: drv_fault_handler.h:133
dev_Lcd_Initialize
void dev_Lcd_Initialize(void)
Initializes the LCD Device.
Definition: dev_lcd.c:126
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
dev_Lcd_WriteStringXY
void dev_Lcd_WriteStringXY(volatile uint8_t column_index, volatile uint8_t line_index, const char *str)
Sets the cursor position to the given x- and y-coordinates and writes the given string on the lcd scr...
Definition: dev_lcd.c:305
LCD_s::refresh
volatile uint16_t refresh
Definition: app_lcd.h:56
appLCD_Dispose
volatile uint16_t appLCD_Dispose(void)
Unloads the LC display data object and resources.
Definition: app_lcd.c:227
BUCK_CONVERTER_s::data
volatile struct BUCK_CONVERTER_DATA_s data
BUCK runtime data.
Definition: dev_buck_typedef.h:506
LCD_s::screen
volatile uint16_t screen
Definition: app_lcd.h:57
appLCD_Execute
volatile uint16_t appLCD_Execute(void)
Refreshes the LC display.
Definition: app_lcd.c:120
BUCK_CONVERTER_DATA_s::i_out
volatile uint16_t i_out
BUCK common output current.
Definition: dev_buck_typedef.h:299
LCD_REFRESH
#define LCD_REFRESH
Screen refresh delay compare value.
Definition: app_lcd.c:59
fltobj_BuckOVLO
volatile struct FAULT_OBJECT_s fltobj_BuckOVLO
Over Voltage Lock Out Fault Object.
Definition: app_fault_monitor.c:51
LCD_s::screens
volatile uint16_t screens
Definition: app_lcd.h:58
FLT_OBJECT_STATUS_s::FaultStatus
volatile bool FaultStatus
Bit 0: Flag bit indicating if FAULT has been tripped.
Definition: drv_fault_handler.h:84
BUCK_CONVERTER_DATA_s::temp
volatile uint16_t temp
BUCK board temperature.
Definition: dev_buck_typedef.h:302
fltobj_BuckOCP
volatile struct FAULT_OBJECT_s fltobj_BuckOCP
Over Current Protection Fault Object.
Definition: app_fault_monitor.c:52
ADC_GRANULARITY
#define ADC_GRANULARITY
ADC granularity in [V/tick].
Definition: dpsk3_hwdescr.h:126
TEMP_FB_SLOPE
#define TEMP_FB_SLOPE
Definition: dpsk3_hwdescr.h:1557
buck
volatile struct BUCK_CONVERTER_s buck
Global data object for a BUCK CONVERTER.
Definition: app_power_control.c:28
LCD_STARTUP
#define LCD_STARTUP
Startup screen delay compare value.
Definition: app_lcd.c:47
BUCK_CONVERTER_DATA_s::v_out
volatile uint16_t v_out
BUCK output voltage.
Definition: dev_buck_typedef.h:301