How to use interrupts on MCF51EM?

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

How to use interrupts on MCF51EM?

ソリューションへジャンプ
3,410件の閲覧回数
rodrigocorrêa
Contributor II

Hello everyone.

 

I'm programming the MCF51EM256 and I do not understand how to use the interrupts.

 

For exemple. I would like to blink a LED every second. So I should make a interrupt that runs every second;

 

How do I do this? How and I declare a interrupt and define its time on CodeWarrior 6.3?

 

I am not using processor expert.

 

Can anybody give me any tutorial or app note?

ラベル(1)
タグ(2)
0 件の賞賛
返信
1 解決策
2,774件の閲覧回数
TICS_Fiona
NXP Employee
NXP Employee

Hello Rodrigo

For how to define the vector table in your project, you may refer to the example project for EM256 Demo board, which is contained in CW 6.3 installation folder:

C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.3\(CodeWarrior_Examples)\ColdFire V1\Evaluation Board Examples\DEMOEM\EM256 Demo

This example demonstrates KBI interrupts, the LEDs, and push buttons.

If you need to blink a LED every second, please enable a timer and toggle the led in the timer interrupt subroutine, you may refer to the attached project, it is based on CW10.6, but the source code is same.  It demonstrates interrupts from the timer and uses two LED's. For details, please look into its readme.txt.

Best Regards

Fiona Kuang

Technical Information & Commercial Support

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

8 返答(返信)
2,775件の閲覧回数
TICS_Fiona
NXP Employee
NXP Employee

Hello Rodrigo

For how to define the vector table in your project, you may refer to the example project for EM256 Demo board, which is contained in CW 6.3 installation folder:

C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.3\(CodeWarrior_Examples)\ColdFire V1\Evaluation Board Examples\DEMOEM\EM256 Demo

This example demonstrates KBI interrupts, the LEDs, and push buttons.

If you need to blink a LED every second, please enable a timer and toggle the led in the timer interrupt subroutine, you may refer to the attached project, it is based on CW10.6, but the source code is same.  It demonstrates interrupts from the timer and uses two LED's. For details, please look into its readme.txt.

Best Regards

Fiona Kuang

Technical Information & Commercial Support

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

2,772件の閲覧回数
rodrigocorrêa
Contributor II

I really apreciate it, Mr. Xing Kuang.

You were completely clear in your answer.

Let me ask just one more thinkg..
How do I write a code to be executed in a time specified by the interruption? For exemple, check a variable value and take any decision according to the interruption time? 

0 件の賞賛
返信
2,772件の閲覧回数
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I made a sample code to you , please see attachment.

In the code I send you, I use Timer1, the interrupt is defined as 1s interval. The interval is decided by TPM1SC register Prescale Divisor bits. For more about how to set Timer registers, may I suggest you read the “MCF51QE128 Reference Manual”, page 341-346.

In the sample code I sent you, the interrupt subroutine is defined as:

void interrupt 66 timer()

here, “interrupt” is key word for interrupt subroutine.

  Vector number can be found in Reference Manual ColdFire Exception Vector Table, Vector Number(s) row.

the demo code is for 51QE128 but the method is exactly the same for 51EM.

Hope this helps!


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,772件の閲覧回数
rodrigocorrêa
Contributor II

Thanks for your answer. I really apreciate it;

What are the meaning of those variables you wrote in your code?

          TPM1C0SC = 0x50;

          TPM1CNTH = 0x00;

          TPM1SC = 0x0E;

How does it work? Why do we need to attribute these values like you've done? Shoudn't you call the interruption in the main program, like we do with functions?

2,772件の閲覧回数
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I comment the code as below. setting these registers is because we need enable TPM channel 0 interrupt, define TPM clock source, and "when" to trigger the interrupt.

TPM1C0SC = 0x50; //enable channel 0 interrupt, output compare mode

TPM1CNTH = 0x00; //this is TPM counter. 0x00 is the default value, you can remove this line of code.

TPM1SC = 0x0E; //TPM clock source is bus rate clock, TPM clock source is divided by 64

for more information about these registers, see related chip user manual.

once you finishing these configuration. void interrupt 66 timer() will be called automatically.


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,772件の閲覧回数
rodrigocorrêa
Contributor II

Thanks a Lot, Mrs. ZhangJennie!
I would like to ask just one more thing (if you allow me..)

Where Exactly do you set the time of the interruption?
For Exemple, 1s, 10s, 1ms...?

0 件の賞賛
返信
2,772件の閲覧回数
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

we can set TPM1SC and TPM1CNT to get interrupt time.

for example, you have 4.194Mhz bus clock.

1. to get 1s interrupt, we can set:

TPM1SC = 0x0E; //TPM clock source is bus rate clock, TPM clock source is divided by 64

TPM1C0V=0xfffe;  //65535

thus we can get 4.194M/64/65535 = 1hz  TPM clock

2. to get 1ms interrupt, we can set

TPM1SC = 0x08; //TPM clock source is bus rate clock, TPM clock source is divided by 1

TPM1C0V=0x1061;  //4193

thus we can get 4.194M/1/4193 = 1khz  TPM clock

with this method you can set multi interrupt time value.


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,772件の閲覧回数
rodrigocorrêa
Contributor II

Thank you very very much!!!

0 件の賞賛
返信