Digital Power Starter Kit 3 Firmware  DM330017-3, Rev.3.0
dsPIC33C Buck Converter Peak Current 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  // end of group app-layer-lcd-properties-private
50 
51 
59 #define LCD_REFRESH 2000
60  // end of group app-layer-lcd-properties-private
62 
63 
72 #define LCD_NO_OF_SCREENS 3
73  // 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 PCMC ");
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  {
194  if (fltobj_BuckUVLO.Status.bits.FaultStatus)
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
#define ADC_GRANULARITY
ADC granularity in [V/tick].
#define BUCK_ISNS_FEEDBACK_GAIN
Current Gain in V/A.
#define TEMP_FB_SLOPE
#define TEMP_FB_ZERO
Conversion macros of temperature feedback parameters.
volatile struct FAULT_OBJECT_s fltobj_BuckUVLO
Under Voltage Lock Out Fault Object.
volatile struct FAULT_OBJECT_s fltobj_BuckOCP
Over Current Protection Fault Object.
volatile struct FAULT_OBJECT_s fltobj_BuckOVLO
Over Voltage Lock Out Fault Object.
volatile struct FAULT_OBJECT_s fltobj_BuckRegErr
Regulation Error Fault Object.
volatile uint16_t appLCD_Dispose(void)
Unloads the LC display data object and resources.
Definition: app_lcd.c:227
volatile uint16_t appLCD_Initialize(void)
Initializes the LC display.
Definition: app_lcd.c:88
volatile uint16_t appLCD_Execute(void)
Refreshes the LC display.
Definition: app_lcd.c:120
#define LCD_STARTUP
Startup screen delay compare value.
Definition: app_lcd.c:47
volatile uint16_t lcd_cnt
Local counter used to trigger LCD refresh event.
Definition: app_lcd.c:35
#define LCD_REFRESH
Screen refresh delay compare value.
Definition: app_lcd.c:59
#define LCD_NO_OF_SCREENS
Number of screens which can be selected.
Definition: app_lcd.c:72
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
void dev_Lcd_Initialize(void)
Initializes the LCD Device.
Definition: dev_lcd.c:126
#define PrintLcd(LINE,...)
Writes a complete line to the LC display.
Definition: dev_lcd.h:45
volatile struct BUCK_CONVERTER_s buck
Global data object for a BUCK CONVERTER.
struct FLT_OBJECT_STATUS_s::@111::@113 bits
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
Declaration of public LC display data object.
Definition: app_lcd.h:54
volatile bool enabled
Definition: app_lcd.h:55
volatile uint16_t screens
Definition: app_lcd.h:58
volatile uint16_t refresh
Definition: app_lcd.h:56
volatile uint16_t screen
Definition: app_lcd.h:57
struct BUCK_CONVERTER_STATUS_s::@126::@128 bits
data structure for single bit addressing operations
volatile uint16_t v_out
BUCK output voltage.
volatile uint16_t i_out
BUCK common output current.
volatile uint16_t temp
BUCK board temperature.
volatile uint16_t v_in
BUCK input voltage.
volatile struct BUCK_CONVERTER_STATUS_s status
BUCK operation status bits.
volatile struct BUCK_CONVERTER_DATA_s data
BUCK runtime data.