I am using FTM combine mode to generate some sort of pulses that will be sent to triac. (FTM0 channel 0 and 1)
I want to connect the zero cross signal to FTM hardware trigger pin (PTB3). Can I achieve FTM register reloading on every zero cross detection by using hardware synchronization?
For combine mode signal generation I used FRDMkv1 ftm_combine_pwm example with little modification. Also tried to setup hardware synchronization using PTB3 but that seems to not reacting at all. When comparing signal that should simulate zero cross detection and firing angle signal (that I am creating using combined mode), firing angle signal is "moving". Frequency doesn't seem that is changing, but pulse time, and angle of pulse change.
I want to have ON period of this signal that will control triac always with almost the same difference from zero cross detection. Is combine pwm mode with hardware synchronization way to achieve this?
Is there example code of FTM hardware synchronization?
Thanks.
Hi Felipe Garcia,
thanks for the document. I tried changing some parts of the code, but the code still doesn't work. Regarding the init for CMP0_OUT, do I need to do anything else to initialize PTC5 as CMP0_OUT?
PORT_SetPinMux(PORTC, 5U, kPORT_MuxAlt6);
SIM->SOPT4 = ((SIM->SOPT4 &
/* Mask bits to zero which are setting */
(~(SIM_SOPT4_FTM0TRG2SRC_MASK)))
/* FlexTimer 0 Hardware Trigger 2 Source Select: CMP0 output drives FTM0 hardware trigger 2. */
| SIM_SOPT4_FTM0TRG2SRC(0x00u));
Regarding FTM counter synchronization my expectation is that on every trigger counter will reset, and my pulse is always the same distance from zero crossing pulse.
No matter what I try my signals stays pretty much the same.
Hi Azema Talam,
Sorry for the delay reply and thanks for sharing the update. Do you have any more questions I can help you with?
Best regards,
Felipe
Hi Azema Talam,
Please check the following document where it is shown how to implement FTM hardware and software synchronization. The application note includes some code examples you could try.
PWM Synchronization Using Kinetis Flextimers
I hope this helps.
Have a great day,
Felipe
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
So I looked again at the documentation and it seems that TRIG2 – is not connected to the FTM1_FLT0 pin.
I tried using PTC5 - CMP0_OUT but it still doesn't work.
This is my code.
CLOCK_EnableClock(kCLOCK_PortC);
CLOCK_EnableClock(kCLOCK_Ftm0);
/* PORTC5 (pin 50) is configured as CMP0_OUT */
PORT_SetPinMux(PORTC, 5U, kPORT_MuxAlt6);
SIM->SOPT4 = ((SIM->SOPT4 &
/* Mask bits to zero which are setting */
(~(SIM_SOPT4_FTM0TRG2SRC_MASK)))
/* FlexTimer 0 Hardware Trigger 2 Source Select: CMP0 output drives FTM0 hardware trigger 2. */
| SIM_SOPT4_FTM0TRG2SRC(0x00u));
FTM0->FMS = 0;
FTM0->MODE = FTM_MODE_WPDIS(1) | FTM_MODE_INIT(1);
FTM0->MODE |= FTM_MODE_FTMEN(1);
FTM0->MODE |= FTM_MODE_PWMSYNC(0);
FTM0->COMBINE |= FTM_COMBINE_COMBINE0(1) | FTM_COMBINE_COMP0(1);
FTM0->COMBINE |= FTM_COMBINE_SYNCEN0(1);
FTM0->CONTROLS[0].CnSC=FTM_CnSC_ELSB_MASK;
FTM0->CONTROLS[1].CnSC=FTM_CnSC_ELSB_MASK;
FTM0->SC = 7;
FTM0->MOD = 4883;
FTM0->CNTIN = 1;
FTM0->CONTROLS[0].CnV=FTM_CnV_VAL(1900);
FTM0->CONTROLS[1].CnV=FTM_CnV_VAL(2000);
// FTM0->DEADTIME = FTM_DEADTIME_DTPS(3) | FTM_DEADTIME_DTVAL(7);
FTM0->SYNCONF = FTM_SYNCONF_SYNCMODE(1) |FTM_SYNCONF_HWTRIGMODE(1) | FTM_SYNCONF_HWWRBUF(1) | FTM_SYNCONF_HWRSTCNT(1) | FTM_SYNCONF_CNTINC(1) ;
FTM0->SYNC |= FTM_SYNC_TRIG2(1)| FTM_SYNC_REINIT(1) ;
FTM0->SC|=FTM_SC_CLKS(1);