Questions about busclock and XGate

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Questions about busclock and XGate

5,605 Views
tim_milliken
Contributor III
The docs seem to be very unclear about the bus clock in the xgate. If I am running the core at 40 mHz what is the clock on the xgate? I have seen docs that say upto 80mHz on the xgate but is that in flash or ram. I am trying to get time from a IC channel/ If I am thinking right Busclock/Prescaler = timer clock. Then Duration of the input capture/ timer clock = time in seconds. Please let me know if I am doing something wrong cause all of my times are way out and can't figure out why. Tim
Labels (1)
0 Kudos
Reply
13 Replies

2,830 Views
Alban
Senior Contributor II
Hi Tim,
 
From the clock module.
 
The XGATE (on S12XE or S12XE) is ALWAYS double the frequency of the Bus. It is fixed.
 
Cheers,
Alban
0 Kudos
Reply

2,830 Views
tim_milliken
Contributor III
Here is the code I am using to set the clock
   REFDV = 0;
   SYNR = 9;
   CRGFLG &= 0x10;
   while(!(CRGFLG & 0x8));
   CLKSEL |= 0x80;
I am using the EVB9S12xDP512 board that has a 4 mHz crystal and a 16 mHz clock on it and I just looked at the jumper settings and I have it on the jumper set to run the 4 mHz crystal so I feel like a real DUMMY now. Let me change that around and I will post my findings. Thanks Tim
0 Kudos
Reply

2,830 Views
tim_milliken
Contributor III
ok I came up with the same results after changing the REFDV and SYNR settings. But now what am I doing wrong in tryinh to get real time from my capture time. this is how I am calc. it.
my capture time stamp 4930/ XGate bus clock 80,000,000 = 0.000061625  . Correct me if I am wrong but I think I am doing this right. But if I figure in that I have a 40mHz bus clock it comes out to what I think is closer to being right. Also I have the interrupt in the XGate module. In that case do I need to caculate on the core bus clock of 40Mhz?? I suspose I am just lost at the at the moment. Thanks for any help.. Tim
0 Kudos
Reply

2,830 Views
Alban
Senior Contributor II
Dear Tim,
 
All modules are working from the core clock, not from the XGATE.
 
You need to divide your count by the module clock and divide by all prescalers configured in your timer.
Only the XGATE is running from the 80MHz in your configuration.
Therefore even if you move the Timer interrupt code to be handled by the CPU12X or the XGATE, you don't need to change it.
 
The XGATE works by event, it should not be made to loop on something to wait.
It's preferable to work with small interrupt routines.
 
Cheers,
Alban.
0 Kudos
Reply

2,830 Views
Steve
NXP Employee
NXP Employee
Tim, it sounds like you are confusing two different things here. The timer, CPU & all of the other modules run from the bus clock* which is a maximum of 40MHz for S12XD. The XGATE runs at double this frequency so a maximum of 80MHz. So it doesn't matter if the timer interrupts go to the XGATE or to the CPU they will always time relative to a 40MHz (max) clock.
Note that if you want XGATE to run at full speed you have to execute its code from RAM because then it can fetch its instructions at full (80MHz) speed. The flash is limited to 40MHz read so XGATE running from flash can only run at that slower speed.
 
* Some modules, for example flash and ATD, have additional dividers that bring the bus clock down into their usable range.
0 Kudos
Reply

2,830 Views
srimt
Contributor I

Dear Steve

 

I have a question about XGATE application.

I want to use XGATE to create a standard square wave output from a GPIO.

 

    interrupt void SoftwareTrigger0_handler(void)

    {

             long i;

             PTP_PTP3 ^= 0x01;

             i = 0x5AC;

             while (i --);

 

             asm SIF;

    }

 

I did get a square wave from the PTP3 pin, but it's not a exactly standard square wave. what's the root cause? Does the instruction time of XGATE be changed ?

Thanks in advance! Srimt

0 Kudos
Reply

2,830 Views
kef
Specialist I

XGATE can execute up to two instructions per bus cycle. It will do 2 instructions only if it is executing from RAM, doesn't perform R/W accesses and if CPU doesn't access RAM in the current bus cycle. Executing from flash XGATE can do up to 1 instruction per bus cycle in case CPU doesn't access flash. Accessing registers space also adds some nuisances who wins and who has to wait a bit. Sometimes CPU12X slows down the XGATE, also there are cases when XGATE can slow down the CPU12X...

 

Code like yours should make some jitter on output pin, it's expected.

0 Kudos
Reply

2,830 Views
srimt
Contributor I

Thanks for your answer. But I need to implement a 8KHz standard square wave, and the timer just can implement 1KHz,  Do you have any good suggestions for me ?

 

Thanks again!

0 Kudos
Reply

2,830 Views
kef
Specialist I

PWM module, ECT module, TIM module all can be used to produce suqare wave with frequencies up to busclock /2. Of course there are some restrictions.

 

For example using PWM module with least possible PWM prescaler, default left aligned mode, first you divide busclock / target frequency. Say busclock is 40MHz, target - 8kHz. 40M / 8k = 5000. 5000 is >=256, so you should concatenate two 8bit PWM channels into one 16bit PWM. Period - 5000, duty cycle 5000/2=2500.

0 Kudos
Reply

2,830 Views
srimt
Contributor I

Thanks, I have got a 8KHz Standard spuare wave over ECT and XGATE.

 

 Busclock = 32MHz

 Buts tick time = 31.25ns

 ECT_MCCNT = 2000;

 

 while(ECT_MCCNT >= 5);
 asm SIF;
 PTP_PTP3 ^= 1;

 

Now my system works well. Thanks all good guys here.

0 Kudos
Reply

2,830 Views
kef
Specialist I

You code doesn't look right.

 

1. MCCNT is not writeable in normal modes, ECT_MCCNT = 2000 won't work without BDM pod connected.

2. MCCNT is upcounting. If MCCNT would accept MCCNT = 2000, condition ECT_MCCNT >=5 would be true about 65536-2000-5 timer ticks, almost 2ms @32MHz. You code works because in special mode (when BDM pod is attached and you aren't using hotplug debugging), writing anything to MCCNT  resets MCCNT.

 

This should work in all modes (not tested):

 

signed int targettcnt;

 

  for(;:smileywink:

 

   targettcnt = TCNT + 2000;

    while( (signed int)(TCNT - targettcnt) < 0) ) {}

 

   PTP ^= (1<<3);

  }

 

 

But jitter still will be high compared to automatic pin action on timer output compare, or compared to PWM. Here's the code (not tested) for 8kHz square wave on PP3/PWM3

 

 

   PWMPER23=4000;  // 32M / 8k

   PWMDTY23=2000;
   PWMCTL |= PWMCTL_CON23_MASK; // concatenate PWM 2 and 3
   PWME |= (1<<3);

0 Kudos
Reply

2,830 Views
srimt
Contributor I

:smileyhappy:

 

1. I initialized the MCCNT value 2000 one time.

2. I set MCEN bit which means modulus Down_Counter enable

3. I set FLMC bit which means Force Load Register into Modulus Counter Count Register

So after counter down count to 0, system will auto reload 2000 to the counter.

 

I have tested my code, it works well. BTY, my cpu is MC9S12XEQ512.

 

And PWM sources have been used by other programs.

 

:smileyhappy:

0 Kudos
Reply

2,830 Views
kef
Specialist I
Oh, lack of sleep probably :smileyhappy:. TCNT and MCCNT are different things of course, and writing about not writeable MCCNT, I meant TCNT, sorry.
Message Edited by kef on 2009-09-28 12:18 PM
0 Kudos
Reply