Finite State Machine
The program will be controlled through the use of multiple Finite State Machines to ensure that inputs are only serviced at the appropriate periods. The system will use three state machines to :
Pedal State Machine:
This state machine governs the running state of the car and defines the conditions under which the driver can turn on and move the vehicle. Transitions for this FSM depend on the state of the directional state machine.
State | Description |
---|---|
Off | The vehicle is not receiving power |
Idle | The car is on, but no pedals are pressed |
Driving | The gas pedal is pressed car is in motion. |
Brake | The brakes are engaged and the car is not moving |
Directional State Machine
Governs the possible gear shifts made by the user.
State | Description |
---|---|
Neutral | The vehicle is in neutral gear |
Forward | The vehicle is in forward gear |
Reverse | The vehicle is in reverse |
Turn Signal State Machine
Governs the states of the turn signals made by the driver. Independent from the other FSMs.
State | Description |
---|---|
No signal | The car is currently not signalling |
Left signal | The car has the left signal active |
Right signal | The car has the left signal active |
ADC Driver
On the STM32 is a 12-bit analog-to-digital converter (ADC). The role of an ADC is to take an analog signal as an input and give as output a digital number proportional to the magnitude of the input signal. The following formula can be used to determine the ADC reading:
The ADC on the STM32 has 19 multiplexed channels, allowing it to read signals from 16 external sources and 3 internal sources. The pin mappings for the 16 external sources are included below:
ADC Channel | Pin Name |
---|---|
ADC_IN0 | PA0 |
ADC_IN1 | PA1 |
ADC_IN2 | PA2 |
ADC_IN3 | PA3 |
ADC_IN4 | PA4 |
ADC_IN5 | PA5 |
ADC_IN6 | PA6 |
ADC_IN7 | PA7 |
ADC_IN8 | PB0 |
ADC_IN9 | PB1 |
ADC_IN10 | PC0 |
ADC_IN11 | PC1 |
ADC_IN12 | PC2 |
ADC_IN13 | PC3 |
ADC_IN14 | PC4 |
ADC_IN15 | PC5 |
Analog-to-digital conversion of the different channels can be performed both single mode, in which the ADC converts all the channels at once in a single sequence of conversions, and continuous mode, where the device automatically restarts the scan after converting all of the different channels. The 12-bit value obtained from the conversion will be stored in the ADC read-only data register (ADC_DR).
Driver Inputs
SMT32F0 Interrupts
Interrupts on the SMT32 are managed by the extended interrupts and events controller (EXTI), which allows for the management of up to 32 different interrupt lines (23 external and 9 internal). Each line can have its own active edge and interrupt priority programmed independently. For each input
Handling Inputs
Each of the driver control inputs will be connected to the onboard GPIO pins. As we are only concerned with handling each input as they are triggered, they are all set to be handled by interrupt service routine.