Tuesday, May 22nd 2018, 11:45pm UTC+2

You are not logged in.

  • Login
  • Register

jhgorse

Beginner

Date of registration: Jul 9th 2014

Posts: 17

1

Friday, May 4th 2018, 7:54pm

GRAPH widget performance optimization

Greetings,

I am looking for ways to optimize the performance of the GRAPH_DATA_XY widget for the refresh of the screen for new data on embedded hardware. The vertical refresh is progressively slower the more data is displayed (# of chart graphs, primarily).

I have an STM32F429ZI running with external 32 MB SPANSION SDRAM on an 800x480 LCD. WM_SetCreateFlags(WM_CF_MEMDEV) is set before GUI_Init(). I believe I have triple buffering on now which helped with screen flicker between emWin screens previously.

Example code:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
 *
 *   	Defines
 *
 **********************************************************************
 */
#define OutputDebugString(x) printf(x)
#define ID_WINDOW_0  (GUI_ID_USER + 0x00)
#define ID_GRAPH_0   (GUI_ID_USER + 0x01)
#define ID_BUTTON_0  (GUI_ID_USER + 0x02)
#define ID_BUTTON_1  (GUI_ID_USER + 0x03)

#define Y_SCALE_MAX     113.0   // So that 100 is the highest Y scale bar number displayed
#define Y_SCALE_MIN     0
#define VSCROLL_OFFY    10
#define GY              (340)
#define GRAPH_PIXELS_Y  GY     // Delta-Y of our chart area
#define Y_SCALE_FACTOR ((float)(Y_SCALE_MAX-(Y_SCALE_MIN))/GRAPH_PIXELS_Y)

#define GX              (740)
#define GRAPH_PIXELS_X  GX      // Widget pixels
#define GXp             (GX - 5)  // Usable graph pixels
#define GXLO            15      // X left offset pixels
#define GXRO            15      // X rigt offset pixels

#define ID_BUTTON_0     (GUI_ID_USER + 0x03)
#define ID_BUTTON_1     (GUI_ID_USER + 0x04)
#define ID_BUTTON_2     (GUI_ID_USER + 0x05)
#define ID_TEXT_0       (GUI_ID_USER + 0x23)
#define ID_GRAPH_0      (GUI_ID_USER + 0x24)
#define ID_BUTTON_3     (GUI_ID_USER + 0x25)
#define ID_BUTTON_4     (GUI_ID_USER + 0x27)

#define PREPOPULATED_DATA_POINTS (MAXSTRIPINDEX/5)
#define MAX_GRAPHS	10

/*********************************************************************
 *
 *   	Static data
 *
 **********************************************************************
 */
static GRAPH_DATA_Handle _ahData[MAX_GRAPHS];	// Array of handles for the GRAPH_DATA objects
static GRAPH_SCALE_Handle _hScaleV;				// Handle of vertical scale
static GRAPH_SCALE_Handle _hScaleH;				// Handle of horizontal scale
static GUI_POINT _aPoint[MAX_GRAPHS];

static I16 _aValue[MAX_GRAPHS];
static int _Stop = 0;

// Array of colors for the GRAPH_DATA objects
static GUI_COLOR _aColor[] = {
    GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_ORANGE,
    GUI_GREEN, GUI_GREEN, GUI_RED, GUI_RED,
    GUI_LIGHTBLUE, GUI_LIGHTBLUE };

static U8 _aLineStyles[] = {
    GUI_LS_SOLID, GUI_LS_SOLID, GUI_LS_SOLID, GUI_LS_DASH,
    GUI_LS_SOLID, GUI_LS_DASH, GUI_LS_SOLID, GUI_LS_DASH,
    GUI_LS_SOLID, GUI_LS_DASH };

/*********************************************************************
 *
 *   	_aDialogCreate
 */
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { {
  WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 780, 440, 0, 0x0, 0 }, {
	GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 20, 80, GX, GY, 0, 0x0, 0 }, {
	BUTTON_CreateIndirect, "Right", ID_BUTTON_0, 760, 80, 20, GY, 0, 0x0, 0 }, {
	BUTTON_CreateIndirect, "Left", ID_BUTTON_1, 0, 80, 20, GY, 0, 0x0, 0 }, };

/*********************************************************************
 *
 *   	Static code
 *
 **********************************************************************
 */

/*********************************************************************
 *
 *       _AddValues
 *
 * Function description
 *   This routine calculates new random values in dependence of the previous added values
 *   and adds them to the GRAPH_DATA objects
 */
static void _AddValues(void) {
  static unsigned data_time = 0;
  unsigned i = 0;
  GUI_POINT pt;

  pt.x = data_time;

  for (int i = 0; i < MAX_GRAPHS; i++) {
    pt.y = i * 20 + rand() % 50 / Y_SCALE_FACTOR;
    GRAPH_DATA_XY_AddPoint(_ahData[i], &pt);
  }
  data_time++;
}

/*********************************************************************
 *
 *   	_cbDialog
 */
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  WM_HWIN hDlg;
  static GRAPH_DATA_Handle hGraphData;
  int NCode;
  int Id;
  static int DataAttached;
  unsigned i;

  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Window'
    //
    hItem = pMsg->hWin;
    WINDOW_SetBkColor(hItem, GUI_GRAY);
    //
    // Initialize the GRAPH widget
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);

    for (i = 0; i < MAX_GRAPHS; i++) {
      _ahData[i] = GRAPH_DATA_XY_Create(_aColor[i], 2000, 0, 0);
      GRAPH_AttachData(hItem, _ahData[i]);
      GRAPH_DATA_XY_SetLineStyle(_ahData[i], _aLineStyles[i]);
      GRAPH_DATA_XY_SetOffY(_ahData[i], 10 / Y_SCALE_FACTOR);
    }

    GRAPH_SetVSizeY(hItem, 120);
    GRAPH_SetGridVis(hItem, 1);
    WIDGET_SetEffect(hItem, &WIDGET_Effect_3D);
    //
    // Create and add vertical scale
    //
    _hScaleV = GRAPH_SCALE_Create(5, GUI_TA_LEFT | GUI_TA_BOTTOM,
        GRAPH_SCALE_CF_VERTICAL, 10 / Y_SCALE_FACTOR);
    GRAPH_SCALE_SetTextColor(_hScaleV, GUI_YELLOW);
    GRAPH_AttachScale(hItem, _hScaleV);
    GRAPH_SetGridDistY(hItem, 10 / Y_SCALE_FACTOR);
    GRAPH_SCALE_SetFactor(_hScaleV, Y_SCALE_FACTOR);
    GRAPH_SCALE_SetOff(_hScaleV,
        -(Y_SCALE_MIN / Y_SCALE_FACTOR) + VSCROLL_OFFY + 5);

    //
    // Create and add horizontal scale
    //
    _hScaleH = GRAPH_SCALE_Create(320, GUI_TA_RIGHT, GRAPH_SCALE_CF_HORIZONTAL,
        60);
    GRAPH_SCALE_SetTextColor(_hScaleH, GUI_DARKGREEN);
    GRAPH_AttachScale(hItem, _hScaleH);
    GRAPH_SetGridDistX(hItem, 60);
    GRAPH_SCALE_SetTickDist(_hScaleH, 60);

    break;
  case WM_NOTIFY_PARENT:
    Id = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (Id) {
    case ID_BUTTON_0: // Notifications sent by 'Right'
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      }
      break;
      case ID_BUTTON_1: // Notifications sent by 'Left'
        switch (NCode) {
        case WM_NOTIFICATION_CLICKED:
          break;
        case WM_NOTIFICATION_RELEASED:
          break;
        }
        break;
    }
    break;
    default:
      WM_DefaultProc(pMsg);
      break;
  }
}

