PIT questions (yes, I know these come up a lot :))

cancel
Showing results for 
Search instead for 
Did you mean: 

PIT questions (yes, I know these come up a lot :))

3,843 Views
Eggmania
Contributor I
Hello-
 
I was trying to get PIT0 working on the M52233Demo board.  Searching through the forums I found the main piece of advice was to make sure that the desired interrupts were unmasked.  I've done this and it doesn't work yet.  If I trigger a forced interrupt in software with MCF_INTC_INTFRCH then I can get into my ISR so I know I have it set up correctly at that end.  The code I'm using is as follows:
 
 MCF_PIT0_PCSR   = 0b0000111100011001; 
/* Sets up PIT0 as max prescale, interrupts inabled, rollover to 0xFFFF, timer enabled */ 

 MCF_INTC_ICR55(0x00) = 0b00111111;
/* Set up timer priority as 7/7 */
 
 MCF_INTC_IMRH(0x00)  = 0x0000;
 MCF_INTC_IMRL(0x00)  = 0x0000;
/* Unmask all interrupts */   
 
Have I left something out?
 
I'm also a little confused by some of these register-accessing macros.  It looks like the macros use the passed parameter as an offset from the base value of the register.  When would I ever use this?  For example, IMRH/L by themselves already reach all 63 interrupt sources, so why would I ever need to pass a nonzero value to the macro? 
 
Likewise with the control register ICRnx.  'X' already runs over the available 63 sources, so why would I ever use different values of 'N'? 
Labels (1)
0 Kudos
10 Replies

409 Views
ColdFireHot
Contributor I
OK, here is what I had to do....not very obvious to me.
 
1) Create a project using the "C" Stationary for the M52233DEMO.
2) I modified "main.c" and "Int_handlers.c" as follows:
 
/*
 * File:  main.c
 * Purpose:  sample program
 *
 */
#include <stdio.h>
#include "mcf52233.h"
extern long int rti_count;
#define EVER ;;
int main()
{
  long int localCnt=0;
  long int lastx = 0;
  
  // Lets get the party started
  mcf5xxx_irq_enable();
 
 PIT_Timer_Init(0,3000);
 
 printf("Hello World in C\n\r");
 
 fflush(stdout);
 
 for(EVER)
 {
   if (++localCnt > 10000)
   {
      long int x = rti_count;
      printf("%ld\r", (x-lastx));
        fflush(stdout);
      localCnt = 0;
      lastx = x;
   }
 };
...
void rti_6th_event()
{
//   fec_mii_blk_test();
}
... 
3) Set the project build to "M52233DEMO UART Debug" and compiled.
4) I had to "#include "common.h"" in the file "mii.h" - compiler complained about uint8 and uint16 etc.
5) Performed a debug run.
 
With Hyperterm running I saw the hello world message and the number of interrupts between prints.
 
This took about 2 hours to finally figure out that without including the mcf52233.h header the function
declaration for PIT_Timer_Init() was not being used for setting up the stack!  No error to indicate why the values I was passing in were not being used.
 
Any who....hope this helps.
 
Mark
 
0 Kudos

409 Views
Eggmania
Contributor I
Thanks to everybody who answered.  It turns out my initial code was correct, but my prescaler values were simply way too high.  It took so long to trip the interrupt that it looked like it was not working.  After I followed the excellent advice to watch what was happening to the counter as the debugger was running this became immediately apparent.
0 Kudos

409 Views
Bartington
Contributor I
Sorry my apology
I must have been tired that day
I was wrong you have to set 0 for masking an Interrupt and reload only if the Prescaler is not the Max Value but value taken from the PMR.
Enabling General Interrupt is done by modifying the SR register.
Thanks a lot for the Correction.
 
Happy new year everybody.
 
 
0 Kudos

409 Views
Bartington
Contributor I
Hello
i'll try to help assuming that the PIT module of the 52233 is the same as the 52223 and 5213 (RM stand for reference manual, check the PIT part)
 
PSCR:
- if you're only looking for 1 interrupt or reloading manually the counter then i'll understand that the Reload bit is off otherwise i'll suggest that you switch it on
 
Interrupts:
- i assume that you don't want any interrupt as you hanven't cleared the PIF bit in the PSCR by writing one to it and you've unmask all interrupts.
- That assumption becomes weird as you still set a level and priority for it.
 
i suggest that you look into the interrupt part;
- Setting an interrupt routine 
- Setting the pointer on this routine in the vector table.
- Masking the right interrupt by writing 1 into the relevant bit of the IMRH
- Enabling general interrupts
(check mcf5xxx.c file for available functions, it should be in the support files of your project folder)
 
