Kinetis FTM: Control triac with zero detection

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis FTM: Control triac with zero detection

Jump to solution
1,976 Views
arnogir
Senior Contributor II

Hello

I'm using a Kinetis K60.

I need to command a Triac with a specific delay after the Zero detection to adjust output power:

triac.jpg

To do this, I have a hardware which generate a pulse when signal is 0.

Then from this time, I must generate a pulse a (configurable) time after.

My first Idea was:

ZeroDetection pulse connected to an GPIO which generate an interrupt on the edge. In this interrupt, I get the FTM counter and Set CnV and Cn+1V (Combine mode) to generate a pulse of certain time in a controlled delay:

CnV = Current FTM + Delay

Cn+1V = Current FTM + Delay + Pulse wide

Generate IT on Cn1V compare to disable Output (ElsnA, ElsnB = 0)

Bad: Delay between input rise and Get FTM counter (due to interrupt save context time)

My second Idea was:

ZeroDetection pulse is connected on CH0 of FTMx. CH0 is configured in Capture Input mode and generate an interrupt.

In this interrupt, I have the Real timer value when input was Rised.

Then I made the same operation on FTMx (CH2+CH3)

CnV = Current FTM + Delay

Cn+1V = Current FTM + Delay + Pulse wide

Generate IT on Cn1V compare to disable Output (ElsnA, ElsnB = 0)

But this system require software operation. (Input compare IT + calcul to set CnV and  Cn1V and then in Cn1V IT, disable output..)

Are they a way to generate a pulse (with configurable wide) a certain time (configurable) after an input rise without any software intervention (except in initialization time)?

Thank

Regards

:smileyhappy:

0 Kudos
Reply
1 Solution
1,429 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,Arno,

If your zero-crossing circuit can generate two rising edges in one AC cycle, no problem to use FTM hardware triggering solution. For the K60, the FTM hardware triggering pins are predefined.  Pls refer to section 3.8.2.6 FTM Hardware Triggers in reference manual of K60. I copy it here:

assume that you use FTM0 module, the only FTM0 hardware triggering pin is FTM0_FLT0 pin, which is multiplexed with PTB3 or PTD6, in other words, if you use the solution, the zero-crossing signal has to be connected to PTB3 or PTD6.

BR

XiangJun Rong

3.8.2.6 FTM Hardware Triggers

The FTM synchronization hardware triggers are connected in the chip as follows:

FTM0 hardware trigger 0 = CMP0 Output or FTM1 Match (when enabled in the

FTM1 External Trigger (EXTTRIG) register)

• FTM0 hardware trigger 1 = PDB channel 1 Trigger Output or FTM2 Match (when

enabled in the FTM2 External Trigger (EXTTRIG) register)

• FTM0 hardware trigger 2 = FTM0_FLT0 pin

• FTM1 hardware trigger 0 = CMP0 Output

• FTM1 hardware trigger 1 = CMP1 Output

• FTM1 hardware trigger 2 = FTM1_FLT0 pin

• FTM2 hardware trigger 0 = CMP0 Output

• FTM2 hardware trigger 1 = CMP2 Output

• FTM2 hardware trigger 2 = FTM2_FLT0 pin

For the triggers with more than one option, the SOPT4 register in the SIM module

controls the selection.

View solution in original post

0 Kudos
Reply
10 Replies
1,429 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Arno,

I do not know if you use tri-ac to control a universal motor or heater based on power resistor, but I think the an4609.pdf is very helpful, the an4609 describes how to control a universal motor with tri-ac as power device with low cost solution, if you control a heater based on power resistor with ac line, it is also helpful, the mechanism is the same.

The application note an4609 connects the zero-crossing signal to GPIO pin, the GPIO generates an interrupt, in the ISR of GPIO, launch a PIT timer which can control the firing angle. In the ISR of PIT, set up the reload register of PIT to a new value and set/clear another GPIO which can control of the width of the firing angle signal directly.

I think it is okay to use the FTM to generate the tri-ac gate signal rather than GPIO pin controlled by PIT as the application note.

As a simplest solution, as you know that the FTM supports hardware triggering mode, in this way, you can connect the zero-crossing signal to FTM hardware triggering pin, if you set up the FTM in combined mode( both the rising/falling edge of the FTM signal can be controlled), in other words, you can control both the delay(firing angle) and the width of the tri-ac gate triggering signal by FTM module only.

This is the website of  an4608.pdf.

http://tinyurl.com/llx697e

Hope it can help you.

B R

XiangJun Rong

