Kart/serial link

(Difference between revisions)
Jump to: navigation, search
(Testing through USB)
(29 intermediate revisions by 6 users not shown)
Line 2: Line 2:
 
== Serial link protocol ==
 
== Serial link protocol ==
  
This section defines the serial link protocol used to communicate between the Kart and the SmartPhone. All data is spontaneous send and can not be polled.
+
This section defines the serial link protocol used to communicate between the Kart and the BLE module / PC.
 +
 
 +
=== General principle ===
 +
The system using a [[Kart/Bluetooth|BLE]] module, the throughput is limited by design to a payload of 27 bytes each connection interval (from 7.5 ms to 4 s).
 +
 
 +
To avoid congesting the line, data are sent from the Kart to the User on specific '''events''' or if '''requested''' by the User.
  
 
=== Serial port===
 
=== Serial port===
  
 
Communication is done with:
 
Communication is done with:
* 115200 baud
+
* Resting state : HIGH
* 8 bits
+
* Data bits : 8
* no parity
+
* Parity : none
* no handshake
+
* Stop bits : 1
 +
* Handshake : none
 +
* Baudrate : 115'200
  
 
=== Message Format ===
 
=== Message Format ===
Line 20: Line 27:
 
! EoF (1 byte)
 
! EoF (1 byte)
 
|-
 
|-
| 0x55
+
| 0xAA
 
| UINT8
 
| UINT8
| UINT16/INT16
+
| UINT16/INT16/VECTOR16 (MSB first)
 +
| [https://crccalc.com/ CRC8/ITU]
 +
|}
 +
 
 +
The address is decomposed as follows: 0bMMWRRRRR
 +
* MM : targeted module
 +
** 0b00 : DC Motor
 +
** 0b01 : Stepper Motor
 +
** 0b10 : Sensors
 +
** 0b11 : Control Registers
 +
* W : defines if the data is saved to ('1') or read from ('0') the FPGA
 +
** The FPGA will '''respond to a request''' with the exact same address when W = '0'
 +
** The FPGA will '''save incoming data in the targeted register''' when W = '1'
 +
** The FPGA will '''send data on predefined events''' with the W bit set to '1'
 +
* RRRRR : targeted register
 +
 
 +
==== Frame example ====
 +
 
 +
For the BLE module to light LED1 with it changing each 500 ms, the following frame is sent:
 +
{| cellpadding="8" cellspacing="0" border="1"
 +
! SoF (1 byte)
 +
! Address (1 byte)
 +
! Data High (1 byte)
 +
! Data Low (1 byte)
 +
! EoF (1 byte)
 +
|-
 
| 0xAA
 
| 0xAA
 +
| 0b10100001
 +
| 0b10000001
 +
| 0b11110100
 +
| 0x74
 
|}
 
|}
 +
 +
 +
When the stepper end switch is pressed, imagining that the desired position is reached in the meantime, the FPGA will send the following:
 +
{| cellpadding="8" cellspacing="0" border="1"
 +
! SoF (1 byte)
 +
! Address (1 byte)
 +
! Data High (1 byte)
 +
! Data Low (1 byte)
 +
! EoF (1 byte)
 +
|-
 +
| 0xAA
 +
| 0b01100011
 +
| 0b00000000
 +
| 0b00000011
 +
| 0x47
 +
|}
 +
 +
 +
If the BLE module wants to read the current battery voltage, supposing we have 4 LEDs, the frame is such as:
 +
{| cellpadding="8" cellspacing="0" border="1"
 +
! SoF (1 byte)
 +
! Address (1 byte)
 +
! Data High (1 byte)
 +
! Data Low (1 byte)
 +
! EoF (1 byte)
 +
|-
 +
| 0xAA
 +
| 0b10000101
 +
| Any
 +
| Any
 +
| CRC
 +
|}
 +
The FPGA will then respond with something like (for a 11.998V reading):
 +
{| cellpadding="8" cellspacing="0" border="1"
 +
! SoF (1 byte)
 +
! Address (1 byte)
 +
! Data High (1 byte)
 +
! Data Low (1 byte)
 +
! EoF (1 byte)
 +
|-
 +
| 0xAA
 +
| 0b10000101
 +
| 0x18
 +
| 0x09
 +
| 0x3D
 +
|}
 +
  
 
== Registers ==
 
