Create an PIT Interrupt

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Create an PIT Interrupt

ソリューションへジャンプ
2,177件の閲覧回数
pascalschröer
Contributor V

Hi, I hope anyone can help me....

 

First of all my facts:

I'm using CW V.1.4 (without PEX), to program a MK20DX128 (50MHz)

 

I would like to know, how to create an Interrupt request for the PIT0 Module?!

I tried it like this:

 

Add the ISR Vectro table in kinetis.c with the PIT0_isr at position 46!

Add the prototype of PIT0_isr in kinetis.h

 

Add the PIT0_init() where I enabled the Timer, the Interrupt function

and all Interrupts with the help of:

 

#define EnableInterrupts __asm(" CPSIE i");

 

Well in my opinion it should work... but it doesn't! Where is my fault?

Because there isn't any problem while compilation but although the

PIT Overflow Flag is set, the program doesn't jump into the isr -.-

 

Thanks a lot and please excuse my poor pronunciation!

 

Pascal

Original Attachment has been moved to: CLOCK.c.zip

ラベル(1)
タグ(3)
0 件の賞賛
1 解決策
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Hi

You don't seem to be enabling the PIT0 interrupt to the Cortex M4 core.

To enable the PIT0 interrupt in the K20 (50MHz) you need

IRQ0_31_SER = 0x80000000;

IRQ28_31_PRIORITY = 0xP00000000; where P is the interrupt priority

These registers are in the Cortex M4 NVIC.

Regards

Mark

元の投稿で解決策を見る

0 件の賞賛
16 返答(返信)
1,290件の閲覧回数
Wlodek_D_
Senior Contributor II

Hello,

Thank you for your post, however please consider moving it to the right community place (e.g. Kinetis Microcontrollers ) to get it visible for active members.

For details please see general advice Where to post a Discussion?

Thank you for using Freescale Community.

0 件の賞賛
1,291件の閲覧回数
mjbcswitzerland
Specialist V

Hi

You don't seem to be enabling the PIT0 interrupt to the Cortex M4 core.

To enable the PIT0 interrupt in the K20 (50MHz) you need

IRQ0_31_SER = 0x80000000;

IRQ28_31_PRIORITY = 0xP00000000; where P is the interrupt priority

These registers are in the Cortex M4 NVIC.

Regards

Mark

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

Thank's a lot :smileyhappy:  :smileycheck:

If you have got some time, it would be very nice if you could look at my second question about the Clock generation and the use of PLL... Because my Interrupt works now, but it's just too fast...

Regards

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Hi

It looks like your code is setting an 8MHz crystal input to 48MHz core speed (8/2*24).

The bus clock seems to be the same as the core clock (48MHz) so your PIT should be firing every (0x000752FF + 1) bus clocks. That is every 480000/48000000 s - or every 10ms.

What rate is it firing at and what rate were you expecting?

Regards

Mark

P.S. Supposedly you noticed my mistake in the last post - I set the bits for PIT1 and not PIT0.

PIT0 is

IRQ0_31_SER = 0x40000000;

IRQ28_31_PRIORITY = 0x00P00000; where P is the interrupt priority

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

P.S. Supposedly you noticed my mistake in the last post - I set the bits for PIT1 and not PIT0.

PIT0 is

IRQ0_31_SER = 0x40000000;

IRQ28_31_PRIORITY = 0x00P00000; where P is the interrupt priority

Yes I noticed that, but it doesn't matter because with the help of these Registers, I could solve the problem :smileywink:

Thank you for answering my other question about the clock peroid...I calculated the same. But that doesen't work when I calculate a time

which I can measure...for example 10s

Well, I tried it like this:

1 / 48MHz = 20.83ns => 10s * 20.83ns = 480000000 cycles

So it should be like this:

PIT_LDVAL0 = PIT_LDVAL_TSV(0x1C9C3801);  //+1 cycle

Or is there a fault? Because my Interrupt is firing every 5 Seconds -.-

Thanks

P.S. In my other post about the Clock and the WDOG is the same fault...

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

The PIT value looks good so it must be that your PLL is running at 100MHz and the bus clock too, although I don't read this in your configuration code.

To run at 50MHz from an 8MHz crystal the following register settings are required (at the end of the initialisation) - please compare with yours:

MCG_C1 = 0x28

MCG_C2 = 0x1c
MCG_C5 = 0x03

MCG_C6 = 0x40

Regards

Mark

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

Hmmm

I have got exactly the same values after initialisation but the interrupt fires every 5 Seconds...

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Pascal

Do you have the correct crystal attached - is it too fast?

Which board are you using - a TWR-K20N50M or FRDM-K20D50M?

If so you can load binary to it that flashes the LED at a defined rate at µTasker Test Software and Demos - if it works (eg. LED flashes at 5Hz the USB operates) there must be a code problem - else it must be a HW issue.

Regards

Mark

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

I'm using the FRDM-K20D50M board with an external 8MHz Oszillator.

At the moment, I toggle PIN A13 and look at my oszilloscope. So I see,

that the PIN A13 toggles every 5 Seconds. I have also measured the output

frequency of the oszillator but there are 8MHz how expected.