I also Suggest that you use ICR0 and IMR0 as it might be the only Bank available.
If I'm not mistaken Banks allows you to preset configurations and swap between them as needed.
 
Good Luck
Olivier
0 Kudos

409 Views
Eggmania
Contributor I
Thanks for your answers!
 
****
 
"Reload bit is off otherwise i'll suggest that you switch it on"
 
The manual says with a zero here that "Counter rolls over to 0xFFFF on count of 0x0000" which is fine for me.
 
"i assume that you don't want any interrupt as you haven't cleared the PIF bit in the PSCR by writing one to it..."
 
The manual says that PIF is cleared on reset, however, I added in a forced clearing and it did not make a difference.
 
"..and you've unmask all interrupts."
 
The manual says that "The IMRHn and IMRLn are each 32 bits and provide a bit map for each interrupt to allow the request to be disabled (1 = disable the request, 0 = enable the request).  The IMRn is set to all ones by reset, disabling all interrupt requests".  Your comment seems to imply that I should have used a 1 to allow the interrupt to go through.  I did try it with 1s and it made no difference, but the manual seems to say I should write all zeroes to the mask register if I want to enable all interrupts.
 
"- Enabling general interrupts"
 
Usually there is some other value that must be set elsewhere to globally activate interrupts, but I cannot find a reference to this in the interrupts chapter of the manual and I haven't seen it mentioned in the sample code that pops up in these forums.  Is there a register besides the IMRs I have to fiddle with?
 
"
- Setting an interrupt routine 
- Setting the pointer on this routine in the vector table."
 
I know I have done this part correctly, since if I use the INTFRCH to trigger an interrupt on source 55 I go into my ISRs.
 
 
0 Kudos

409 Views
mjbcswitzerland
Specialist V
Hi

You probably have seen the following forum posting with example code but I will link it here to be sure.

http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&message.id=726&query.id=10386#M7...

If you have the Demo board you will be able to debug quite easily.

Using the BDM write the values and then watch to see whether the timer is really counting - then see that its interrupt flag is being set, then see that the interrupt is getting through to the interrupt controller. Somewhere along teh line you may find out where it is not getting through.

To generate a 50ms TICK interrupt the following write are required and thsi can be entered straight into the registers in the debugger.

PIT_PCSR = 0xc36;
PIT_PMR = 0x16e;
IC_ICR_0_55 = 0x20; (priority 0, level 4)
IC_IMRH = 0xff7ffffe; (PIT 0 interrup enabled)
PIT_PCSR = 0x0c3f (enable timer to run)
Now the interrupt will arrive very quickly.

Regards

Mark Butcher
www.uTasker.com
0 Kudos

409 Views
Eggmania
Contributor I
"If you have the Demo board you will be able to debug quite easily.

Using the BDM..."
 
Well, a problem I have here is that we don't have a BDM.  We are using the USB cable that came with the dem board to program the device.  However, it has come to my attention that the USB cable only allows writing code to RAM and not to the flash ROM.  Is it true that I cannot write to the flash unless I have something in addition to a USB cable?  And, can I expect interrupts to work if I am running code from RAM only and not from ROM?  We were hoping to put off the purchase of a programmer as they are more than we are comfortable spending, but if we can't expect code in RAM to work properly then there may be no choice but to rush order a programmer.
0 Kudos

409 Views
mjbcswitzerland
Specialist V
Yes, as others are saying, you have everything that you need with the Demo board to debug in SRAM (up to 32k), to delete, program FLASH and debug from FLASH (with limit to number of HW breakpoints).

In fact this is a strength of the Freescale solution which is appreciated by a lot of people - it also results in the Freescale chips being prefered in some projects simply due to the fact that the start-up package is complete.

Please see the following tutorial. It contains a step-for-step guide to programming the Demo board from CW6.0 and also using CF Flasher 3.3.1 (a tool available on the Freescale web site) - pages 7 and 8.

M5223X Tutorial

Regards

Mark
0 Kudos

409 Views
peg
Senior Contributor IV
Hi,
 
Is this the board you have?
 
 
It has a built in BDM. All the stuff in the white outline around the USB connector IS a BDM.
 
There should be very little you cannot do.
 
Regards
Peg
 
0 Kudos

409 Views
ColdFireHot
Contributor I

Hi,

The BDM is part of the M52233DEMO board.  Unless you have some other board you should be able to program and test from CodeWarrior 6.3.  I have the above mentioned board connected now and it works for me.  I created the stationary program and executed from RAM both the Console and Uart compiles.

What is your clock frequency?  With a big divisor you may not get an interrupt for a long time if your PLL is not setup properly.

Mark

 

0 Kudos