Hi guys,
I'm currently working on a gyro sensor reading program, and I need to configure a SPI interface (using the Xmos as Master, with only one slave connected to) with 8Mhz clock frequency and achieve 2.3kHz sampling rate.
I've tried to use the latest SPI library (v.3.0.2), and apparently it was communicating with the sensor, but not in the way I need.
So I started some simulation tests by following the examples in the Application Note AN00160 provided in https://www.xmos.com/support/libraries/lib_spi.
I have 2 questions regarding this library:
1) What is the difference between using or not using a Clock Block in the "spi_master" function? The SPI master example applies "null" in the "clk_spi", and it works fine for frequencies around 100kHz, but the program starts freezing when high frequencies such as 10000kHz is applied.
It only starts working whenever a Clock Block is used, but now a huge delay (?) shows up between each data transfer, eventually limiting the sampling rate. Could anyone explain me this phenomenon?
2) What is the equation used for the clock frequency? I mean, I have tried to apply 8000 (in order to achieve 8MHz) in the "speed_in_khz" variable within the "begin_transaction" function, but it doesn't drive the right frequency. It works fine when I apply 10600 instead, but I still can't figure out how to find the right value for each desired frequency output. I have also found the following equation within "spi_sync.xc", but it still doesn't make sense to me.
unsigned d = (XS1_TIMER_KHZ + 4*speed_in_khz - 1)/(4*speed_in_khz);
configure_clock_ref(cb, d);
start_clock(cb);
, considering that XS1_TIMER_KHZ = 10000
Thank you very much!!
SPI clock frequency and sampling rate
-
- New User
- Posts: 2
- Joined: Wed May 25, 2016 5:32 am
-
- XCore Addict
- Posts: 230
- Joined: Wed Mar 10, 2010 12:46 pm
I'm not sure what is happening without the clock block enabled, but hopefully I can help with getting a frequency you desire.
When you use the "configure_clock_ref(clk, d)" function it takes the reference clock (assuming you haven't changed the clock input) and divides it by 2*d.
The reference clock is 100MHz, so if you want 8MHz then the closest you'll get is setting d to 6 so you get:
100 / 2*6 = 8.33MHz
When you use the "configure_clock_ref(clk, d)" function it takes the reference clock (assuming you haven't changed the clock input) and divides it by 2*d.
The reference clock is 100MHz, so if you want 8MHz then the closest you'll get is setting d to 6 so you get:
100 / 2*6 = 8.33MHz
-
- XCore Legend
- Posts: 1126
- Joined: Thu May 27, 2010 10:08 am
You should be able to get a bit closer to 8.000MHz..
If you use:
then you can divide from the 500MHz core clock by 2n. So for example, if you do:
you can get to 500 / (31 * 2) = 8.064516129MHz
If you use:
Code: Select all
void configure_clock_xcore(clock clk, unsigned char divide);
Code: Select all
void configure_clock_xcore(clk, 31);
-
- New User
- Posts: 2
- Joined: Wed May 25, 2016 5:32 am
Hi guys,
Sorry for the late reply.
I'll try using those functions and see if I can get the clock frequency that I need.
Thank you very much for your help :)
By the way, I'll post some pictures later regarding the Clock Block phenomenon.
Thanks.
Sorry for the late reply.
I'll try using those functions and see if I can get the clock frequency that I need.
Thank you very much for your help :)
By the way, I'll post some pictures later regarding the Clock Block phenomenon.
Thanks.