/*********************************************************************
 *
 *   	Public code
 *
 **********************************************************************
 */
/*********************************************************************
 *
 *   	CreateWindow
 */
void MainTask(void) {
  WM_HWIN hGraph;
  WM_HWIN hDlg;

  hGraph = 0;
  WM_SetCreateFlags(WM_CF_MEMDEV);
  GUI_Init();
  hDlg = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
      _cbDialog, WM_HBKWIN, 0, 0);
  GUI_Delay(50);
  for (int i = 0; i < 20; i++) // PREPOPULATED_DATA_POINTS
    _AddValues();

  while (1) {
    GUI_Delay(500);
    if (!_Stop) {
      if (!hGraph) {
        hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
      }
      _AddValues();
    }
  }
}

/*************************** End of file ****************************/

jhgorse

Beginner

Date of registration: Jul 9th 2014

Posts: 17

2

Friday, May 4th 2018, 11:05pm

Resolved by moving the emWin RAM to SDRAM and increasing it from 100 kB to 1,000 kB.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584

3

Monday, May 7th 2018, 2:08pm

Hi,

Good that it is working.

You should get rid of the following line:

C/C++ Source code

1
WM_SetCreateFlags(WM_CF_MEMDEV);


and exchange it with:

C/C++ Source code

1
WM_MULTIBUF_Enable(1);


I guess you are using it to avoid flickering, but automatic memory devices should be used as a last option against flickering.

It leads to unnecessary drawing operations (first drawing into a memory device and then drawing the memory device) and might have a big impact on the performance if not enough memory available to hold the entire window (worst case). If there is not enough memory available it will split the drawing operation into multiple small memory devices.

Regards,
Sven