Hello,
I'm new to code warrior and I really liked this compiler and the power, its features offers.. I have come across adding watchpoints to find the number of clock cycles that my code will undergo between two segments. This way I will be abe to calculate the executing time of my code.
I want to know that is it accurate enough and can I trust it as the correct executing time of my code??
Please asnwer for both 'Full Chip simulation' and 'P&E Multilink Cyclone Pro'. If using fullchip simulation I can find the correct time them I think I need not use P&E and connect my processor everytime before finding the time. I use the MC9s12xd256 processor..
解決済! 解決策の投稿を見る。
You saw this circuit previously, no need to zoom it. Yes, CPU will run at 4MHz (until you select PLL clock) and bus clock will be 2MHz.Bus clock is more important than some internal CPU frequency.
To check what freq. your CPU is operating at, you may clear NECLK bit in ECLKCTL register and probe bus clock on ECLK pin. You can also check oscilator or PLL clock by clearing NCLK2X bit and and probing ECLK2X pin.
For full chip simulation answer is clear - use bus cycle counter. It is very close to real timing. Error is probably mainly due to misaligned word reads from flash and simultaneous accesses to same addresses from XGATE and CPU12X.
To measure in hardware you can simply output some pulses to test pins and measure time with oscilloscope.
You can also use timer to measure not very long periods. In case longest period is shorter than timer overflow period, you can do
volatile unsigned short t1;
volatile unsigned short t2
t1 = TCNT; // before
benchmarked_routine();
t2 = TCNT; // after
t2 -t1 --- time difference expressed in timer ticks. You need to take into account timer prescaler. If TCNT is reset on TC7 output compare (TCRE==1), then timedif = (t2-t1) % TC7.
Thanks Keff for replying
I think I will choose the simple approach, use cycle bus counter, that appears in status bar of 'Full chip simulation' adjacent to CPU frequency. But the big problem that I don't know at what frequency my mc9s12xd256 is running in actual. I have not altered any settings or registers of it.
I hope you can help me here too.
In simulator it makes sense to set Oscilator frequency (see Simulator->Clock Frequency). You may choose there also to show time or bus cycles on the status bar. After you select correct oscilator frequency (your crystal clock), engaging PLL will take into account clock multiplier.
Ya I know that, but the question is that I don't know at what frequency actually my MCU runs in real. I have not set any registers reagrding clock. I want to know the frequency of my CPU so that I can set it in oscillator and get correct time in status bar.
Don't you know what's frequency of crystal or oscilator on your PCB? I also don't know that.
Actually I thought there is a internal clock in the MCU and default settings is to use that.
This is the document of the PCB. I can see here 4Mhz. Can I set the CPU clock to be 4Mhz in the real time oscillator
http://www.cedt.iisc.ernet.in/smartcar/Smart_Car_Hardware/Smart_Car_Controller.pdf
and here is the datasheet of the crystall
http://www.cedt.iisc.ernet.in/smartcar/Smart_Car_Hardware/Data_Sheets/abls_crystal.pdf
I will be really thankful if you can sort this issue for me..
Thanks
Maybe you expected similar behaviour like in S08 families, but no, in S12(X) crystal oscilator is always enabled. Bus clock is derived from this oscilator or external clock. Bus clock = osc. clock / 2. In case external oscilator fails, backup clock is availablle (PLL selfclock mode). S12XD self clock mode frequency is from 1MHz min and 5.5MHz max.
Yes, you should set oscilator clock to 4MHz. Then until you rise bas clock with PLL, bus clock will be 2MHz.
"Yes, you should set oscilator clock to 4MHz."
But how to set the 4Mhz clock. I mean please tell me the register name associated with it.... or some example program would be great..
Also I have enabled timer with the following settings. What do you expect the time in ms that my timer will tick...
TIOS = 128; //output compare select..
TC7= 65535; /* Store given value to the compare register */
TFLG1 = 128; /* Reset interrupt request flag */
TIE_C7I = 1; /* Enable interrupt */
TSCR1_TEN = 1; /* Start timer */
I tested it in my own real MCU and in simulator having a 4mz crystall, I got around 920 ms using a stop watch ..
Also in simulator I got a similar time in ms using a 4Mhz CPU clock and 2Mhz bus clock..
Also please help me with BUS clock and CPU clock. Please check assertions.
1. The bus clock supplies all perepherials like timers.
2. My code runs at CPU clock, ie at 4Mhz...
Thanks in advance
It's not a register. In real hardware you have crystal or oscilator frequency. In simulator you have Simulator menu, and then Clock Frequency menu item.
Looks like you didn't touch timer prescaler, so prescaler defaults to busclock/1. Timer is ticking at bus clock frequency. Since PLL is not configured, bus clock and timer clock are both 4MHz/2 = 2MHz.
Such long time is not that simple to measure with timer. Timer overflow period at 2MH bus is ~33ms and you would need to count overflows between 2 events.
yes, except XGATE.
Yes and no. CPU clock is of course clocked from oscilator. But oscilator clock is divided by 2 to form bus clock. Shortest CPU12X instruction takes 1 bus clock period. Next to shortest CPU12X instruction takes 2 bus clocks, etc. XGATE operates at frequency bus clock *2.
Ok so lets conclude this thread. I think as I got a 4Mhz crystall at my PCB so I should I assume that my CPU is running at 4Mhz even if I cannot measure that accurately.
I have attached a photograph depciting the XTAL area of my PCB.
You saw this circuit previously, no need to zoom it. Yes, CPU will run at 4MHz (until you select PLL clock) and bus clock will be 2MHz.Bus clock is more important than some internal CPU frequency.
To check what freq. your CPU is operating at, you may clear NECLK bit in ECLKCTL register and probe bus clock on ECLK pin. You can also check oscilator or PLL clock by clearing NCLK2X bit and and probing ECLK2X pin.
Thanks a lot, for your very useful guidance.. keff