forked from geissdoerfer/shepherd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
virtual_harvester.c
525 lines (454 loc) · 21.3 KB
/
virtual_harvester.c
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#include "virtual_harvester.h"
#include "calibration.h"
#include "hw_config.h"
#include "math64_safe.h"
#include "spi_transfer_pru.h"
#include <stdint.h>
// internal variables
static uint32_t voltage_set_uV = 0u;
static bool_ft is_rising = 0u;
static uint32_t voltage_hold = 0u;
static uint32_t current_hold = 0u;
static uint32_t voltage_step_x4_uV = 0u;
static uint32_t settle_steps = 0; // adc_ivcurve
static uint32_t interval_step = 1u << 30u;
static uint32_t volt_step_uV = 0u;
static uint32_t power_last_raw = 0u; // adc_mppt_po
static const volatile struct HarvesterConfig *cfg;
// to be used with harvester-frontend
static void harvest_adc_2_ivcurve(struct SampleBuffer *const buffer, const uint32_t sample_idx);
static void harvest_adc_2_isc_voc(struct SampleBuffer *const buffer, const uint32_t sample_idx);
static void harvest_adc_2_cv(struct SampleBuffer *const buffer, const uint32_t sample_idx);
static void harvest_adc_2_mppt_voc(struct SampleBuffer *const buffer, const uint32_t sample_idx);
static void harvest_adc_2_mppt_po(struct SampleBuffer *const buffer, const uint32_t sample_idx);
// to be used in virtual harvester (part of emulator)
static void harvest_ivcurve_2_cv(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA);
static void harvest_ivcurve_2_mppt_voc(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA);
static void harvest_ivcurve_2_mppt_po(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA);
static void harvest_ivcurve_2_mppt_opt(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA);
#define HRV_ISC_VOC (1u << 3u)
#define HRV_IVCURVE (1u << 4u)
#define HRV_CV (1u << 8u)
#define HRV_MPPT_VOC (1u << 12u)
#define HRV_MPPT_PO (1u << 13u)
#define HRV_MPPT_OPT (1u << 14u)
void harvester_initialize(const volatile struct HarvesterConfig *const config)
{
// basic (shared) states for ADC- and IVCurve-Version
cfg = config;
voltage_set_uV = cfg->voltage_uV + 1u; // deliberately off for cv-version
settle_steps = 0u;
interval_step = 1u << 30u; // deliberately out of bounds
// TODO: hrv_mode-bit0 is "emulation"-detector
is_rising = (cfg->hrv_mode >> 1u) & 1u;
// MPPT-PO
volt_step_uV = cfg->voltage_step_uV;
power_last_raw = 0u;
// for IV-Curve-Version, mostly resets states
voltage_hold = 0u;
current_hold = 0u;
voltage_step_x4_uV = cfg->voltage_step_uV << 2u;
// TODO: all static vars in sub-fns should be globals (they are anyway), saves space due to overlaps
// TODO: check that ConfigParams are used in SubFns if applicable
// TODO: divide lib into IVC and ADC Parts
// TODO: embed cfg->current_limit_nA as a limiter if resources allow for it
}
uint32_t sample_adc_harvester(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
if (cfg->algorithm >= HRV_MPPT_PO) harvest_adc_2_mppt_po(buffer, sample_idx);
else if (cfg->algorithm >= HRV_MPPT_VOC) harvest_adc_2_mppt_voc(buffer, sample_idx);
else if (cfg->algorithm >= HRV_CV) harvest_adc_2_cv(buffer, sample_idx);
else if (cfg->algorithm >= HRV_IVCURVE) harvest_adc_2_ivcurve(buffer, sample_idx);
else if (cfg->algorithm >= HRV_ISC_VOC) harvest_adc_2_isc_voc(buffer, sample_idx);
// todo: else send error to system
return 0u;
}
static void harvest_adc_2_cv(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
/* Set constant voltage and log resulting current
* - ADC and DAC voltage should match but can vary, depending on calibration and load (no closed loop)
* - Note: could be self-adjusting (in loop with adc) if needed
* - influencing parameters: voltage_uV,
*/
/* ADC-Sample probably not ready -> Trigger at timer_cmp -> ads8691 needs 1us to acquire and convert */
/* NOTE: it's in here so this timeslot can be used for calculations */
__delay_cycles(800 / 5);
const uint32_t current_adc = adc_fastread(SPI_CS_HRV_C_ADC_PIN);
const uint32_t voltage_adc = adc_fastread(SPI_CS_HRV_V_ADC_PIN);
if (voltage_set_uV != cfg->voltage_uV)
{
/* set new voltage if not already set */
voltage_set_uV = cfg->voltage_uV;
const uint32_t voltage_raw = cal_conv_uV_to_dac_raw(voltage_set_uV);
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | voltage_raw);
}
buffer->values_current[sample_idx] = current_adc;
buffer->values_voltage[sample_idx] = voltage_adc;
}
static void harvest_adc_2_ivcurve(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
/* Record iv-curves
* - by controlling voltage with sawtooth
* - influencing parameters: window_size, voltage_min_uV, voltage_max_uV, voltage_step_uV, wait_cycles_n, hrv_mode (init)
*/
/* ADC-Sample probably not ready -> Trigger at timer_cmp -> ads8691 needs 1us to acquire and convert */
/* NOTE: it's in here so this timeslot can be used for calculations */
__delay_cycles(800 / 5);
const uint32_t current_adc = adc_fastread(SPI_CS_HRV_C_ADC_PIN);
const uint32_t voltage_adc = adc_fastread(SPI_CS_HRV_V_ADC_PIN);
if (settle_steps == 0u)
{
if (++interval_step >= cfg->window_size)
{
/* reset curve to start */
voltage_set_uV = is_rising ? cfg->voltage_min_uV : cfg->voltage_max_uV;
interval_step = 0u;
}
else
{
/* stepping through */
if (is_rising) voltage_set_uV = add32(voltage_set_uV, cfg->voltage_step_uV);
else voltage_set_uV = sub32(voltage_set_uV, cfg->voltage_step_uV);
}
/* check boundaries */
if (is_rising && (voltage_set_uV > cfg->voltage_max_uV))
voltage_set_uV = cfg->voltage_max_uV;
if ((!is_rising) && (voltage_set_uV < cfg->voltage_min_uV))
voltage_set_uV = cfg->voltage_min_uV;
/* write new step */
const uint32_t voltage_raw = cal_conv_uV_to_dac_raw(voltage_set_uV);
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | voltage_raw);
settle_steps = cfg->wait_cycles_n;
}
else settle_steps--;
buffer->values_current[sample_idx] = current_adc;
buffer->values_voltage[sample_idx] = voltage_adc;
}
static void harvest_adc_2_isc_voc(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
/* Record VOC & ISC
* - open the circuit -> voltage will settle when set to MAX
* - short circuit current -> current will rise when voltage is set to 0
* - influencing parameters: wait_cycles_n
*/
/* ADC-Sample probably not ready -> Trigger at timer_cmp -> ads8691 needs 1us to acquire and convert */
/* NOTE: it's in here so this timeslot can be used for calculations */
__delay_cycles(800 / 5);
const uint32_t current_adc = adc_fastread(SPI_CS_HRV_C_ADC_PIN);
const uint32_t voltage_adc = adc_fastread(SPI_CS_HRV_V_ADC_PIN);
if (settle_steps == 0u)
{
/* write new state (is_rising == VOC, else ISC)*/
const uint32_t voltage_raw = is_rising ? DAC_MAX_VAL : 0u;
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | voltage_raw);
/* sample and hold after settling-period */
if (is_rising) current_hold = current_adc;
else voltage_hold = voltage_adc;
/* prepare next state-change */
is_rising ^= 1u; // reverse direction
settle_steps = cfg->wait_cycles_n;
}
else settle_steps--;
buffer->values_current[sample_idx] = current_hold;
buffer->values_voltage[sample_idx] = voltage_hold;
}
static void harvest_adc_2_mppt_voc(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
/* Determine VOC and harvest
* - first part of interval is used for determining the open circuit voltage
* - Determine VOC: set DAC to max voltage -> hrv will settle at open voltage -> wait till end of measurement duration and sample valid voltage
* - influencing parameters: interval_n, duration_n, setpoint_n8, voltage_max_uV, voltage_min_uV, indirectly wait_cycles_n,
*/
/* ADC-Sample probably not ready -> Trigger at timer_cmp -> ads8691 needs 1us to acquire and convert */
/* NOTE: it's in here so this timeslot can be used for calculations later */
__delay_cycles(800 / 5);
const uint32_t current_adc = adc_fastread(SPI_CS_HRV_C_ADC_PIN);
const uint32_t voltage_adc = adc_fastread(SPI_CS_HRV_V_ADC_PIN);
/* keep track of time, do step = mod(step + 1, n) */
if (++interval_step >= cfg->interval_n) interval_step = 0u;
if (interval_step == 0u)
{
/* open the circuit -> voltage will settle */
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | DAC_MAX_VAL);
}
if (interval_step == cfg->duration_n - 1u)
{
/* end of voc-measurement -> lock-in the value */
const uint32_t voc_uV = cal_conv_adc_raw_to_uV(voltage_adc);
voltage_set_uV = mul32(voc_uV, cfg->setpoint_n8) >> 8u;
/* check boundaries */
if (voltage_set_uV > cfg->voltage_max_uV) voltage_set_uV = cfg->voltage_max_uV;
if (voltage_set_uV < cfg->voltage_min_uV) voltage_set_uV = cfg->voltage_min_uV;
/* write setpoint voltage */
const uint32_t voltage_raw = cal_conv_uV_to_dac_raw(voltage_set_uV);
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | voltage_raw);
}
if (interval_step < cfg->duration_n)
{
/* output disconnected during voc-measurement */
buffer->values_current[sample_idx] = 0u;
buffer->values_voltage[sample_idx] = voltage_adc; // keep voltage for debug-purposes
}
else
{
/* converter-mode at pre-set VOC */
buffer->values_current[sample_idx] = current_adc;
buffer->values_voltage[sample_idx] = voltage_adc;
}
}
static void harvest_adc_2_mppt_po(struct SampleBuffer *const buffer, const uint32_t sample_idx)
{
/* perturb & observe
* - move a voltage step every interval and evaluate power-increase
* - if higher -> keep this step-direction and begin doubling step-size
* - if lower -> reverse direction and move the smallest step back
* - resulting steps if direction is kept: 1, 1, 2, 4, 8, ...
* - influencing parameters: interval_n, voltage_set_uV, voltage_step_uV, voltage_min_uV, voltage_max_uV,
*/
/* ADC-Sample probably not ready -> Trigger at timer_cmp -> ads8691 needs 1us to acquire and convert */
/* NOTE: it's in here so this timeslot can be used for calculations */
__delay_cycles(800 / 5);
const uint32_t current_adc = adc_fastread(SPI_CS_HRV_C_ADC_PIN);
const uint32_t voltage_adc = adc_fastread(SPI_CS_HRV_V_ADC_PIN);
/* keep track of time, do step = mod(step + 1, n) */
if (++interval_step >= cfg->interval_n) interval_step = 0u;
if (interval_step == 0u)
{
const uint32_t power_raw = mul32(current_adc, voltage_adc);
if (power_raw > power_last_raw)
{
/* got higher power -> keep direction, move further, speed up */
if (is_rising) voltage_set_uV = add32(voltage_set_uV, volt_step_uV);
else voltage_set_uV = sub32(voltage_set_uV, volt_step_uV);
volt_step_uV = mul32(2u, volt_step_uV);
if (volt_step_uV > 300000u) volt_step_uV = 300000u; // TODO: new, max step size
}
else
{
/* got less power -> reverse direction, restart step-size */
is_rising ^= 1u;
volt_step_uV = cfg->voltage_step_uV;
if (is_rising) voltage_set_uV = add32(voltage_set_uV, volt_step_uV);
else voltage_set_uV = sub32(voltage_set_uV, volt_step_uV);
}
power_last_raw = power_raw;
// TODO: experimental, to keep contact to solar-voltage when voltage is dropping
const uint32_t adc_uV = cal_conv_adc_raw_to_uV(voltage_adc);
const uint32_t diff_uV = sub32(voltage_set_uV, adc_uV);
if (is_rising && (diff_uV > (volt_step_uV << 1u)))
{
is_rising = 0u;
voltage_set_uV = sub32(adc_uV, volt_step_uV);
}
/* check boundaries */
if (voltage_set_uV >= cfg->voltage_max_uV)
{
voltage_set_uV = cfg->voltage_max_uV;
is_rising = 0u;
volt_step_uV = cfg->voltage_step_uV;
}
if (voltage_set_uV <= cfg->voltage_min_uV)
{
voltage_set_uV = cfg->voltage_min_uV;
is_rising = 1u;
volt_step_uV = cfg->voltage_step_uV;
}
/* write setpoint voltage */
const uint32_t voltage_raw = cal_conv_uV_to_dac_raw(voltage_set_uV);
dac_write(SPI_CS_HRV_DAC_PIN, DAC_CH_B_ADDR | voltage_raw);
}
buffer->values_current[sample_idx] = current_adc;
buffer->values_voltage[sample_idx] = voltage_adc;
}
/* // TODO: do we need a constant-current-version?
const uint32_t current_nA = cal_conv_adc_raw_to_nA(current_adc); // TODO: could be simplified by providing raw-value in cfg
if (current_nA > cfg->current_limit_nA)
*/
void sample_ivcurve_harvester(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA)
{
// check for IVCurve-Input Indicator and use selected algo
if (cfg->window_size <= 1) return;
else if (cfg->algorithm >= HRV_MPPT_OPT) harvest_ivcurve_2_mppt_opt(p_voltage_uV, p_current_nA);
else if (cfg->algorithm >= HRV_MPPT_PO) harvest_ivcurve_2_mppt_po(p_voltage_uV, p_current_nA);
else if (cfg->algorithm >= HRV_MPPT_VOC) harvest_ivcurve_2_mppt_voc(p_voltage_uV, p_current_nA);
else if (cfg->algorithm >= HRV_CV) harvest_ivcurve_2_cv(p_voltage_uV, p_current_nA);
// todo: else send error to system
}
static void harvest_ivcurve_2_cv(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA)
{
/* look for wanted constant voltage in an iv-curve-stream (constantly moving up or down in voltage, jumping back when limit reached)
* - influencing parameters: voltage_uV (in init)
* - no min/max usage here, the main FNs do that, or python if cv() is used directly
* */
static uint32_t voltage_last = 0u, current_last = 0u;
static bool_ft compare_last = 0u;
/* find matching voltage with threshold-crossing-detection -> direction of curve is irrelevant */
const bool_ft compare_now = *p_voltage_uV < voltage_set_uV;
/* abs(step_size) -> for detecting reset of sawtooth */
const uint32_t step_size_now = (*p_voltage_uV > voltage_last) ? (*p_voltage_uV - voltage_last)
: (voltage_last - *p_voltage_uV);
/* voltage_set_uV can change outside of loop, so algo has to keep track */
const uint32_t distance_now = (*p_voltage_uV > voltage_set_uV)
? (*p_voltage_uV - voltage_set_uV)
: (voltage_set_uV - *p_voltage_uV);
const uint32_t distance_last = (voltage_last > voltage_set_uV)
? (voltage_last - voltage_set_uV)
: (voltage_set_uV - voltage_last);
if ((compare_now != compare_last) && (step_size_now < voltage_step_x4_uV))
{
/* a fresh ConstVoltage was found in stream, choose the closer value
* TODO: could also be interpolated if sampling-routine has time to spare */
if ((distance_now < distance_last) && (distance_now < voltage_step_x4_uV))
{
voltage_hold = *p_voltage_uV;
current_hold = *p_current_nA;
}
else if ((distance_last < distance_now) && (distance_last < voltage_step_x4_uV))
{
voltage_hold = voltage_last;
current_hold = current_last;
}
}
voltage_last = *p_voltage_uV;
current_last = *p_current_nA;
compare_last = compare_now;
/* manipulate the values of the parameter-pointers ("return values") */
*p_voltage_uV = voltage_hold;
*p_current_nA = current_hold;
}
static void harvest_ivcurve_2_mppt_voc(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA)
{
/* VOC - working on an iv-curve-stream, without complete curve-memory
* NOTE with no memory, there is a time-gap before CV gets picked up by harvest_ivcurve_2_cv()
* - influencing parameters: interval_n, duration_n, current_limit_nA, voltage_min_uV, voltage_max_uV, setpoint_n8, window_size
* from init: (wait_cycles_n), voltage_uV (for cv())
*/
static uint32_t age_now = 0u, voc_now = 0u;
static uint32_t age_nxt = 0u, voc_nxt = 0u;
/* keep track of time, do step = mod(step + 1, n) */
if (++interval_step >= cfg->interval_n) interval_step = 0u;
age_nxt++;
age_now++;
/* lookout for new VOC */
if ((*p_current_nA < cfg->current_limit_nA) && (*p_voltage_uV <= voc_nxt) &&
(*p_voltage_uV >= cfg->voltage_min_uV) && (*p_voltage_uV <= cfg->voltage_max_uV))
{
voc_nxt = *p_voltage_uV;
age_nxt = 0u;
}
/* current "best VOC" (the lowest voltage with zero-current) can not get too old, or be NOT the best */
if ((age_now > cfg->window_size) || (voc_nxt <= voc_now))
{
age_now = age_nxt;
voc_now = voc_nxt;
age_nxt = 0u;
voc_nxt = cfg->voltage_max_uV;
}
/* underlying cv-algo is doing the rest */
harvest_ivcurve_2_cv(p_voltage_uV, p_current_nA);
/* emulate VOC Search @ beginning of interval duration */
if (interval_step < cfg->duration_n)
{
/* No Output here, also update wanted const voltage */
voltage_set_uV = mul32(voc_now, cfg->setpoint_n8) >> 8u;
*p_current_nA = 0u;
}
}
static void harvest_ivcurve_2_mppt_po(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA)
{
/* Perturb & Observe
* NOTE with no memory, there is a time-gap before CV gets picked up by harvest_ivcurve_2_cv()
* - influencing parameters: interval_n, voltage_step_uV, voltage_max_uV, voltage_min_uV
*/
static uint32_t power_last = 0u;
/* keep track of time, do step = mod(step + 1, n) */
if (++interval_step >= cfg->interval_n) interval_step = 0u;
/* underlying cv-algo is updating the current harvest-power */
harvest_ivcurve_2_cv(p_voltage_uV, p_current_nA);
/* p_voltage_uV and p_current_nA are changed now! */
if (interval_step == 0u)
{
const uint32_t power_now = mul32(*p_voltage_uV, *p_current_nA);
if (power_now > power_last)
{
/* got higher power -> keep direction, move further, speed up */
if (is_rising) voltage_set_uV = add32(voltage_set_uV, volt_step_uV);
else voltage_set_uV = sub32(voltage_set_uV, volt_step_uV);
volt_step_uV = mul32(2u, volt_step_uV);
}
else
{
if ((power_now == 0) && (voltage_set_uV > 0))
{
/* lost tracking - or started with bad init */
is_rising = 1u;
volt_step_uV = cfg->voltage_step_uV;
voltage_set_uV = sub32(voltage_set_uV, voltage_step_x4_uV);
}
else
{
/* got less power -> reverse direction */
is_rising ^= 1u;
volt_step_uV = cfg->voltage_step_uV;
if (is_rising) voltage_set_uV = add32(voltage_set_uV, volt_step_uV);
else voltage_set_uV = sub32(voltage_set_uV, volt_step_uV);
}
}
power_last = power_now;
/* check boundaries */
if (voltage_set_uV >= cfg->voltage_max_uV)
{
voltage_set_uV = cfg->voltage_max_uV;
is_rising = 0u;
volt_step_uV = cfg->voltage_step_uV;
}
if (voltage_set_uV <= cfg->voltage_min_uV)
{
voltage_set_uV = cfg->voltage_min_uV;
is_rising = 1u;
volt_step_uV = cfg->voltage_step_uV;
}
if (voltage_set_uV < cfg->voltage_step_uV)
{
voltage_set_uV = cfg->voltage_step_uV;
is_rising = 1u;
volt_step_uV = cfg->voltage_step_uV;
}
}
}
static void harvest_ivcurve_2_mppt_opt(uint32_t *const p_voltage_uV, uint32_t *const p_current_nA)
{
/* Derivate of VOC -> selects the highest power directly
* - influencing parameters: window_size, voltage_min_uV, voltage_max_uV,
*/
static uint32_t age_now = 0u, power_now = 0u, voltage_now = 0u, current_now = 0u;
static uint32_t age_nxt = 0u, power_nxt = 0u, voltage_nxt = 0u, current_nxt = 0u;
/* keep track of time */
age_nxt++;
age_now++;
/* search for new max */
const uint32_t power_fW = mul32(*p_voltage_uV, *p_current_nA);
if ((power_fW >= power_nxt) && (*p_voltage_uV >= cfg->voltage_min_uV) &&
(*p_voltage_uV <= cfg->voltage_max_uV))
{
age_nxt = 0u;
power_nxt = power_fW;
voltage_nxt = *p_voltage_uV;
current_nxt = *p_current_nA;
}
/* current "best VOC" (the lowest voltage with zero-current) can not get too old, or NOT be the best */
if ((age_now > cfg->window_size) || (power_nxt >= power_now))
{
age_now = age_nxt;
power_now = power_nxt;
voltage_now = voltage_nxt;
current_now = current_nxt;
age_nxt = 0u;
power_nxt = 0u;
voltage_nxt = 0u;
current_nxt = 0u;
}
/* return current max */
*p_voltage_uV = voltage_now;
*p_current_nA = current_now;
}