| 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 |
#include "menu.h" |
| 44 |
#include "ST7565R.h" |
| 45 |
#include "math.h" |
| 46 |
#include "dyno.h" |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
extern volatile unsigned int ct10Ms; |
| 52 |
extern volatile unsigned char btMin; |
| 53 |
extern volatile unsigned char btEnt; |
| 54 |
extern volatile unsigned char btPlu; |
| 55 |
extern volatile unsigned char prevBtEnt; |
| 56 |
extern volatile unsigned char debounceCt; |
| 57 |
|
| 58 |
extern volatile unsigned long delay25Us; |
| 59 |
|
| 60 |
extern volatile unsigned short lcdUpdateCt; |
| 61 |
|
| 62 |
extern volatile unsigned char dutyCycle; |
| 63 |
extern volatile unsigned char maxDutyCycle; |
| 64 |
extern volatile unsigned char minDutyCycle; |
| 65 |
extern volatile unsigned char dutyCycleStep; |
| 66 |
|
| 67 |
extern unsigned char rampTime; |
| 68 |
|
| 69 |
extern volatile unsigned long long c1SquareSumRMS; |
| 70 |
volatile float c1RMS = 0; |
| 71 |
volatile unsigned char sampleADC = 1; |
| 72 |
|
| 73 |
extern volatile int adc[]; |
| 74 |
int ct = 0; |
| 75 |
|
| 76 |
extern volatile int adc1; |
| 77 |
|
| 78 |
extern volatile short filteredOffset; |
| 79 |
|
| 80 |
extern unsigned short hallTime[]; |
| 81 |
extern volatile unsigned short hallCounter; |
| 82 |
extern volatile unsigned short hallStoppedCounter; |
| 83 |
unsigned long rpm = 0; |
| 84 |
unsigned short hallAverageCt = 0; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
void AddSubmenu(menuType* pMainMenu, menuType* pSubMenu) |
| 101 |
{ |
| 102 |
if(pMainMenu->parent && pMainMenu->submenuCount == 0) |
| 103 |
{ |
| 104 |
pMainMenu->submenu[pMainMenu->submenuCount] = pMainMenu->parent; |
| 105 |
pMainMenu->submenuCount++; |
| 106 |
} |
| 107 |
|
| 108 |
pMainMenu->submenu[pMainMenu->submenuCount] = pSubMenu; |
| 109 |
pMainMenu->submenuCount++; |
| 110 |
|
| 111 |
pSubMenu->parent = pMainMenu; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void StepMenuUp(menuType* pMenu) |
| 123 |
{ |
| 124 |
if(pMenu->activeSubmenu < pMenu->submenuCount - 1) |
| 125 |
pMenu->activeSubmenu++; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
void StepMenuDown(menuType* pMenu) |
| 137 |
{ |
| 138 |
if(pMenu->activeSubmenu > 0) |
| 139 |
pMenu->activeSubmenu--; |
| 140 |
} |
| 141 |
|
| 142 |
menuType* GetActiveMenu(menuType* pMenu) |
| 143 |
{ |
| 144 |
return pMenu->submenu[pMenu->activeSubmenu]; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
void pfnMeasurements(char up, char down) |
| 158 |
{ |
| 159 |
if(lcdUpdateCt > 20000) |
| 160 |
{ |
| 161 |
sampleADC = 0; |
| 162 |
c1RMS = (sqrt(c1SquareSumRMS/4000))/151.55F; |
| 163 |
lcdUpdateCt = 0; |
| 164 |
ST7565R_String(0, 0, "Current: A", 0); |
| 165 |
ST7565R_FloatNumber(0, 50, c1RMS,2,0); |
| 166 |
ST7565R_String(1, 0, "Speed: RPM", 0); |
| 167 |
rpm = 0; |
| 168 |
|
| 169 |
if((hallCounter < 5000) && (hallStoppedCounter < 5000)) |
| 170 |
{ |
| 171 |
for(hallAverageCt = 0; hallAverageCt < 10; hallAverageCt++) |
| 172 |
{ |
| 173 |
rpm +=hallTime[hallAverageCt]; |
| 174 |
} |
| 175 |
rpm = 3000000 / rpm; |
| 176 |
} |
| 177 |
ST7565R_Number(1, 50, rpm, 0); |
| 178 |
ST7565R_String(3, 0, "Duty Cycle", 0); |
| 179 |
ST7565R_String(3, 105, "%", 0); |
| 180 |
sampleADC = 1; |
| 181 |
} |
| 182 |
if(up) |
| 183 |
{ |
| 184 |
ST7565R_String(3, 80, " ", 0); |
| 185 |
if(dutyCycle + dutyCycleStep <= 100) |
| 186 |
dutyCycle+=dutyCycleStep; |
| 187 |
else |
| 188 |
dutyCycle = 100; |
| 189 |
ST7565R_Number(3, 80, dutyCycle, 0); |
| 190 |
} |
| 191 |
else if(down) |
| 192 |
{ |
| 193 |
ST7565R_String(3, 80, " ", 0); |
| 194 |
if(dutyCycle - dutyCycleStep >= 0) |
| 195 |
dutyCycle -= dutyCycleStep; |
| 196 |
else |
| 197 |
dutyCycle = 0; |
| 198 |
ST7565R_Number(3, 80, dutyCycle, 0); |
| 199 |
} |
| 200 |
else |
| 201 |
ST7565R_Number(3, 80, dutyCycle, 0); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void pfnStep(char up, char down) |
| 215 |
{ |
| 216 |
static unsigned char stateFlag = 0; |
| 217 |
if(stateFlag) |
| 218 |
{ |
| 219 |
dutyCycle = maxDutyCycle; |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
dutyCycle = minDutyCycle; |
| 224 |
} |
| 225 |
|
| 226 |
ST7565R_String(1, 20, "Duty Cycle:", 0); |
| 227 |
ST7565R_String(1, 114, "%", 0); |
| 228 |
|
| 229 |
if(up || down) |
| 230 |
{ |
| 231 |
stateFlag = !stateFlag; |
| 232 |
if(stateFlag) |
| 233 |
{ |
| 234 |
ST7565R_String(1, 90, " ", 0); |
| 235 |
} |
| 236 |
else |
| 237 |
{ |
| 238 |
ST7565R_String(1, 90, " ", 0); |
| 239 |
} |
| 240 |
} |
| 241 |
else |
| 242 |
{ |
| 243 |
ST7565R_Number(1, 90, dutyCycle, 0); |
| 244 |
} |
| 245 |
if(stateFlag) |
| 246 |
{ |
| 247 |
dutyCycle = maxDutyCycle; |
| 248 |
ST7565R_Number(1, 90, dutyCycle, 0); |
| 249 |
} |
| 250 |
else |
| 251 |
{ |
| 252 |
dutyCycle = minDutyCycle; |
| 253 |
ST7565R_Number(1, 90, dutyCycle, 0); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
void pfnSetMax(char up, char down) |
| 268 |
{ |
| 269 |
ST7565R_String(0, 0, "Set upper duty cycle", 0); |
| 270 |
ST7565R_String(2, 80, "%", 0); |
| 271 |
if(up && (maxDutyCycle < 100)) |
| 272 |
{ |
| 273 |
ST7565R_String(2, 60, " ", 0); |
| 274 |
if(maxDutyCycle + dutyCycleStep <= 100) |
| 275 |
maxDutyCycle+=dutyCycleStep; |
| 276 |
else |
| 277 |
maxDutyCycle = 100; |
| 278 |
ST7565R_Number(2, 60, maxDutyCycle, 0); |
| 279 |
} |
| 280 |
else if(down && (maxDutyCycle > 0)) |
| 281 |
{ |
| 282 |
ST7565R_String(2, 60, " ", 0); |
| 283 |
if((maxDutyCycle - dutyCycleStep >= 0) && (maxDutyCycle - dutyCycleStep >= minDutyCycle)) |
| 284 |
maxDutyCycle-=dutyCycleStep; |
| 285 |
|
| 286 |
ST7565R_Number(2, 60, maxDutyCycle, 0); |
| 287 |
} |
| 288 |
else |
| 289 |
ST7565R_Number(2, 60, maxDutyCycle, 0); |
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
void pfnSetMin(char up, char down) |
| 304 |
{ |
| 305 |
ST7565R_String(0, 0, "Set lower duty cycle", 0); |
| 306 |
ST7565R_String(2, 80, "%", 0); |
| 307 |
if(up) |
| 308 |
{ |
| 309 |
ST7565R_String(2, 60, " ", 0); |
| 310 |
if((minDutyCycle + dutyCycleStep <= 100) && (minDutyCycle + dutyCycleStep <= maxDutyCycle)) |
| 311 |
minDutyCycle+=dutyCycleStep; |
| 312 |
ST7565R_Number(2, 60, minDutyCycle, 0); |
| 313 |
} |
| 314 |
else if(down) |
| 315 |
{ |
| 316 |
ST7565R_String(2, 60, " ", 0); |
| 317 |
if(minDutyCycle - dutyCycleStep >= 0) |
| 318 |
minDutyCycle -= dutyCycleStep; |
| 319 |
else |
| 320 |
minDutyCycle = 0; |
| 321 |
ST7565R_Number(2, 60, minDutyCycle, 0); |
| 322 |
} |
| 323 |
else |
| 324 |
ST7565R_Number(2, 60, minDutyCycle, 0); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
void pfnRamp(char up, char down) |
| 338 |
{ |
| 339 |
|
| 340 |
ST7565R_String(1, 0, "Ramp period:", 0); |
| 341 |
ST7565R_String(1, 94, "sec", 0); |
| 342 |
if(up) |
| 343 |
{ |
| 344 |
ST7565R_String(1, 80, " ", 0); |
| 345 |
if(rampTime + 1 <= 10) |
| 346 |
rampTime += 1; |
| 347 |
else |
| 348 |
rampTime = 10; |
| 349 |
ST7565R_Number(1, 80, rampTime, 0); |
| 350 |
} |
| 351 |
else if(down) |
| 352 |
{ |
| 353 |
ST7565R_String(1, 80, " ", 0); |
| 354 |
if(rampTime - 1 >= 1) |
| 355 |
rampTime -= 1; |
| 356 |
else |
| 357 |
rampTime = 1; |
| 358 |
ST7565R_Number(1, 80, rampTime, 0); |
| 359 |
} |
| 360 |
else |
| 361 |
ST7565R_Number(1, 80, rampTime, 0); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
void pfnDutyCycleStep(char up, char down) |
| 375 |
{ |
| 376 |
ST7565R_String(0, 0, "Set duty cycle step", 0); |
| 377 |
if(up && (dutyCycleStep < 25)) |
| 378 |
{ |
| 379 |
ST7565R_String(2, 60, " ", 0); |
| 380 |
ST7565R_Number(2, 60, ++dutyCycleStep, 0); |
| 381 |
} |
| 382 |
else if(down && (dutyCycleStep > 1)) |
| 383 |
{ |
| 384 |
ST7565R_String(2, 60, " ", 0); |
| 385 |
ST7565R_Number(2, 60, --dutyCycleStep, 0); |
| 386 |
} |
| 387 |
else |
| 388 |
ST7565R_Number(2, 60, dutyCycleStep, 0); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
void pfnAbout(char up, char down) |
| 402 |
{ |
| 403 |
ST7565R_String(1, 10, "AD-DYNO1-EBZ REV A", 0); |
| 404 |
ST7565R_String(2, 30, "SW REV 0.1", 0); |
| 405 |
} |