0 Kudos
Reply
1,429 Views
arnogir
Senior Contributor II

Hello,

@Bob: I not fully understand your mind.

@xiangjun:

I think it is okay to use the FTM to generate the tri-ac gate signal rather than GPIO pin controlled by PIT as the application note.

As a simplest solution, as you know that the FTM supports hardware triggering mode, in this way, you can connect the zero-crossing signal to FTM hardware triggering pin, if you set up the FTM in combined mode( both the rising/falling edge of the FTM signal can be controlled), in other words, you can control both the delay(firing angle) and the width of the tri-ac gate triggering signal by FTM module only.

I do not know if I understand your idea.

I feel that you tell me that it is possible to trigger the start of the counter on each edge of an input, and then to generate a pulse with combine mode.

I do not know technically how to configure the FTM for it.

About my idea of my first post, the problem I encounter is that the registrer values are really set only when FTM counter loop back to 0. Or I must stop the FTM (Clk = 0), updates register and restart.

If you think they can do everything in a simpler way, can you tell me briefly registers values of your idea?


:smileyhappy:

0 Kudos
Reply
1,429 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Arno,

I have checked the FTM module, I know that ONLY RISING edge of hardware triggering signal can trigger FTM to start counting, the falling edge of hardware triggering signal can not trigger FTM to start counting. I suppose you hope that the tri-ac works in both positive and negative cycles, in other words, one AC cycle can trigger FTM twice, so the FTM hardware triggering solution is NOT feasible.

Regarding your two solution, I think both solution are okay, both GPIO interrupt source and capture interrupt source supports rising/falling edge to trigger interrupt. In the ISR, you can initialize the FTM_CNT to zero by writting the FTM_CNT register directly, if you set up the FTM channel in COMBINED mode, you can set up the FTM_CnV register and FTM_Cn+1V register to control both the delay and width of the tri-ac gate signal, you can set up the FTM_MOD as maximum so that the PWM signal only generate one cycle.

The solution based on an4608 is okay.

BR

XiangJun Rong

0 Kudos
Reply
1,429 Views
arnogir
Senior Contributor II

Hi

Yes I want work in both positive and negative cycle.

But it is possible to obtain a positive edge on each by design an hardware zero crossing detection which provide positive edge on both. This is not a problem for me.

So you seem say that it is possible to triggering start counter by  directly by hardware, without software. How do  it?

0 Kudos
Reply
1,429 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Arno,

It is dependent on the the waveform of the zero-crossing signal, if the zero-crossing signal can provide both rising edge in one AC cycle, of course, the FTM hardware triggering solution is okay. In detail, if the zero-crossing signal can generate a rising edge when the AC voltage crosses zero from negative to positive, while the zero-crossing signal can generate another rising edge when the AC voltage crosses zero from positive to negative voltage, the hardware triggering solution is okay. Can you provide two edge for the zero-crossing signal in on e AC cycle?

Hope it can help you.

BR

Xiangjun Rong

0 Kudos
Reply
1,429 Views
arnogir
Senior Contributor II

Yes I will study an hardware solution to generate a rising edge in both zero crossing (Positive to negative and Negative to positive alternance).

I havn't yet looking for the solution, but I think this will be possible without any problem.

But today my problem is to know how configure the FTM to trig FTM counter without any Software intervention?? (Currently done in a keyboard interrupt from a generic GPIO PTA6)

0 Kudos
Reply
1,430 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,Arno,

If your zero-crossing circuit can generate two rising edges in one AC cycle, no problem to use FTM hardware triggering solution. For the K60, the FTM hardware triggering pins are predefined.  Pls refer to section 3.8.2.6 FTM Hardware Triggers in reference manual of K60. I copy it here:

assume that you use FTM0 module, the only FTM0 hardware triggering pin is FTM0_FLT0 pin, which is multiplexed with PTB3 or PTD6, in other words, if you use the solution, the zero-crossing signal has to be connected to PTB3 or PTD6.

BR

XiangJun Rong

3.8.2.6 FTM Hardware Triggers

The FTM synchronization hardware triggers are connected in the chip as follows:

FTM0 hardware trigger 0 = CMP0 Output or FTM1 Match (when enabled in the

FTM1 External Trigger (EXTTRIG) register)

• FTM0 hardware trigger 1 = PDB channel 1 Trigger Output or FTM2 Match (when

enabled in the FTM2 External Trigger (EXTTRIG) register)

• FTM0 hardware trigger 2 = FTM0_FLT0 pin

• FTM1 hardware trigger 0 = CMP0 Output