== Registers ==
  
=== SmartPhone to Kart ===
+
=== DC Motor ===
 +
 
 +
Reading range : 0x00 to 0x1F
 +
 
 +
Writing range : 0x20 to 0x3F
  
 
{| cellpadding="4" cellspacing="0" border="1"
 
{| cellpadding="4" cellspacing="0" border="1"
 
! Address
 
! Address
! Datatype
+
! Name
 +
! Type
 
! Description
 
! Description
 +
! Direction
 +
! Event
 
|-
 
|-
 
| 0
 
| 0
| UINT16
+
| Prescaler
| DC motor PWM period
+
| Uint16
 +
| DC PWM frequency, as fclk / (PWMsteps * prescaler) = 10M / (16 * prescaler)
 +
| Smartphone -> Kart
 +
|
 
|-
 
|-
 
| 1
 
| 1
| INT5
+
| Speed
| DC motor speed: -15 to 15 (Negative numbers = backwards)
+
| Int5
 +
| Desired speed, from -15 (0xFFF1) to 15 (0x000F) (negative = backward)
 +
| Smartphone -> Kart
 +
|
 +
|}
 +
 
 +
 
 +
=== Stepper Motor ===
 +
 
 +
Reading range : 0x40 to 0x5F
 +
 
 +
Writing range : 0x60 to 0x7F
 +
 
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
! Address
 +
! Name
 +
! Type
 +
! Description
 +
! Direction
 +
! Event
 +
|-
 +
| 0
 +
| Prescaler
 +
| Uint16
 +
| Stepper switching frequency, as 100k / prescaler
 +
| Smartphone -> Kart
 +
|
 +
|-
 +
| 1
 +
| Target angle
 +
| Uint16
 +
| Desired steering angle, in motor steps (0 = end switch)
 +
| Smartphone -> Kart
 +
|
 
|-
 
|-
 
| 2
 
| 2
| UINT16
+
| Actual angle
| stepper motor period (speed proportional to 1/period)
+
| Uint16
 +
| Actual steering angle, in motor steps (0 = end switch)
 +
| Kart -> Smartphone
 +
| When a delta of at least STP_ANGLE_DELTA_DEG (10°) from the last registered value happens
 
|-
 
|-
 
| 3
 
| 3
| UINT16
+
| Stepper HW
| Desired Steering Angle
+
| Vector2
 +
| Bit 0: stepper end
 +
Bit 1: position reached
 +
| Kart -> Smartphone
 +
| Sent when stepper end is pressed (rising edge) or position reached (rising edge)
 +
|}
 +
 
 +
 
 +
=== Sensors ===
 +
 
 +
Reading range : 0x80 to 0x9F
 +
 
 +
Writing range : 0xA0 to 0xBF
 +
 
 +
The sensors count may change based on the values given in the ''Kart -> Kart_Student_pkg''.
 +
Thus, the registers addresses are based on the following definitions :
 +
* '''NB_LEDS''' : the number of LEDs / digital outputs used | '''NUMBER_OF_LEDS''' in the package
 +
* '''NB_ENDSW''' : the number of end switches / buttons used | '''NUMBER_OF_EXT_END_SWITCHES''' in the package
 +
* '''NB_HALL''' : the number of hall sensors used | '''NUMBER_OF_HALL_SENSORS''' in the package
 +
* '''NB_PROXI''' : the number of eproximity sensors used | '''NUMBER_OF_PROXIMITY_SENSORS''' in the package
 +
{{WarningBox|content=
 +
Beware that the last address is not bigger than 31 !
 +
}}
 +
 
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
! Address
 +
! Name
 +
! Type
 +
! Description
 +
! Direction
 +
! Event
 
|-
 
|-
| 3
+
| 0
| UINT16
+
| Refresh proximity
| LEDs
+
| -
 +
| Send anything to this register to refresh the proximity sensors
 +
| Smartphone -> Kart
 +
|  
 
|-
 
|-
| 5
+
| 1
| UINT16
+
| LED1
| Hardware orientation
+
| Bit + Uint15
 +
| Bit 15: on / off/
 +
Bits 14 -> 0: half-period in ms (if 0, led status = bit 15)
 +
| Smartphone -> Kart
 +
|  
 
|-
 
|-
| 15
+
| NB_LEDS
| UINT16
+
| LEDn
| Serial link update interval [ms]
+
| Bit + Uint15
 +
