@@ -370,36 +370,44 @@ where
370
370
TIM : Instance + WithPwm ,
371
371
PINS : Pins < TIM , P > ,
372
372
{
373
+ /// Enable PWM output of the timer on channel `channel`
373
374
#[ inline]
374
375
pub fn enable ( & mut self , channel : Channel ) {
375
376
TIM :: enable_channel ( PINS :: check_used ( channel) as u8 , true )
376
377
}
377
378
379
+ /// Disable PWM output of the timer on channel `channel`
378
380
#[ inline]
379
381
pub fn disable ( & mut self , channel : Channel ) {
380
382
TIM :: enable_channel ( PINS :: check_used ( channel) as u8 , false )
381
383
}
382
384
385
+ /// Set the polarity of the active state for the primary PWM output of the timer on channel `channel`
383
386
#[ inline]
384
387
pub fn set_polarity ( & mut self , channel : Channel , p : Polarity ) {
385
388
TIM :: set_channel_polarity ( PINS :: check_used ( channel) as u8 , p) ;
386
389
}
387
390
391
+ /// Get the current duty cycle of the timer on channel `channel`
388
392
#[ inline]
389
393
pub fn get_duty ( & self , channel : Channel ) -> u16 {
390
394
TIM :: read_cc_value ( PINS :: check_used ( channel) as u8 ) as u16
391
395
}
392
396
397
+ /// Set the duty cycle of the timer on channel `channel`
393
398
#[ inline]
394
399
pub fn set_duty ( & mut self , channel : Channel , duty : u16 ) {
395
400
TIM :: set_cc_value ( PINS :: check_used ( channel) as u8 , duty as u32 )
396
401
}
397
402
403
+ /// Get the maximum duty cycle value of the timer
404
+ ///
398
405
/// If `0` returned means max_duty is 2^16
399
406
pub fn get_max_duty ( & self ) -> u16 {
400
407
( TIM :: read_auto_reload ( ) as u16 ) . wrapping_add ( 1 )
401
408
}
402
409
410
+ /// Get the PWM frequency of the timer in Hertz
403
411
pub fn get_period ( & self ) -> Hertz {
404
412
let clk = self . clk ;
405
413
let psc = self . tim . read_prescaler ( ) as u32 ;
@@ -409,6 +417,7 @@ where
409
417
clk / ( ( psc + 1 ) * ( arr + 1 ) )
410
418
}
411
419
420
+ /// Set the PWM frequency for the timer in Hertz
412
421
pub fn set_period ( & mut self , period : Hertz ) {
413
422
let clk = self . clk ;
414
423
@@ -418,6 +427,7 @@ where
418
427
self . tim . cnt_reset ( ) ;
419
428
}
420
429
430
+ /// Set the polarity of the active state for the complementary PWM output of the advanced timer on channel `channel`
421
431
#[ inline]
422
432
pub fn set_complementary_polarity ( & mut self , channel : Channel , p : Polarity ) {
423
433
TIM :: set_channel_polarity ( PINS :: check_complementary_used ( channel) as u8 , p) ;
@@ -429,30 +439,39 @@ where
429
439
TIM : Instance + WithPwm + Advanced ,
430
440
PINS : Pins < TIM , P > ,
431
441
{
442
+ /// Enable complementary PWM output of the timer on channel `channel`
432
443
#[ inline]
433
444
pub fn enable_complementary ( & mut self , channel : Channel ) {
434
445
TIM :: enable_nchannel ( PINS :: check_complementary_used ( channel) as u8 , true )
435
446
}
436
447
448
+ /// Disable complementary PWM output of the timer on channel `channel`
437
449
#[ inline]
438
450
pub fn disable_complementary ( & mut self , channel : Channel ) {
439
451
TIM :: enable_nchannel ( PINS :: check_complementary_used ( channel) as u8 , false )
440
452
}
441
453
442
- /// Set number DTS ticks during that complementary pin is `dead`
454
+ /// Set number DTS ticks during that the primary and complementary PWM pins are simultaneously forced to their inactive states
455
+ /// ( see [`Polarity`] setting ) when changing PWM state. This duration when both channels are in an 'off' state is called 'dead time'.
456
+ ///
457
+ /// This is necessary in applications like motor control or power converters to prevent the destruction of the switching elements by
458
+ /// short circuit in the moment of switching.
443
459
#[ inline]
444
460
pub fn set_dead_time ( & mut self , dts_ticks : u16 ) {
445
461
let bits = pack_ceil_dead_time ( dts_ticks) ;
446
462
TIM :: set_dtg_value ( bits) ;
447
463
}
448
464
449
465
/// Set raw dead time (DTG) bits
466
+ ///
467
+ /// The dead time generation is nonlinear and constrained by the DTS tick duration. DTG register configuration and calculation of
468
+ /// the actual resulting dead time is described in the application note RM0368 from ST Microelectronics
450
469
#[ inline]
451
470
pub fn set_dead_time_bits ( & mut self , bits : u8 ) {
452
471
TIM :: set_dtg_value ( bits) ;
453
472
}
454
473
455
- /// Return dead time for complementary pins in DTS ticks
474
+ /// Return dead time for complementary pins in the unit of DTS ticks
456
475
#[ inline]
457
476
pub fn get_dead_time ( & self ) -> u16 {
458
477
unpack_dead_time ( TIM :: read_dtg_value ( ) )
@@ -464,11 +483,13 @@ where
464
483
TIM :: read_dtg_value ( )
465
484
}
466
485
486
+ /// Set the pin idle state
467
487
#[ inline]
468
488
pub fn set_idle_state ( & mut self , channel : Channel , s : IdleState ) {
469
489
TIM :: idle_state ( PINS :: check_used ( channel) as u8 , false , s) ;
470
490
}
471
491
492
+ /// Set the complementary pin idle state
472
493
#[ inline]
473
494
pub fn set_complementary_idle_state ( & mut self , channel : Channel , s : IdleState ) {
474
495
TIM :: idle_state ( PINS :: check_complementary_used ( channel) as u8 , true , s) ;
0 commit comments