• FTM1 hardware trigger 1 = CMP1 Output

• FTM1 hardware trigger 2 = FTM1_FLT0 pin

• FTM2 hardware trigger 0 = CMP0 Output

• FTM2 hardware trigger 1 = CMP2 Output

• FTM2 hardware trigger 2 = FTM2_FLT0 pin

For the triggers with more than one option, the SOPT4 register in the SIM module

controls the selection.

0 Kudos
Reply
1,429 Views
arnogir
Senior Contributor II

Ok,

Then I can configure trigger by FTMx_FTL0 (trigger2)

So I have to configure FTMx_SYNC_TRIG2 = 1.

And so after?

So currently, bellow is the code I have:

At init time:

MODE_WPDIS + MODE_INIT set to 1

MODE_FTMEN set to 1

SC =0 (To switch off all the FTM during intitializing)

CNTIN = 1

MOD = 65535

C0SC = 0

COMBINE_CONBINE0 + COMBINE_SYNCEN0 set to 1   (I'm using Channel 0 + 1 to generate a pulse)

C0V = My specific value "Set pulse time"

C1V= My specific value "Clear pulse time"

In a GPIO keyboard interrupt on which Zero Crossing signal is connected

SC = 0 (To can change all value without wait FTM counter overflow to refresh register value due to synchronization)

C0SC |= ELSB_MASK ( to configure a pin set on C0V value match and a pin clear on C1V value match)

CNT = 0 ( To reset FTM counter)

SC = TOIE + CLKS(1) + PS(My div)

In TOIE interrupt à stop the Timer (SC = 0) but this can never occurs because Timer Overflow time is bigger than my Input Keyboard interrupt (Zero crossing).

The question is how do to make the work of the Keyboard interrupt directly by hardware (without software intervention) by using FTM_FLT0?

I think:

At init time, configure C0SC_ELSB to 1.

Add FTMx_SYNC_TRIG2 = 1

Configure SC = TOIE + CLKS(1) + PS(My div)

Then counter will restart to 0  at each FTMx_FLT0 rising up.

I have true?

0 Kudos
Reply
1,429 Views
arnogir
Senior Contributor II

Hello

Thank for your help.

Now it work correctly without any software except in initialization time Smiley Happy

Bellow, the init code:

/* Set up mode register */ FTMx_MODE = FTM_MODE_WPDIS_MASK | FTM_MODE_INIT_MASK ; /* FTMEN bit is write protected. Can be written only when WPDIS = 1 */  FTMx_MODE |= FTM_MODE_FTMEN_MASK;  /* Clear status and control register */ FTMx_SC = (uint32_t)0x00UL;  /* Clear counter initial register */ FTMx_CNTIN = (uint32_t)0x01UL; /* Set to 1. By this way, if CnV And Cn1V = 0, ouput have no signal  /* Set up modulo register */ FTMx_MOD = (uint32_t)(MODULO-1);  /* Set up channel status and control register */ FTMx_CnV = 0; FTMx_Cn1V = 0; FTMx_CnSC |= FTM_CnSC_ELSB_MASK; /* To generate positive pulse */ /* Set FTM_COMBINE_COMBINE{0,1,2,3}_MASK and FTM_COMBINE_SYNCEN{0,1,2,3}_MASK */ FTMx_COMBINE |= ((FTM_COMBINE_COMBINE0_MASK + FTM_COMBINE_SYNCEN0_MASK) << (i*8)); /* To trig with Hardware Pin */ FTMx_SYNCONF = FTM_SYNCONF_HWTRIGMODE_MASK | FTM_SYNCONF_SYNCMODE_MASK | FTM_SYNCONF_HWRSTCNT_MASK | FTM_SYNCONF_HWWRBUF_MASK;  FTMx_SYNC = FTM_SYNC_TRIG2_MASK | FTM_SYNC_CNTMIN_MASK; /* FTM run normally in debbeguer */ //debug AG FTMx_CONF |= FTM_CONF_BDMMODE(0x03); /* Start FTM */ FTMx_SC= (uint32_t)(FTM_SC_TOIE_MASK | FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALER));

Thank

1,429 Views
bobpaddock
Senior Contributor III

Setup up output compare with auto-reload to drive the output.

Use the input to resynchronize output compare to the line, rather than fixed time from each zero crossing.

In  the real world there will be extra zeros and missing zeros due to line noise; refrigerator coming on, lightning, person in next apartment arc welding who knows.

So only accept zero crossing inputs when you expect to get them.  In the end it ends up acting like a PLL to clean up the line signal.

0 Kudos
Reply