@@ -237,11 +237,8 @@ status_t FTM_Init(FTM_Type *base, const ftm_config_t *config)
237
237
/* Configure the update mechanism for buffered registers */
238
238
FTM_SetPwmSync (base , config -> pwmSyncMode );
239
239
240
- if (config -> reloadPoints )
241
- {
242
- /* Setup intermediate register reload points */
243
- FTM_SetReloadPoints (base , config -> reloadPoints );
244
- }
240
+ /* Setup intermediate register reload points */
241
+ FTM_SetReloadPoints (base , config -> reloadPoints );
245
242
246
243
/* Set the clock prescale factor */
247
244
base -> SC = FTM_SC_PS (config -> prescale );
@@ -327,6 +324,9 @@ status_t FTM_SetupPwm(FTM_Type *base,
327
324
uint32_t srcClock_Hz )
328
325
{
329
326
assert (chnlParams );
327
+ assert (srcClock_Hz );
328
+ assert (pwmFreq_Hz );
329
+ assert (numOfChnls );
330
330
331
331
uint32_t mod , reg ;
332
332
uint32_t ftmClock = (srcClock_Hz / (1U << (base -> SC & FTM_SC_PS_MASK )));
@@ -373,7 +373,7 @@ status_t FTM_SetupPwm(FTM_Type *base,
373
373
reg &= ~(FTM_CnSC_MSA_MASK | FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK | FTM_CnSC_ELSB_MASK );
374
374
375
375
/* Setup the active level */
376
- reg |= (FTM_CnSC_ELSA (chnlParams -> level ) | FTM_CnSC_ELSB ( chnlParams -> level ) );
376
+ reg |= (uint32_t ) (chnlParams -> level << FTM_CnSC_ELSA_SHIFT );
377
377
378
378
/* Edge-aligned mode needs MSB to be 1, don't care for Center-aligned mode */
379
379
reg |= FTM_CnSC_MSB (1U );
@@ -397,6 +397,10 @@ status_t FTM_SetupPwm(FTM_Type *base,
397
397
}
398
398
399
399
base -> CONTROLS [chnlParams -> chnlNumber ].CnV = cnv ;
400
+ #if defined(FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT ) && (FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT )
401
+ /* Set to output mode */
402
+ FTM_SetPwmOutputEnable (base , chnlParams -> chnlNumber , true);
403
+ #endif
400
404
}
401
405
else
402
406
{
@@ -445,7 +449,7 @@ status_t FTM_SetupPwm(FTM_Type *base,
445
449
reg &= ~(FTM_CnSC_MSA_MASK | FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK | FTM_CnSC_ELSB_MASK );
446
450
447
451
/* Setup the active level for channel n */
448
- reg |= (FTM_CnSC_ELSA (chnlParams -> level ) | FTM_CnSC_ELSB ( chnlParams -> level ) );
452
+ reg |= (uint32_t ) (chnlParams -> level << FTM_CnSC_ELSA_SHIFT );
449
453
450
454
/* Update the mode and edge level for channel n */
451
455
base -> CONTROLS [chnlParams -> chnlNumber * 2 ].CnSC = reg ;
@@ -455,25 +459,25 @@ status_t FTM_SetupPwm(FTM_Type *base,
455
459
reg &= ~(FTM_CnSC_MSA_MASK | FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK | FTM_CnSC_ELSB_MASK );
456
460
457
461
/* Setup the active level for channel n + 1 */
458
- reg |= (FTM_CnSC_ELSA (chnlParams -> level ) | FTM_CnSC_ELSB ( chnlParams -> level ) );
462
+ reg |= (uint32_t ) (chnlParams -> level << FTM_CnSC_ELSA_SHIFT );
459
463
460
464
/* Update the mode and edge level for channel n + 1*/
461
465
base -> CONTROLS [(chnlParams -> chnlNumber * 2 ) + 1 ].CnSC = reg ;
462
466
463
- /* Set the channel pair values */
464
- base -> CONTROLS [chnlParams -> chnlNumber * 2 ].CnV = cnvFirstEdge ;
465
- base -> CONTROLS [(chnlParams -> chnlNumber * 2 ) + 1 ].CnV = cnvFirstEdge + cnv ;
466
-
467
467
/* Set the combine bit for the channel pair */
468
468
base -> COMBINE |=
469
469
(1U << (FTM_COMBINE_COMBINE0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlParams -> chnlNumber )));
470
- }
470
+
471
+ /* Set the channel pair values */
472
+ base -> CONTROLS [chnlParams -> chnlNumber * 2 ].CnV = cnvFirstEdge ;
473
+ base -> CONTROLS [(chnlParams -> chnlNumber * 2 ) + 1 ].CnV = cnvFirstEdge + cnv ;
471
474
472
475
#if defined(FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT ) && (FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT )
473
- /* Set to output mode */
474
- FTM_SetPwmOutputEnable (base , chnlParams -> chnlNumber , true);
476
+ /* Set to output mode */
477
+ FTM_SetPwmOutputEnable (base , (ftm_chnl_t )((uint8_t )chnlParams -> chnlNumber * 2 ), true);
478
+ FTM_SetPwmOutputEnable (base , (ftm_chnl_t )((uint8_t )chnlParams -> chnlNumber * 2 + 1 ), true);
475
479
#endif
476
-
480
+ }
477
481
chnlParams ++ ;
478
482
}
479
483
@@ -535,6 +539,13 @@ void FTM_SetupInputCapture(FTM_Type *base,
535
539
{
536
540
uint32_t reg ;
537
541
542
+ /* Clear the combine bit for the channel pair */
543
+ base -> COMBINE &= ~(1U << (FTM_COMBINE_COMBINE0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * (chnlNumber >> 1 ))));
544
+ /* Clear the dual edge capture mode because it's it's higher priority */
545
+ base -> COMBINE &= ~(1U << (FTM_COMBINE_DECAPEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * (chnlNumber >> 1 ))));
546
+ /* Clear the quadrature decoder mode beacause it's higher priority */
547
+ base -> QDCTRL &= ~FTM_QDCTRL_QUADEN_MASK ;
548
+
538
549
reg = base -> CONTROLS [chnlNumber ].CnSC ;
539
550
reg &= ~(FTM_CnSC_MSA_MASK | FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK | FTM_CnSC_ELSB_MASK );
540
551
reg |= captureMode ;
@@ -562,15 +573,22 @@ void FTM_SetupOutputCompare(FTM_Type *base,
562
573
{
563
574
uint32_t reg ;
564
575
565
- /* Set output on match to the requested level */
566
- base -> CONTROLS [chnlNumber ].CnV = compareValue ;
576
+ /* Clear the combine bit for the channel pair */
577
+ base -> COMBINE &= ~(1U << (FTM_COMBINE_COMBINE0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * (chnlNumber >> 1 ))));
578
+ /* Clear the dual edge capture mode because it's it's higher priority */
579
+ base -> COMBINE &= ~(1U << (FTM_COMBINE_DECAPEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * (chnlNumber >> 1 ))));
580
+ /* Clear the quadrature decoder mode beacause it's higher priority */
581
+ base -> QDCTRL &= ~FTM_QDCTRL_QUADEN_MASK ;
567
582
568
583
reg = base -> CONTROLS [chnlNumber ].CnSC ;
569
584
reg &= ~(FTM_CnSC_MSA_MASK | FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK | FTM_CnSC_ELSB_MASK );
570
585
reg |= compareMode ;
571
586
/* Setup the channel output behaviour when a match occurs with the compare value */
572
587
base -> CONTROLS [chnlNumber ].CnSC = reg ;
573
588
589
+ /* Set output on match to the requested level */
590
+ base -> CONTROLS [chnlNumber ].CnV = compareValue ;
591
+
574
592
#if defined(FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT ) && (FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT )
575
593
/* Set to output mode */
576
594
FTM_SetPwmOutputEnable (base , chnlNumber , true);
@@ -662,6 +680,8 @@ void FTM_SetupQuadDecode(FTM_Type *base,
662
680
663
681
void FTM_SetupFault (FTM_Type * base , ftm_fault_input_t faultNumber , const ftm_fault_param_t * faultParams )
664
682
{
683
+ assert (faultParams );
684
+
665
685
uint32_t reg ;
666
686
667
687
reg = base -> FLTCTRL ;
0 commit comments