Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

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.

StateDescription

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.
BrakeThe brakes are engaged and the car is not moving

Directional State Machine

Governs the possible gear shifts made by the user.

StateDescription
NeutralThe vehicle is in neutral gear
ForwardThe vehicle is in forward gear
ReverseThe vehicle is in reverse

Turn Signal State Machine

Governs the states of the turn signals made by the driver. Independent from the other FSMs.

StateDescription
No signalThe car is currently not signalling
Left signalThe car has the left signal active
Right signalThe 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 ChannelPin Name
ADC_IN0PA0
ADC_IN1PA1
ADC_IN2PA2
ADC_IN3PA3
ADC_IN4PA4
ADC_IN5PA5
ADC_IN6PA6
ADC_IN7PA7
ADC_IN8PB0
ADC_IN9PB1
ADC_IN10PC0
ADC_IN11PC1
ADC_IN12PC2
ADC_IN13PC3
ADC_IN14PC4
ADC_IN15PC5

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 both its active edge and interrupt priority programmed independently.

In order to generate an interrupt for an external line, the line must be configured. To do this, the bit in the interrupt mask register (EXTI_IMR) corresponding to the interrupt line must be set to '1', along with the corresponding bits in the desired edge trigger registers (Should an interrupt be triggered on a high-to-low or low-to-high change?), which are EXTI_RTSR and EXTI_FTSR for rising and falling edges respectively. Once this is done, an interrupt request will be generated once the selected edge appears on the external interrupt line and the pending bit corresponding to said interrupt line will be set. The STM32 will clear this bit automatically once the ISR concludes. 

The STM32 has the first 16 external interrupt lines set aside for the GPIOs, meaning that there are only 16 digital interrupts available for use on the STM32. The GPIOs are mapped to the external interrupt lines as follows:

This means that only one port can have have an interrupt enabled for a given pin number at a time. For instance, enabling interrupt on PA0 will preclude the enabling of interrupts for pin 0 of any other port.

Handling input requests

The driver control inputs will be connected to onboard GPIOs. As we are only concerned with handling each input as they are triggered, most of the inputs will be set to be handled through the use of interrupts (for the prototype, we will collect information on the gas pedal through polling). all set to be handled by interrupt service routine. 

  • No labels