| ''See LED1''
 +
| Smartphone -> Kart
 +
|
 +
|-
 +
| NB_LEDS + 1
 +
| Voltage
 +
| Uint16
 +
| Battery voltage, U = register * 250*e-6 * 7.8 [V]
 +
| Kart -> Smartphone
 +
| When a delta of at least SENS_BATT_DELTA_MV (100) from the last registered value happens
 +
|-
 +
| NB_LEDS + 2
 +
| Current
 +
| Uint16
 +
| Consumed current, I = register * 250*10*e-6 / (100 * 5*10*e-3) [A]
 +
| Kart -> Smartphone
 +
| When a delta of at least SENS_CURR_DELTA_MA (50) from the last registered value happens
 +
|-
 +
| NB_LEDS + 3
 +
| Range finder
 +
| Uint16
 +
| Distance to sensor, register * 25.4 / (147*10*e-6 * (10M / 10)) [mm]
 +
Register zeroed if less than 152 mm (sensor min distance) or greater than 1500 mm (arbitrary max distance), event not sent in such case
 +
| Kart -> Smartphone
 +
| When a delta of at least SENS_RANGEFNDR_MM (100) from the last registered value happens
 +
|-
 +
| NB_LEDS + 4
 +
| End switches
 +
| Vector(NB_ENDSW)
 +
| Sensors current values, right justified (sensor 1 is bit 0)
 +
| Kart -> Smartphone
 +
| On any edge change of any sensor
 +
|-
 +
| NB_LEDS + 5
 +
| Hall1
 +
| Uint5 + Uint11
 +
| Uint5 (left justified) : number of 1/2 turns counted
 +
Uint11 : time in steps of 4 ms
 +
| Kart -> Smartphone
 +
| When a count of at least SENS_HALLCOUNT_HALF_TURN_DELTA (20) happens
 +
|-
 +
| NB_LEDS + NB_HALL + 4
 +
| Halln
 +
| Uint5 + Uint11
 +
| ''See Hall1''
 +
| Kart -> Smartphone
 +
| ''See Hall1''
 +
|-
 +
| NB_LEDS + NB_HALL + 5
 +
| Proxy1
 +
| Uint16
 +
| Proximity value in unknown unit ''(tests should be conducted, the highest the closest)''
 +
| Kart -> Smartphone
 +
| When a delta of at least SENS_PROXI_DELTA (255) from the last registered value happens
 +
|-
 +
| NB_LEDS + NB_HALL + NB_PROXI + 4
 +
| Proxyn
 +
| Uint16
 +
| ''See Proxy1''
 +
| Kart -> Smartphone
 +
| ''See Proxy1''
 +
|-
 +
| NB_LEDS + NB_HALL + NB_PROXI + 5
 +
| Ambient1
 +
| Uint16
 +
| Ambient light, E = register * 250*10*e-3 [lx] ''([https://www.vishay.com/docs/83372/vcnl4000.pdf clear sensor cover])''
 +
| Kart -> Smartphone
 +
| When a delta of at least SENS_AMBIENT_DELTA (255) from the last registered value happens
 +
|-
 +
| NB_LEDS + NB_HALL + 2* NB_PROXI + 4
 +
| Ambientn
 +
| Uint16
 +
| ''See ambient1''
 +
| Kart -> Smartphone
 +
| ''See ambient1''
 
|}
 
|}
  
=== Kart to SmartPhone ===
+
 
 +
=== Control Registers ===
 +
 
 +
Reading range : 0xC0 to 0xDF
 +
 
 +
