@@ -277,26 +277,21 @@ bool TONE_PWM_CONFIG::InitializeFromPulseCountAndTimePeriod(uint64_t pulse_count
277
277
this ->duty_with_polarity = 0x8000U | (time_period / 2U );
278
278
279
279
if (this ->pulse_count == 0 ) {
280
- LOG_LV3 (" TON" , " Infinite duration requested\n " );
281
-
282
280
this ->seq0_refresh = 0xFFFFFFU ; // 24-bit maximum value
283
281
this ->seq1_refresh = 0xFFFFFFU ; // 24-bit maximum value
284
282
this ->loop_count = 0xFFFFU ; // 16-bit maximum value
285
283
this ->task_to_start = NRF_PWM_TASK_SEQSTART0;
286
284
this ->shorts = NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
287
285
}
288
286
else if (this ->pulse_count == 1 ) {
289
- LOG_LV3 (" TON" , " Edge case: exactly one pulse\n " );
290
- // yes, this is an edge case
287
+ // yes, this is an edge case; e.g., frequency == 100, duration == 100 causes this
291
288
this ->seq0_refresh = 0 ;
292
289
this ->seq1_refresh = 0 ;
293
290
this ->loop_count = 1 ;
294
291
this ->task_to_start = NRF_PWM_TASK_SEQSTART1;
295
292
this ->shorts = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
296
293
}
297
294
else {
298
- LOG_LV3 (" TON" , " Non-infinite duration of at least two pulses requested\n " );
299
-
300
295
// This is the interesting section.
301
296
//
302
297
// To ensure refresh value stays within 24 bits, the maximum number of bits
@@ -318,37 +313,27 @@ bool TONE_PWM_CONFIG::InitializeFromPulseCountAndTimePeriod(uint64_t pulse_count
318
313
319
314
// NOTE: Due to final SEQ1 outputting exactly one pulse, may need one additional bit for loop count
320
315
// ... but that will still be within the 16 bits available, because top of range is 13 bits.
321
- LOG_LV3 (" TON" , " Using %d bits for refresh, and %d bits for loop_count\n " , bits_for_refresh, bits_for_loop_count);
322
316
323
317
// now determine how many PWM pulses should occur per loop (when both SEQ0 and SEQ1 are played)
324
318
uint32_t total_refresh_count = 1 << bits_for_refresh; // range is [2 .. 2^24]
325
319
uint32_t full_loops = (this ->pulse_count - 1 ) / total_refresh_count; // == loopCount - 1
326
320
327
- LOG_LV3 (" TON" , " total_refresh_count is 0x%" PRIx32 " (%" PRIu32 " )\n " , total_refresh_count, total_refresh_count);
328
- LOG_LV3 (" TON" , " full_loops is 0x%" PRIx32 " (%" PRIu32 " )\n " , full_loops, full_loops);
329
-
330
321
// if (pulses - 1) % total_refresh_count == 0, then start at SEQ1 and split refresh evenly
331
322
// else, start at SEQ0, and set SEQ0 to extra pulses needed...
332
323
uint32_t extraPulsesNeededIfStartingAtSequence1 = (this ->pulse_count - 1 ) % total_refresh_count;
333
324
uint32_t seq0_count;
334
325
335
326
if (extraPulsesNeededIfStartingAtSequence1 == 0 ) {
336
- LOG_LV3 (" TON" , " Pulse count (minus one) is exact multiple of total_refresh_count -- starting at SEQ1\n " );
337
327
seq0_count = total_refresh_count / 2 ; // range is [1 .. 2^23]
338
328
this ->task_to_start = NRF_PWM_TASK_SEQSTART1;
339
329
}
340
330
else {
341
- LOG_LV3 (" TON" , " Pulse count (minus one) requires extra %" PRIu32 " pulses ... setting SEQ0 to that value\n " , extraPulsesNeededIfStartingAtSequence1);
342
331
seq0_count = extraPulsesNeededIfStartingAtSequence1;
343
332
this ->task_to_start = NRF_PWM_TASK_SEQSTART0;
344
333
}
345
334
this ->loop_count = full_loops + 1 ;
346
335
this ->seq0_refresh = seq0_count - 1 ;
347
336
this ->seq1_refresh = (total_refresh_count - seq0_count) - 1 ;
348
-
349
- LOG_LV3 (" TON" , " seq0_count is %" PRIu32 " , so refresh will be set to %" PRIu32 " \n " , seq0_count, this ->seq0_refresh );
350
- LOG_LV3 (" TON" , " seq1_count is %" PRIu32 " , so refresh will be set to %" PRIu32 " \n " , (total_refresh_count - seq0_count), this ->seq1_refresh );
351
-
352
337
this ->shorts = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
353
338
}
354
339
this ->is_initialized = true ;
0 commit comments