Difference between revisions of "Changing SimpleMotion baud rate"

From Granite Devices Knowledge Wiki
Jump to: navigation, search
[checked revision][checked revision]
Line 36: Line 36:
 
//and reinitialization of the speed is needed.
 
//and reinitialization of the speed is needed.
 
</syntaxhighlight>
 
</syntaxhighlight>
[[category:SimpleMotion]]
+
 
 +
Baud rate parameter behavior:
 +
*Newly set baud rate will stay active only when device stays on (logic voltage on and drive not restarted). Baud rate will always reset to default 460800 BPS if device is powered off/on.
 +
*If you setup the SimpleMotion watchdog has been set, then baud rate will also reset to default also if connection is lost for certain period of time. This is useful ensuring that you can re-connect again to the device with default baud rate and then re-do the baud date change procedure.
  
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Software]]
 
[[Category:Software]]
 +
[[Category:SimpleMotion]]

Revision as of 10:36, 25 July 2018

RS485 based SimpleMotion V2 bus supports changing baud rate on the fly from the default 460800 PBS. The procedure in simplest form is done by writing new baudrate value into parameter SMP_BUS_SPEED, and after that closing and re-opening the bus with the same speed.

However, in addition it is recommended to setup watchdog feature that will reset bus baudrate to default in case of connection is lost and timeouted. Example:

int pbs=1000000;//new bus baud rate
int slaveSMWatchdogTimeountMs=700;//adjustable in 10ms steps up to 8000 ms
 
//open SM bus with default baud rate
smSetBaudrate(460800);
smhandle=smOpenBus("COM1");
 
//reduce timeout because as following commands are sent to address 0 (broadcast to all devices), they will not return anything, so they will just timeout
smSetTimeout(50);
 
//setup SM bus watchdog feature. when communication is timeouted, motor will be stopped and baudrate is reset to default
smSetParameter(smhandle,0,SMP_FAULT_BEHAVIOR,((slaveSMWatchdogTimeountMs/10)<<8)|1);
 
//change baudrate of all devices on the bus (by giving address 0). it is important to change all devices at once so no communication errors happen due to wrong speed devices on the bus.
smSetParameter(smhandle,0,SMP_BUS_SPEED,pbs);
 
//reset errors that have come from above commands (SM library current version expects response from the commands even when they are broadcasted to address 0, thus it is expected not to give respose)
resetCumulativeStatus(smhandle);
 
//set longer timeout, to make SM bus watchdog activate on error, set this value higher than slaveSMWatchdogTimeountMs
smSetTimeout(1000);
 
//reopen SM bus device with new speed
smCloseBus(smhandle);
smSetBaudrate(pbs);
smhandle=smOpenBus("COM1");
 
//continue using bus at new speed normally.
//keep in mind that new commands must be sent to bus at least with the rate defined by slaveSMWatchdogTimeountMs.
//if any command fails to timeout, or by any other reason timeout occurs, then devices have reset to default speed 
//and reinitialization of the speed is needed.

Baud rate parameter behavior:

  • Newly set baud rate will stay active only when device stays on (logic voltage on and drive not restarted). Baud rate will always reset to default 460800 BPS if device is powered off/on.
  • If you setup the SimpleMotion watchdog has been set, then baud rate will also reset to default also if connection is lost for certain period of time. This is useful ensuring that you can re-connect again to the device with default baud rate and then re-do the baud date change procedure.