coldfire V1 MCF51JM128 speed problems

cancel
Showing results for 
Search instead for 
Did you mean: 

coldfire V1 MCF51JM128 speed problems

538 Views
Contributor I

Hi I am running the MCF51JM128 ic in the Firebird32 dev board, and I am attempting some speed benchmarking. I have the PLL set to 48Mhz, I am using codewarrior V10 and timing using an interrupt with a counter counting microseconds.
I am trying to time how long it takes to toggle a digital IO 10000 times in a for loop and I am getting very slow results i.e. 28000uS (my Arduino running at 16Mhz does it in 6200uS). This is after setting the all counters to volatile and turning on optimisation which did help quite a lot.

Even just with an empty for loop it takes 17000uS to run.
I have done a step by step debug and it seems the program is spending a lot of time in the interrupt handler when it doesn't need to be (not my interrupt service routine).

Has anyone experienced any similar problems or have some ideas of what I am doing wrong?
Cheers
Nick Schulze
www.HowNotToEngineer.com

Labels (1)
0 Kudos
3 Replies

37 Views
Specialist I

You are talking about some abstract code that runs slower than you expect. Where's your code or disassembler listings? Also you should provide PLL initialization and specify external clock rate if used.

0 Kudos

37 Views
Contributor I

Right sorry about that..

Extrenal clock source of 12MHz.

 

INIT Routine

void Firebird_init(void){ FB_PLL_init();  //SET BUS CLOCK TO 24MHZ FB_TPM_init();  //TIMERS  SOPT1 = 0x20;  //STOP MODE ENABLE  //GATE BUS CLOCK TO ALL PERIPHERALS SCGC1 = 0xFF;     SCGC2 = 0xEF; SCGC3 = 0xFF;  EnableInterrupts;
        LCD_init();
 }

 

PLL Setup

void FB_PLL_init(void){ //SETS THE FIREBIRDS BUS CLOCK TO 24MHZ USING PLL  //FOLLOWING MCG MODE STATE DIAGRAM IN DATASHEET  //PLLSPEED = 12/8*32 = 48MHZ //BUSCLOCK = PLLSPEED/2 = 24MHZ  //FLL BYPASSED EXTERNAL MODE (FBE) MCGC2 = 0x36;             while (!MCGSC_OSCINIT){}   //WAIT FOR INIT CYCLE TO COMPLETE      MCGC1 = 0xB8;          while (!MCGSC_IREFST){}         //WAIT WHILE REF CLOCK SOURCE SYNCS while (MCGSC_CLKST != 0x02){}   //WAIT FOR EXTERNAL REF TO SYNC    //BYPASSED LOW POWER EXTERNAL (BLPE) MCGC2 = 0x3E;     MCGC1 = 0x98;   MCGC3 = 0x48;     //MULTIPLY BY 32 while (!MCGSC_PLLST){}   //WAIT FOR PLL SOURCE TO SYNC    //PLL BYPASSED EXTERNAL (PBE) MCGC2 = 0x36;    while (!MCGSC_LOCK){}    //WAIT FOR PLL LOCK    //PLL ENGAGED EXTERNAL (PEE) MCGC1 = 0x18;                   //DIVIDE BY 8                                        while (MCGSC_CLKST != 0x03){}   //WAIT FOR PLL OUTPUT TO SYNC   }

 

TIMER setup

void FB_TPM_init(void){   //TIMER 1 FOR PWM PINS //USE THE PWM and PWM_OFF MACROS TO USE THE PWM PINS TPM1SC = 0x0A;  //SELECT BUS CLOCK 16X CLOCK DIVIDER TPM1MOD = 256;  //256 COUNT PERIOD  //TIMER 2 FOR TIMING AND DELAYS TPM2SC =  0x48; //ENABLE INTERRUPTS, SELECT BUS CLOCK, 1X CLOCK DIVIDER  TPM2MOD = 24;  //COUNT UP TO 24 = 1us TPM2C0SC = 0x50; //SELECT CHANNEL 2 AS OUTPUT COMPARE, UNLINK OUTPUT PINS TPM2C0V = 0x0000; //RESET TIMER VALUE}

 

TIMER ISR

volatile int micros = 0;void interrupt 0x4E TPM2_ISR(void){  //DELAY COUNTER INCREMENTS EVERY MILLISECOND if(delay_called){  delay_count++; }  //DEBOUNCE FOR 100 MILLISECONDS if(debouncing){  debounce_count++;  if(debounce_count > 100000){   debouncing = 0;   debounce_count = 0;  } }  micros++;  //RESET INTERRUPT FLAG TPM2C0SC; TPM2C0SC_CH0F = 0;}

 

MICROS function

int _micros(void){ return micros;}

 

MAIN

#include "Firebird.h"int start = 0;int dif = 0;volatile int i = 0;byte once = 0;void main(void) {  Firebird_init();  LCD_clear();   for(;;) { if(once){  start = _micros(); // START  HERE 
                //CODE THAT I AM TESTING   while(i<10000){   i++;   PTED ^= 0x40;  }   dif = _micros()- start; //END HERE    LCD_print(dtos(dif,0));  once = 0; }    __RESET_WATCHDOG();   } }

 

When I do the step by step debug, it keeps jumping to the exceptions.h file, each jump to the exceptions.h does not correspond to a call of my TIMER ISR. The ISR does get called when it should, but the code spends minimal time here as all it does is increment micros;

0 Kudos

37 Views
Contributor I

First sorry for my english :smileytongue: , but running a 1Mhz interrupt may be too overwhelming for a microcontroller running at 24Mhz.  And Coldfire may have a lot of registers to save in the stack.  Disasemble the ISR routine and you'll se how many cycles are lost saving registers, processing an seting values.

 

In my case, I'm using a 24MHz MCF51JM28 to write a 320x240 TFT LCD and have achieved 5.5Mbytes x second, almost 35 FPS filling a screen with solid color (16bits), so this things are fast. The trick is to use RGPIO (Rapid GPIO) , you can toggle an output at 6Mhz!.

 

I hope it can helps.

 

Polo

0 Kudos