This blog focuses on the LCD for the electronic load that peteroakes, jc2048 and Jan Cumps are designing.
The post shows what's displayed on the screen and how that info is retrieved.. |
The Layout
The LCD shows the mode, status, set and measured values.
The Display
The optional display is a boosterpack, Product LinkProduct Link. The load doesn’t need the display to operate.
It was added for two reasons: it served as a debug tool at the beginning of the project when the SCPI commands weren,t implemented.
And it’s a test case to ensure that presentation layer is independent of instrument code.
Both SCPI module and display use the load’s api to control and query the app.
The boosterpack has a monochrome 96 x 96 graphic LCD with reflective back plane.
That display was used on early Nokia mobile phones and is made by SHARP.
The Firmware
The firmware uses the drivers that come with SimpleLink TI-RTOS. The eload uses standard functionality only.
The code to manage the screen is very easy. A single RTOS task initialises the LCD, then refreshes all the content once per second.
That’s it.
Initialise
This code runs at the startup of the device. It initialises the display and shows a welcome message
void *threadDisplay(void *arg0); #define THREAD_PRIORITY_DISPLAY 10 #define THREAD_SLEEP_DISPLAY 1 #define THREAD_STACK_DISPLAY 2048
priParam.sched_priority = THREAD_PRIORITY_DISPLAY; pthread_attr_setschedparam(&attrs, &priParam); retc |= pthread_attr_setstacksize(&attrs, THREAD_STACK_DISPLAY); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1); } retc = pthread_create(&thread, &attrs, threadDisplay, NULL); if (retc != 0) { /* pthread_create() failed */ while (1); }
void *threadDisplay(void *arg0) { uint32_t i; char formatString[12]; Display_init(); /* Initialize display and try to open LCD type of display. */ Display_Params params; Display_Params_init(¶ms); params.lineClearMode = DISPLAY_CLEAR_BOTH; // Display_Handle hLcd = Display_open(Display_Type_LCD | Display_Type_GRLIB, ¶ms); Display_Handle hLcd = Display_open(Display_Type_LCD, ¶ms); if (!hLcd) { return NULL; // we didn't get a display handle. Check if the following is defined: BOARD_DISPLAY_USE_LCD } Graphics_Context *context = DisplayExt_getGraphicsContext(hLcd); GrContextForegroundSet(context, ClrBlack); GrContextBackgroundSet(context, ClrWhite); GrClearDisplay(context); GrContextFontSet(context, &g_sFontCmss12); GrStringDraw(context, "The Breadboard", -1, 10, 15, 0); GrStringDraw(context, "Electronic Load", -1, 15, 30, 0); GrStringDraw(context, "Copyright Free", -1, 13, 45, 0); GrStringDraw(context, "Version 0", -1, 22, 60, 0); GrFlush(context); int8_t cMode; float fVoltage = 0.0f; float fCurrent = 0.0f;
Main Schedule
The loop is run once per second. It displays the constant mode, the current, voltage, power and resistance.
while (1) { sleep(THREAD_SLEEP_DISPLAY); cMode = eloadGetChar(); fVoltage = eloadGetVoltageDC(); fCurrent = eloadGetCurrentDC(); GrClearDisplay(context); GrContextFontSet(context, &g_sFontCmss12); sprintf(formatString, "mode: %c %02.4f\0", cMode, eloadGetSetpoint()); GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, 0, 0); i = 0; sprintf(formatString, "I: %02.4f\0", fCurrent); GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, (15 + 12*i), 0); i = 1; sprintf(formatString, "V: %02.4f\0", fVoltage); GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, (15 + 12*i), 0); i = 2; sprintf(formatString, "P: %02.4f\0", fVoltage * fCurrent); GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, (15 + 12*i), 0); i = 3; if (fCurrent> 0.0f) { sprintf(formatString, "R: %02.4f\0", fVoltage / fCurrent); } else { sprintf( formatString, "R: --.--"); } GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, (15 + 12*i), 0); i = 4; sprintf(formatString, "Input: O%s\0", eloadInputEnabled()? "n " : "ff"); GrContextFontSet(context, &g_sFontFixed6x8); GrStringDraw(context, (int8_t *)formatString, -1, 4, (15 + 12*i), 0); GrFlush(context); } }
Top Comments