Writing range : 0xE0 to 0xFF
 +
{{WarningBox|content=
 +
The control registers module is '''WRITE ONLY''' for now !
 +
}}
  
 
{| cellpadding="4" cellspacing="0" border="1"
 
{| cellpadding="4" cellspacing="0" border="1"
 
! Address
 
! Address
! Datatype
+
! Name
 +
! Type
 
! Description
 
! Description
 +
! Direction
 +
! Event
 
|-
 
|-
 
| 0
 
| 0
| UINT16
+
| Hardware Control
| Hall speed count 1
+
| Vector6
 +
| Bit 0: when '0', the Kart goes backwards when the motor turns foward
 +
Bit 1: when '1', the Kart turns to the right as the stepper coils go from 1 to 4
 +
 
 +
Bit 2: when '1', the angles are measured clockwise
 +
 
 +
Bit 3: emulates the end switch contact for the stepper motor
 +
 
 +
Bit 4: restart the stepperMotor module, stops the DC motor while '1'
 +
 
 +
Bit 5: when '1', the BLE connection has been established (otherwise, the Kart should not be able to move)
 +
| Smartphone -> Kart
 +
| The end sensor always defines angle 0. Angles are always positive numbers in registers.
 +
If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted.
 +
If the Bluetooth connection is lost, the DC motor has to be stopped.
 +
|}
 +
 
 +
 
 +
 
 +
 
 +
==== Sequence control register ====
 +
 
 +
''The sequence control register is not yet re-implemented.
 +
The old behavior, kept for reference, is the following:''
 +
 
 +
The sequence control register is used to load a new sequence from start of memory as well as to start and stop a sequence.
 +
 
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
! Bit
 +
! Meaning
 +
! Description
 +
|-
 +
| 0
 +
| Reset sequence
 +
| sets the sequence RAM write and read addresses back to 0
 
|-
 
|-
 
| 1
 
| 1
| UINT16
+
| Run / stop
| Hall speed count 2
+
| starts or stops a sequence
 +
|}
 +
 
 +
===== Sequence operations register =====
 +
 
 +
The sequence memory is made out of 16-bit controls and the sequence can range up to 2<sup>10</sup> operations.
 +
From the communication point of view, the sequence memory is seen as a FIFO&nbsp;:
 +
the sequence operations are pushed one after the other into the sequence register,
 +
starting at the first one of the list after the <code>reset sequence</code> bit
 +
has been set in the [[#Control register|control register]]
 +
 
 +
The sequence operations are split into 2&nbsp;parts: a 4-bit command and optional parameters.
 +
A sequence register has been defined in order to build loops:
 +
the <code>goto</code> operation is only carried out if the register is not zero.
 +
The register is initialised with all bits to&nbsp;'1'.
 +
 
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
|
 +
! colspan = "2" | command
 +
! parameter
 +
| comment
 
|-
 
|-
| 2
+
| Bits
| UINT1
+
! colspan = "2" | 15 ÷ 12
| Steering status: 0x01 means angle reached
+
! 11 ÷ 0
 +
|
 
|-
 
|-
| 3
+
| rowspan = "13" | || 0 || nop || ||
| UINT16
+
| Actual Steering Angle
+
 
|-
 
|-
| 4
+
| 1 || set speed || speed || set the propulsion motor speed
| UINT1
+
| Stepper End (bit is '0' when end switch is pressed)
+
 
|-
 
|-
| 5
+
| 2 || set angle || angle || set the direction motor angle
| UINT16
+
| ADC Value of the Battery Voltage Level
+
 
|-
 
|-
|
+
| 3 || drive LEDs || pattern || specify a given pattern for turning the LEDs on or off
|
+
|
+
 
|-
 
|-
| 8
+
| 4 || set LEDs || mask || set bits from '1's of mask
| UINT16
+
| Proximity 1
+
 
|-
 
|-
| 9
+
| 5 || clear LEDs || mask || clear bits from '1's of mask
| UINT16
+
| Proximity 2
+
 
|-
 
|-
| 10
+
| 6 || blink LEDs || period, mask || ''not implemented yet''
| UINT16
+
| Proximity 3
+
 
|-
 
|-
| 11
+
| 8 || run distance || hall ticks || run until the Hall counter has augmented by at least a given tick number
| UINT16
+
| Proximity 4
+
 
|-
 
|-
| 12
+
| 9 || run for || milliseconds || run for a specified time span
| UINT16
+
| Ambient Light 1
+
 
|-
 
|-
| 13
+
| A || run until || event || ''not implemented yet''
| UINT16
+
| Ambient Light 2
+
 
|-
 
|-
| 14
+
| D || modify register || operation, operand || bits 11÷10 : 00 = set, 10 = add, 11 = sub / bits 9÷0 : operand
| UINT16
+
| Ambient Light 3
+
 
|-
 
|-
| 15
+
| E || goto nz || address || jumps to the specified sequence step as long as the register is not zero
| UINT16
+
|-
| Ambient Light 4
+
| F || end || || the sequence controller in the FPGA stops and the <code>running</code> status bit is cleared, announcing that the sequence is terminated
 
|}
 
|}
  