regards

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Pascal

If you load this to your board you can measure the speed that the LED toggles at - it should be 100ms ON/100ms OFF:http://www.utasker.com/Demos/Kinetis/uTaskerFlexibleBootLoader_FRDM-K20D50M.zip

It uses 48MHz PLL and 24 MHz bus clock - with the debugger stop the program running and compare the clock registers with yours to try to find a difference that could explain something. Connecting USB will enumerate as an external hard drive if the clocks are correct (USB requires an accurate 48MHz clock).

Regards

Mark

1,290件の閲覧回数
mjbcswitzerland
Specialist V

Pascal

To be sure, I have just configured a project that configures 48MHz PLL and 48MHz bus clock and then toggles an output each time PIT0 fires (set to 10s).

This is attached as SREC so that you can load it to your FRDM-K20D50M board. This time you can also inspect the PIT0 configuration to see whether there are any differences.

PIT0_LDVAL0 is set to 0x1c9c37ff.

The green LED flashes at 2.5Hz all the time and PIT0 controls the red led. Therefore you will see that the green LED blinks for 10s and then the red LED is lit for 10s, etc.

Regards

Mark

1,290件の閲覧回数
pascalschröer
Contributor V

Thanks, I have found the problem!! MCG_C2 must be 0x2C :smileyhappy:

Now it works very well :smileywink:

Thanks for your support!

Pascal

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Pascal

I think that there needs to be someone from Freescale who can confirm this since I always use the mid-frequency range with the 8MHz crystal and have never has a problem with it.

According to the K20M50 data sheet:

- the low range setting RANGE=00 is used only for a 32kHz crystal (from 30kHz to 40kHz).

- the mid range RANGE=01 is used for a high frequency range selection (from 3MHz to 8MHz)

- the very high frequency range RANGE = 1x is used for crystals from 8MHz to 32MHz.

Since 8MHz is on the boundary between RANGE 01 and 1x there shouldn't be any difference in the two. In fact the data sheet quotes most values with an 8MHz crystal and RANGE 01 (for start-up time,supply current) so this is certainly a valid setting.

If you can influence the PIT speed (bus clock/core speed) you must have the crystal oscillating at twice the frequecy in one case, although you measured the frequency and said that you measured 8MHz. Could it have been that it was 8MHz when you measured and went to 16MHz (overtone) when you didn't - that would mean that the PIT timeout would be correct when you connect your probe to it.

At the moment I am not convinced of the finding since it doesn't match with the data sheet or experience over three years with many Kinetis devices. Perhaps you have a starnge board where the oscillator is really not stable but it would be useful if Freescale could remark on the findings as a potential problem.

Regards

Mark

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

First of all thank you to spend so much time in my problem!

I don't now what to think about it... I have measured 8MHz all the time with the help of a professional Tectronix oszilloscope,

the schematics say's that there is a 8MHz oscillator and the value on top of the oscillator say's it too...

The second point is, I have created a new project by using PEX and I saw that the PEX set the MCG_C2 register to0x2C like me!!!

Now, I really don't know what to do -.- do you know anyone from freescale who can help me?

Thanks

Pascal

0 件の賞賛
1,290件の閲覧回数
mjbcswitzerland
Specialist V

Pascal

There may be two issues here:

In MCG_C2 there are two settings that are important; the oscillator frequency range and the oscillator gain.

On a FRDM-K20D50M setting the RANGE to medium or high should be "equivalent" and I have confirmed this on my hardware

When I originally posted the value of MCG_C2 I didn't know whether you were using a FRDM or TWR board. The value 0x1c is what I use on a tower board. On the Freedom board I use 0x14 (or 0x24 since they are equivalent).

What I can't use on my FRDM board is neither 0x1c nor 0x2c since the oscillator will not start oscillating if I set the high gain mode. On your board it is oscillating but this could be critical.

Whether you need high gain mode or low gain oscillator mode depends on the hardware - if there is a feedback resistor and loading capacitors the high gain mode is necessary to start the oscillator.

If the crystal has no loading the high gain mode will often fail to start the oscillator and the low gain mode is required.

It seems that the FRDM boards are not always mounted with the same components and so you need to check the board in question.

If you search the forum you will find a number of posts concerning this "problem" - for example Re: Using external reference

I have found that setting the "incorrect" gain setting for a certain HW may work, may never work, or may work when the crystal is touched with a probe.

Therefore I don't think that the issue involves the range setting but more the gain setting. I would recommend you try combinations of the gain setting and the two range settings. You should find that a certain gain setting is then stable for both range settings and then that is the one best suited to your HW.

As mentioned above I can't use high gain on my board - in fact I have all freedom boards and most of them won't start with the high gain setting (since they don't have crystal loading capacitors) so I certainly recomment the low gain setting as first one to try.

Regards

Mark

0 件の賞賛
1,290件の閲覧回数
pascalschröer
Contributor V

So I tried it! You are right, it depends on the gain register-value. If I use the low power operation of the oscillator

I can take the high frequency range and it works like it should! So I would say that the best kind of initialisation is

MCG_C2 = 0x14, for my device :smileyhappy:

regards

Pascal

0 件の賞賛