XS1_TIMER_MHZ value

If you have a simple question and just want an answer.
valgamaa
Newbie
Posts: 1
Joined: Wed Mar 12, 2014 6:21 pm

XS1_TIMER_MHZ value

Post by valgamaa »

I have been working on some code for a MIDI interface using the startKIT, and followed all the documentation relating to serial interfaces. None of this was working, so I tried the simple UART example, starting with the back2back example. This worked back to back, but failed stand-alone.

Looking at the transmitted data with a storage 'scope I finally noticed that the data rate was around 20% too fast, and correcting this resulted in a working interface.

What should the XS1_TIMER_MHZ variable be, as it returns a value of 100? If this is wrong where is it defined, so that I can correct it, as I will be writing code that runs at a fixed sample-rate and I want to be sure my code will run on the inteded hardware target without modification.



User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Hi. The default reference clock is 100 Mhz for XMOS but is also based on the external clock source supplied to the component and PLL settings. The 500 Mhz versions are able to push this clock higher to 125 Mhz with the proper settings. Noting these values, the reason your MIDI communication is off is likely that the reference clock is not supplying the proper resolution to accurately hit the 31250 bps. My humble suggestion is to review the multi_uart code on github which feeds yet another external clock source of 1.8432 Mhz (supplied on the 8 uart xslice kit) into a free GPIO pin. The UART code then uses this industry std clock source to frame PC standard baud rates (ie. 115.2, 57.6k, etc.). Then again, this value of 1.8432 Mhz is probably not the best choice for your MIDI use. From the net, it appears the best choice for your project is 3 Mhz. So if you feed a 3.3 volt CMOS external clock source @ 3 Mhz (50 ppm or better), into a GPIO pin + use the posted code on github, you should hit your MIDI speed perfectly.

For some reasons, unable to paste some references to the above information. This feedback is from reading up on this topic for a pending project only so please do review the same for yours. Be sure to change the code to reflect the GPIO pin used for your external clock source. Summary is that using an external clock source, you should be able to frame to literally any baud rate (within the scope of the speed of your XMOS) which makes this very very flexible. If you want to get really kinky, consider to apply an external I2C PLL (see SiLabs or similar) as we are applying into our project. Would recommend this after confirming the use of the fixed 3 Mhz clock source.

< updated for an improved clock value >

Sorry, did some calculations and concluding that 3 Mhz is a wiser value for the external clock source. Calculations are as follows:

19200 / 1.8432 = x / 3.00 ; compute for x

That is, with an external clock source of 3.00 Mhz, when you use the UART clock and dial up 19.2k in the API, the hardware will frame @ 31250 bps. If you do elect to use 2.00 Mhz, then you MUST select 28800 bps in the API which I am not sure at this time if the UART code supports. For this reason, consider to use 3 Mhz.