11-18-2015 02:21 PM - edited 11-18-2015 02:24 PM
"nixnet.h" provided a function "nxAdvCANBaudRate_Set" which calculated baud rate from bit timings.
I would like to know how this calculation works for LIN, CAN, and CAN-FD?
Can some one explain it in brief with some examples ? how to find out what parameters to "nxAdvCANBaudRate_Set" function will give me a valid baud valid?
// Session properties (including runtime interface properties) // Macro to set nxPropSession_IntfBaudRate for an advanced CAN baud rate (bit timings) // If you pass a basic baud rate like 125000 or 500000, NI-XNET calculates bit timings for you #define nxAdvCANBaudRate_Set(TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) ( \ (((u32)TimeQuantum) & 0x0000FFFF) | \ (((u32)TimeSeg0 << 16) & 0x000F0000) | \ (((u32)TimeSeg1 << 20) & 0x00700000) | \ (((u32)SyncJumpWidth << 24) & 0x03000000) | \ ((u32)0x80000000) )
11-19-2015 08:19 AM - edited 11-19-2015 08:26 AM
I referred to following section in the documentation but was not able to undertand how I would make a general function using "nxAdvCANBaudRate_Set" so that I can set speed for CAN, LIN, CAN-FD.
I plan on creating a function where a speed is passed and the function would store those values in a struct (TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) and use this struct during create session.
http://www.ni.com/pdf/manuals/372840k.pdf#page=1049
http://www.ni.com/pdf/manuals/372840k.pdf#page=983
For LIN session
As a test I passes "l_baud = nxAdvCANBaudRate_Set(125, 8, 1, 1);" I got l_baud = 2165833853 (0x8118007D) which I assume means baud rate of 125 kbps
Any help is appreciated.
11-19-2015 03:10 PM
I have not used that function before, but the NI X-NET Hardware and Software Manual has a ton of information on the C API. I would suggest taking a look in there (starting on page 5-1).
NI X-NET Hardware and Software Manual
http://www.ni.com/pdf/manuals/372840h.pdf
I also do know that you can set custom baud rates in LabVIEW; it could be helpful to look at some resources for LV and then map it to the C API. For example, I'll include the following link for your reference:
How Can I Set Custom Baud Rates on XNET Devices?
http://digital.ni.com/public.nsf/allkb/EED45251DB3B870786257736006A722B?OpenDocument
Best of luck!
11-23-2015 07:28 AM
Thanks TheXiadow
I referred following link you suggested and it helps me to get started. Looks like for LIN and CAN (speed from 5 kbaud to 1000 kbaud) I can use this method to findout what would be the "TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth" parameters.
How Can I Set Custom Baud Rates on XNET Devices?
http://digital.ni.com/public.nsf/allkb/EED45251DB3
But how do I set custom speed for CAN-FD "set property for nxPropSession_IntfCanFdBaudRate"? Is it even possible?
11-24-2015 04:30 PM
If you look in the NI-XNET manual I linked in my last post, there is information about setting custom baud rates for specifically the nxPropSession_IntfCanFdBaudRate property. On pages 5-268 and 5-269, it provides information on when you set the upper nibble to clear (you can set numeric baud rates) and when you set the upper nibble to 0x8 (you can set custom baud rate programming).