=== Hardware orientation ===
+
===== Sequence status register =====
 +
 
 +
The sequence status register tells what operation is currently active.
  
 
{| cellpadding="4" cellspacing="0" border="1"
 
{| cellpadding="4" cellspacing="0" border="1"
Line 139: Line 426:
 
! Description
 
! Description
 
|-
 
|-
| 0
+
| 15 ÷ 12
| Kart goes as DC motor
+
| Current command
| When '0', the kart goes backwards when the motor turns forwards
+
| indicates which command is currently being processed
 
|-
 
|-
| 1
+
| 0
| Kart turns right (clockwise)
+
| Running
| When '1', kart turns to the right as stepper motor phases go from 1 to 4
+
| indicates that a sequence is currently running
|-
+
| 2
+
| End sensor is on left side
+
| If '1', the angles are measured clockwise.
+
 
|}
 
|}
  
The end sensor always defines position 0. Angles are always positive.
+
== Kart init ==
  
If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted.
+
To init the Kart, the following sequence should be sent to the Kart:
 +
* Write '''DC Motor | Prescaler''' to '''31''' (around 21 kHz PWM frequency)
 +
* Write '''Stepper Motor | Prescaler''' to '''400''' (250 Hz coil switching frequency)
 +
* Write '''Control Registers | Hardware Control''' to restart the system while telling the BLE client is connected (0b110xxx)
 +
** The stepper should turn until hitting the end switch, except if already on it
 +
* Read '''Stepper Motor | Stepper HW''' and check the last bit
 +
** If is '1', it means we are already zeroed
 +
** If not, wait for an event from this register to tell the reset is complete
 +
* Write '''Control Registers | Hardware Control''' to deassert the reset (0b100xxx)
 +
 
 +
The Kart is now ready to function !
 +
 
 +
== Testing through USB ==
 +
[[File:Kart_kci.jpg|450px|right|Kart Command Interpreter]]
 +
To test the Kart from a PC directly, one can do as follows:
 +
* Remove the [[Kart/Bluetooth|BLE]] from the [[Kart/Motherboard|motherboard]]
 +
* Power the [[Kart/Motherboard|motherboard]] with a DC voltage regulator (+12V)
 +
* Wire the USB-C present on the daughterboard to your PC
 +
** Two new COM ports should be detected
 +
* Download and open the '''Kart Command Interpreter''' utility (available in the VHDL project -> CommandInterpreter)
 +
