| Digital Power Starter Kit 3 Firmware dsPIC33C Boost 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 <xc.h> // include processor files - each processor file is guarded.
9 #include <stdint.h> // include standard integer types header file
10 #include <stdbool.h> // include standard boolean types header file
11 #include <stddef.h> // include standard definition types header file
12 #include <math.h> // include standard math library header file
13
14 #include "lcd/app_lcd.h"
15
16 // Additional header files required by this task
17 #include "config/apps.h"
18 #include "config/hal.h"
19
20 // PRIVATE VARIABLE DELARATIONS
21
22 volatile struct LCD_s lcd; // declare one LCD data object
23
24 /***********************************************************************************
25 * @ingroup app-layer-lcd-properties-private
26 * @{
27 * @var lcd_cnt
28 * @brief LCD driver time-base counter
29 * @details
30 * The LCD driver screen update is performed with a fixed frequency generated
31 * by counting task scheduler ticks. The time-base counter 'lcd_cnt' is
32 * incremented with every task scheduler call of function appLCD_Execute().
33 * If the time-base counter value matches or exceeds the constant user value
34 * defined by LCD_STARTUP, the startup screen will be switched to the first
35 * default LCD screen and regular screen updates will be performed.
36 * If the time-base counter value matches or exceeds the constant user value
37 * defined by LCD_STARTUP, the screen update will be performed.
38 *
39 **********************************************************************************/
40 volatile uint16_t lcd_cnt = 0;
41 // end of group app-layer-lcd-properties-private
43
44 /***********************************************************************************
45 * @ingroup app-layer-lcd-properties-private
46 * @{
47 * @def LCD_STARTUP
48 * @brief Startup screen delay compare value
49 * @details
50 * Period counter compare value determining how long the startup screen will be shown
51 ***********************************************************************************/
52 #define LCD_STARTUP 14
53
54 // end of group app-layer-lcd-properties-private
55
56 /***********************************************************************************
57 * @ingroup app-layer-lcd-properties-private
58 * @{
59 * @def LCD_REFRESH
60 * @brief Screen refresh delay compare value
61 * @details
62 * Period counter compare value determining the LCD refresh rate
63 ***********************************************************************************/
64 #define LCD_REFRESH 0
65
66 // end of group app-layer-lcd-properties-private
67
68 /***********************************************************************************
69 * @ingroup app-layer-lcd-properties-private
70 * @{
71 * @def LCD_NO_OF_SCREENS
72 * @brief Number of screens which can be selected
73 * @details
74 * This application supports multiple different screens which can be selected by
75 * the user to display different runtime data fields.
76 ***********************************************************************************/
77 #define LCD_NO_OF_SCREENS 4
78
79 // end of group app-layer-lcd-properties-private
80
81 /*********************************************************************************
82 * @ingroup app-layer-lcd-functions-public
83 * @fn volatile uint16_t appLCD_Initialize(void)
84 * @brief Initializes the LC display
85 * @param void
86 * @return unsigned int (0=failure, 1=success)
87 * @details
88 * This function initializes the LC display driver data object and
89 * loads the startup screen.
90 *
91 **********************************************************************************/
92
93 volatile uint16_t appLCD_Initialize(void)
94 {
95 volatile uint16_t retval = 1;
96
97 if (lcd.refresh == 0)
98 lcd.refresh = LCD_STARTUP;
99
100 lcd.screens = LCD_NO_OF_SCREENS;
101
102 dev_Lcd_Initialize();
103 PrintLcd(0, "%s", FIRMWARE_TITLE);
104 PrintLcd(1, "%s", FIRMWARE_NAME);
105
106 lcd_cnt = 0;
107 lcd.enabled = false;
108
109 return(retval);
110 }
111
112 /*********************************************************************************
113 * @ingroup app-layer-lcd-functions-public
114 * @fn volatile uint16_t appLCD_Execute(void)
115 * @brief Refreshes the LC display
116 * @param void
117 * @return unsigned int (0=failure, 1=success)
118 * @details
119 * This function is frequently called by the task scheduler automatically
120 * updating currently displayed data and/or loading the most recent screen
121 * if a screen switch has been triggered by externally.
122 *
123 **********************************************************************************/
124
125 volatile uint16_t appLCD_Execute(void)
126 {
127 volatile uint16_t retval = 1;
128 volatile float vi=0.0, vo=0.0, isns=0.0, temp=0.0;
129
130 DBGPIN1_Set();
131
132 // IF LCD output is disabled, exit here
133 if(!lcd.enabled)
134 return(retval);
135
136 // If REFRESH period has expired, update LCD contents
137 if(++lcd_cnt >= lcd.refresh) {
138
139 // Calculate output values
140 vi = ((boost.data.v_in << 3) * ADC_GRANULARITY); // Scale ADC value to physical unit
141 vi = (float)(int)(100.0 * vi); // Rounding operation required to prevent display
142 vi /= 100.0; // rounding issues around 9.99 and 10.0 � C
143
144 // Input voltage display
145 if((double)vi < 10.000)
146 PrintLcd(0, "VIN = %2.2f V", (double)vi);
147 else
148 PrintLcd(0, "VIN = %2.1f V", (double)vi);
149
150 switch (lcd.screen)
151 {
152 case 1: // Show Temperature Output
153
154 temp = ((float)(boost.data.temp - TEMP_FB_ZERO) / TEMP_FB_SLOPE); // Scale ADC value to physical unit
155 temp = (float)(int)(100.0 * temp); // Rounding operation required to prevent display
156 temp /= 100.0; // rounding issues around 9.99 and 10.0 V
157
158 if((double)temp < 10.000)
159 PrintLcd(1, "TEMP = %2.2f C", (double)temp);
160 else
161 PrintLcd(1, "TEMP = %2.1f C", (double)temp);
162 break;
163
164 case 2: // Show Current Output
165
166 isns = ((boost.data.i_out * ADC_GRANULARITY) / BOOST_ISNS_FEEDBACK_GAIN); // Scale ADC value to physical unit
167
168 if((double)isns < 1.000)
169 {
170 isns *= 1000.0;
171 PrintLcd(1, "ISNS = %3d mA", (int)isns);
172 }
173 else
174 {
175 PrintLcd(1, "ISNS = %1.2f A", (double)isns);
176 }
177 break;
178
179 case 3: // Firmware Version Number
180 PrintLcd(1, "FW: v%s", FIRMWARE_VERSION_STRING);
181 break;
182
183 default: // Output voltage display
184
185 vo = ((boost.data.v_out << 3) * ADC_GRANULARITY); // Scale ADC value to physical unit
186
187 if((double)vo < 10.000)
188 PrintLcd(1, "VOUT = %2.2f V", (double)vo);
189 else
190 PrintLcd(1, "VOUT = %2.1f V", (double)vo);
191
192 break;
193 }
194
195 // Add Error Indicators
196 if ((lcd.screen<lcd.screens) && (boost.status.bits.fault_active))
197 {
198 if (fltobj_BoostUVLO.Status.bits.FaultStatus)
199 dev_Lcd_WriteStringXY(4, 1, "(UV)");
200 else if (fltobj_BoostOVLO.Status.bits.FaultStatus)
201 dev_Lcd_WriteStringXY(4, 1, "(OV)");
202 else if (fltobj_BoostRegErr.Status.bits.FaultStatus)
203 dev_Lcd_WriteStringXY(4, 1, "(RE)");
204 else if (fltobj_BoostOCP.Status.bits.FaultStatus)
205 dev_Lcd_WriteStringXY(4, 1, "(OC)");
206 else
207 dev_Lcd_WriteStringXY(4, 1, "(LA)");
208 }
209
210 // Trigger LCD Refresh
211 lcd.refresh = LCD_REFRESH;
212 lcd_cnt = 0; // Reset internal interval counter
213 }
214
215 DBGPIN1_Clear();
216
217 return(retval);
218 }
219
220 /*********************************************************************************
221 * @ingroup app-layer-lcd-functions-public
222 * @fn volatile uint16_t appLCD_Start(void)
223 * @brief Enables the periodic refresh of the LC display content
224 * @param void
225 * @return unsigned int (0=failure, 1=success)
226 * @details
227 * This function is enables the periodic display refresh executed by function
228 * 'appLCD_Execute'. Until the LCD driver is enabled, the startup screen will
229 * set by function 'appLCD_Initialize' be shown.
230 *
231 **********************************************************************************/
232
233 volatile uint16_t appLCD_Start(void)
234 {
235 volatile uint16_t retval = 1;
236
237 lcd.enabled = true;
238 retval &= (uint16_t)(lcd.enabled);
239
240 return(retval);
241 }
242
243 /*********************************************************************************
244 * @ingroup app-layer-lcd-functions-public
245 * @fn volatile uint16_t appLCD_Dispose(void)
246 * @brief Unloads the LC display data object and resources
247 * @param void
248 * @return unsigned int (0=failure, 1=success)
249 * @details
250 * This function unloads the LC display data object and frees its resources.
251 * The LCD_s data object of this display needs to be reinitialized before
252 * the LC display can be used again.
253 *
254 **********************************************************************************/
255
256 volatile uint16_t appLCD_Dispose(void)
257 {
258 volatile uint16_t retval = 1;
259
260 /* PLACE DISPOSE CODE HERE */
261
262 return(retval);
263 }
264
265 // end of file
LCD_s::screens
volatile uint16_t screens
Definition: app_lcd.h:58
BOOST_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_boost_typedef.h:214
LCD_s
Definition: app_lcd.h:54
LCD_s::screen
volatile uint16_t screen
Definition: app_lcd.h:57
LCD_s::enabled
volatile bool enabled
Definition: app_lcd.h:55
FAULT_OBJECT_s::Status
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
Definition: drv_fault_handler.h:133
ADC_GRANULARITY
#define ADC_GRANULARITY
ADC granularity in [V/tick].
Definition: dspic33c_mcal.h:114
BOOST_CONVERTER_DATA_s::temp
volatile uint16_t temp
BOOST board temperature.
Definition: dev_boost_typedef.h:328
BOOST_CONVERTER_DATA_s::v_in
volatile uint16_t v_in
BOOST input voltage.
Definition: dev_boost_typedef.h:326
TEMP_FB_ZERO
#define TEMP_FB_ZERO
Conversion macros of temperature feedback parameters.
Definition: dpsk3_hwdescr.h:1559
LCD_s::refresh
volatile uint16_t refresh
Definition: app_lcd.h:56
BOOST_CONVERTER_DATA_s::i_out
volatile uint16_t i_out
BOOST common output current.
Definition: dev_boost_typedef.h:325
BOOST_CONVERTER_s::data
volatile struct BOOST_CONVERTER_DATA_s data
BOOST runtime data.
Definition: dev_boost_typedef.h:533
FLT_OBJECT_STATUS_s::FaultStatus
volatile bool FaultStatus
Bit 0: Flag bit indicating if FAULT has been tripped.
Definition: drv_fault_handler.h:84
TEMP_FB_SLOPE
#define TEMP_FB_SLOPE
Definition: dpsk3_hwdescr.h:1560
BOOST_CONVERTER_DATA_s::v_out
volatile uint16_t v_out
BOOST output voltage.
Definition: dev_boost_typedef.h:327
BOOST_CONVERTER_s::status
volatile struct BOOST_CONVERTER_STATUS_s status
BOOST operation status bits.
Definition: dev_boost_typedef.h:529