** [https://github.com/hei-synd-2131-eln/eln-kart/blob/master/CommandInterpreter/KartCommandInterpreter_WIN.exe Windows 10]
 +
** [https://github.com/hei-synd-2131-eln/eln-kart/blob/master/CommandInterpreter/KartCommandInterpreter_MAC Mac]
 +
** [https://github.com/hei-synd-2131-eln/eln-kart/blob/master/CommandInterpreter/KartCommandInterpreter_LIN Linux]
 +
* In the top menu '''Serial -> Port''', select the correct COM port (should be the biggest of the two new ports)
 +
** You can also change the baudrate, by default '''115'200''' (the correct one if it was not modified in the VHDL '''Kart_pkg.vhd'''
 +
 
 +
To test the connection, click the '''Read''' button. The '''Tx''' and '''Rx''' values should change, and a text added to the text area.
 +
 
 +
=== Simple operation ===
 +
The simplest way to test both motors are the three button at the bottom.
 +
 
 +
* '''Init Kart''' button
 +
** Will set the DC prescaler, stepper prescaler, and execute the restart sequence. '''Must be clicked first.'''
 +
** You may need to modifiy the [[Kart/serial_link#Control_Registers|'''CReg -> HW Control''']] register to correspond to your Kart design. Only change x in the following value: '''0b100xxx'''
 +
* '''DC Motor''' button
 +
** Will set the DC speed to full for 2s, quickly 0, then reversed full speed for 2s
 +
* '''Stepper Motor''' button
 +
** Will set the stepper to 800 then 0
 +
 
 +
=== Custom operation ===
 +
Each register can be read and/or written by hand following their [[Kart/serial_link#Registers|data description]].
 +
 
 +
For this, select the '''Module''' first, then which '''Register'''.
 +
 
 +
==== Read ====
 +
To read, simply click the '''Read''' button. Successful read will be shown in green (CRC is ok) and logged, with extra info (e.g. for the DC prescaler, will give the motor frequency).
 +
 
 +
==== Write ====
 +
To write, enter a value in the value box such as:
 +
* Direct integer (only DC speed should be negative)
 +
* '''0b'''xxxx binary values
 +
* '''0x'''xxxx hexadecimal values
 +
* ''Other values will throw an error''
 +
 
 +
Then click on the '''Write''' button.
 +
 
 +
=== Reset ===
 +
In case of problem, you can simply power-cycle the FPGA board to reset the registers.
  
 
[[Category:Kart]]
 
[[Category:Kart]]

Revision as of 14:08, 4 July 2022

Contents

Serial link protocol

This section defines the serial link protocol used to communicate between the Kart and the BLE module / PC.

General principle

The system using a BLE module, the throughput is limited by design to a payload of 27 bytes each connection interval (from 7.5 ms to 4 s).

To avoid congesting the line, data are sent from the Kart to the User on specific events or if requested by the User.

Serial port

Communication is done with:

  • Resting state : HIGH
  • Data bits : 8
  • Parity : none
  • Stop bits : 1
  • Handshake : none
  • Baudrate : 115'200

Message Format

SoF (1 byte) Address (1 byte) Data (2 bytes) EoF (1 byte)
0xAA UINT8 UINT16/INT16/VECTOR16 (MSB first) CRC8/ITU

The address is decomposed as follows: 0bMMWRRRRR

  • MM : targeted module
    • 0b00 : DC Motor
    • 0b01 : Stepper Motor
    • 0b10 : Sensors
    • 0b11 : Control Registers
  • W : defines if the data is saved to ('1') or read from ('0') the FPGA
    • The FPGA will respond to a request with the exact same address when W = '0'
    • The FPGA will save incoming data in the targeted register when W = '1'
    • The FPGA will send data on predefined events with the W bit set to '1'
  • RRRRR : targeted register

Frame example

For the BLE module to light LED1 with it changing each 500 ms, the following frame is sent:

SoF (1 byte) Address (1 byte) Data High (1 byte) Data Low (1 byte) EoF (1 byte)
0xAA 0b10100001 0b10000001 0b11110100 0x74


When the stepper end switch is pressed, imagining that the desired position is reached in the meantime, the FPGA will send the following:

SoF (1 byte) Address (1 byte) Data High (1 byte) Data Low (1 byte) EoF (1 byte)
0xAA 0b01100011 0b00000000 0b00000011 0x47


If the BLE module wants to read the current battery voltage, supposing we have 4 LEDs, the frame is such as:

SoF (1 byte) Address (1 byte) Data High (1 byte) Data Low (1 byte) EoF (1 byte)
0xAA 0b10000101 Any Any CRC

The FPGA will then respond with something like (for a 11.998V reading):

SoF (1 byte) Address (1 byte) Data High (1 byte) Data Low (1 byte) EoF (1 byte)
0xAA 0b10000101 0x18 0x09 0x3D


Registers

DC Motor

Reading range : 0x00 to 0x1F

Writing range : 0x20 to 0x3F

Address Name Type Description Direction Event
0 Prescaler Uint16 DC PWM frequency, as fclk / (PWMsteps * prescaler) = 10M / (16 * prescaler) Smartphone -> Kart
1 Speed Int5 Desired speed, from -15 (0xFFF1) to 15 (0x000F) (negative = backward) Smartphone -> Kart


Stepper Motor

Reading range : 0x40 to 0x5F

Writing range : 0x60 to 0x7F

Address Name Type Description Direction Event
0 Prescaler Uint16 Stepper switching frequency, as 100k / prescaler Smartphone -> Kart
1 Target angle Uint16 Desired steering angle, in motor steps (0 = end switch) Smartphone -> Kart
2 Actual angle Uint16 Actual steering angle, in motor steps (0 = end switch) Kart -> Smartphone When a delta of at least STP_ANGLE_DELTA_DEG (10°) from the last registered value happens
3 Stepper HW Vector2 Bit 0: stepper end

Bit 1: position reached

Kart -> Smartphone Sent when stepper end is pressed (rising edge) or position reached (rising edge)


Sensors

Reading range : 0x80 to 0x9F

Writing range : 0xA0 to 0xBF

The sensors count may change based on the values given in the Kart -> Kart_Student_pkg. Thus, the registers addresses are based on the following definitions :

  • NB_LEDS : the number of LEDs / digital outputs used | NUMBER_OF_LEDS in the package
  • NB_ENDSW : the number of end switches / buttons used | NUMBER_OF_EXT_END_SWITCHES in the package
  • NB_HALL : the number of hall sensors used | NUMBER_OF_HALL_SENSORS in the package
  • NB_PROXI : the number of eproximity sensors used | NUMBER_OF_PROXIMITY_SENSORS in the package

Dialog-warning.png

Beware that the last address is not bigger than 31 !

Address Name Type Description Direction Event
0 Refresh proximity - Send anything to this register to refresh the proximity sensors Smartphone -> Kart
1 LED1 Bit + Uint15 Bit 15: on / off/

Bits 14 -> 0: half-period in ms (if 0, led status = bit 15)

Smartphone -> Kart
NB_LEDS LEDn Bit + Uint15 See LED1 Smartphone -> Kart
NB_LEDS + 1 Voltage Uint16 Battery voltage, U = register * 250*e-6 * 7.8 [V] Kart -> Smartphone When a delta of at least SENS_BATT_DELTA_MV (100) from the last registered value happens
NB_LEDS + 2 Current Uint16 Consumed current, I = register * 250*10*e-6 / (100 * 5*10*e-3) [A] Kart -> Smartphone When a delta of at least SENS_CURR_DELTA_MA (50) from the last registered value happens
NB_LEDS + 3 Range finder Uint16 Distance to sensor, register * 25.4 / (147*10*e-6 * (10M / 10)) [mm]

Register zeroed if less than 152 mm (sensor min distance) or greater than 1500 mm (arbitrary max distance), event not sent in such case

Kart -> Smartphone When a delta of at least SENS_RANGEFNDR_MM (100) from the last registered value happens
NB_LEDS + 4 End switches Vector(NB_ENDSW) Sensors current values, right justified (sensor 1 is bit 0) Kart -> Smartphone On any edge change of any sensor
NB_LEDS + 5 Hall1 Uint5 + Uint11 Uint5 (left justified) : number of 1/2 turns counted

Uint11 : time in steps of 4 ms

Kart -> Smartphone When a count of at least SENS_HALLCOUNT_HALF_TURN_DELTA (20) happens
NB_LEDS + NB_HALL + 4 Halln Uint5 + Uint11 See Hall1 Kart -> Smartphone See Hall1
NB_LEDS + NB_HALL + 5 Proxy1 Uint16 Proximity value in unknown unit (tests should be conducted, the highest the closest) Kart -> Smartphone When a delta of at least SENS_PROXI_DELTA (255) from the last registered value happens
NB_LEDS + NB_HALL + NB_PROXI + 4 Proxyn Uint16 See Proxy1 Kart -> Smartphone See Proxy1
NB_LEDS + NB_HALL + NB_PROXI + 5 Ambient1 Uint16 Ambient light, E = register * 250*10*e-3 [lx] (clear sensor cover) Kart -> Smartphone When a delta of at least SENS_AMBIENT_DELTA (255) from the last registered value happens
NB_LEDS + NB_HALL + 2* NB_PROXI + 4 Ambientn Uint16 See ambient1 Kart -> Smartphone See ambient1


Control Registers

Reading range : 0xC0 to 0xDF

Writing range : 0xE0 to 0xFF

Dialog-warning.png

The control registers module is WRITE ONLY for now !

Address Name Type Description Direction Event
0 Hardware Control Vector6 Bit 0: when '0', the Kart goes backwards when the motor turns foward

Bit 1: when '1', the Kart turns to the right as the stepper coils go from 1 to 4

Bit 2: when '1', the angles are measured clockwise

Bit 3: emulates the end switch contact for the stepper motor

Bit 4: restart the stepperMotor module, stops the DC motor while '1'

Bit 5: when '1', the BLE connection has been established (otherwise, the Kart should not be able to move)

Smartphone -> Kart The end sensor always defines angle 0. Angles are always positive numbers in registers.

If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted. If the Bluetooth connection is lost, the DC motor has to be stopped.



Sequence control register

The sequence control register is not yet re-implemented. The old behavior, kept for reference, is the following:

The sequence control register is used to load a new sequence from start of memory as well as to start and stop a sequence.

Bit Meaning Description
0 Reset sequence sets the sequence RAM write and read addresses back to 0
1 Run / stop starts or stops a sequence
Sequence operations register

The sequence memory is made out of 16-bit controls and the sequence can range up to 210 operations. From the communication point of view, the sequence memory is seen as a FIFO : the sequence operations are pushed one after the other into the sequence register, starting at the first one of the list after the reset sequence bit has been set in the control register

The sequence operations are split into 2 parts: a 4-bit command and optional parameters. A sequence register has been defined in order to build loops: the goto operation is only carried out if the register is not zero. The register is initialised with all bits to '1'.

command parameter comment
Bits 15 ÷ 12 11 ÷ 0
0 nop
1 set speed speed set the propulsion motor speed
2 set angle angle set the direction motor angle
3 drive LEDs pattern specify a given pattern for turning the LEDs on or off
4 set LEDs mask set bits from '1's of mask
5 clear LEDs mask clear bits from '1's of mask
6 blink LEDs period, mask not implemented yet
8 run distance hall ticks run until the Hall counter has augmented by at least a given tick number
9 run for milliseconds run for a specified time span
A run until event not implemented yet
D modify register operation, operand bits 11÷10 : 00 = set, 10 = add, 11 = sub / bits 9÷0 : operand
E goto nz address jumps to the specified sequence step as long as the register is not zero
F end the sequence controller in the FPGA stops and the running status bit is cleared, announcing that the sequence is terminated
Sequence status register

The sequence status register tells what operation is currently active.

Bit Meaning Description
15 ÷ 12 Current command indicates which command is currently being processed
0 Running indicates that a sequence is currently running

Kart init

To init the Kart, the following sequence should be sent to the Kart:

  • Write DC Motor | Prescaler to 31 (around 21 kHz PWM frequency)
  • Write Stepper Motor | Prescaler to 400 (250 Hz coil switching frequency)
  • Write Control Registers | Hardware Control to restart the system while telling the BLE client is connected (0b110xxx)
    • The stepper should turn until hitting the end switch, except if already on it
  • Read Stepper Motor | Stepper HW and check the last bit
    • If is '1', it means we are already zeroed
    • If not, wait for an event from this register to tell the reset is complete
  • Write Control Registers | Hardware Control to deassert the reset (0b100xxx)

The Kart is now ready to function !

Testing through USB

Kart Command Interpreter

To test the Kart from a PC directly, one can do as follows:

  • Remove the BLE from the motherboard
  • Power the motherboard with a DC voltage regulator (+12V)
  • Wire the USB-C present on the daughterboard to your PC
    • Two new COM ports should be detected
  • Download and open the Kart Command Interpreter utility (available in the VHDL project -> CommandInterpreter)
  • In the top menu Serial -> Port, select the correct COM port (should be the biggest of the two new ports)
    • You can also change the baudrate, by default 115'200 (the correct one if it was not modified in the VHDL Kart_pkg.vhd

To test the connection, click the Read button. The Tx and Rx values should change, and a text added to the text area.

Simple operation

The simplest way to test both motors are the three button at the bottom.

  • Init Kart button
    • Will set the DC prescaler, stepper prescaler, and execute the restart sequence. Must be clicked first.
    • You may need to modifiy the CReg -> HW Control register to correspond to your Kart design. Only change x in the following value: 0b100xxx
  • DC Motor button
    • Will set the DC speed to full for 2s, quickly 0, then reversed full speed for 2s
  • Stepper Motor button
    • Will set the stepper to 800 then 0

Custom operation

Each register can be read and/or written by hand following their data description.

For this, select the Module first, then which Register.

Read

To read, simply click the Read button. Successful read will be shown in green (CRC is ok) and logged, with extra info (e.g. for the DC prescaler, will give the motor frequency).

Write

To write, enter a value in the value box such as:

  • Direct integer (only DC speed should be negative)
  • 0bxxxx binary values
  • 0xxxxx hexadecimal values
  • Other values will throw an error

Then click on the Write button.

Reset

In case of problem, you can simply power-cycle the FPGA board to reset the registers.

Personal tools
Namespaces
Variants
Actions
Navigation
Modules / Projects
Browse
Toolbox