Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Description

The STM32 has a 12-bit onboard 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 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

Usage


Analog-to-digital conversion of the different channels The ADC does conversions in groups of selected channels. Each conversion can be performed both in either single mode, in which the ADC converts all the channels at once in the group in one single sequence of conversions, and continuous mode, where the device automatically restarts the scan after converting all finishing the sequence, resulting in a nonstop conversion of the different input channels. The 12-bit value obtained from the each conversion will be stored in the ADC read-only data register (ADC_DR).

The following formula can be used to determine the ADC reading:

Image Removed

The Additionally, the sequence of channels to convert is defined in the ADC's 32-bit Channel Selection register (ADC_CHSELR), which contains a series of selection bits corresponding to each analog input channel. By using this register, it is possible to select the set of channels to be converted by the ADC, making it useful for when you want to convert either a single channel or a specific set of them. 

The following formula is used to determine the ADC reading:

Image Added


Driver Inputs

SMT32F0 Interrupts

...

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.

Pin Assignments

Input DevicePin
PowerPC0
Gas PedalPC1
Direction SelectorPC2 - PC3
Cruise ControlPC4
Cruise Control IncreasePC5
Cruise Control DecreasePC6
Turn SignalPB7 - PB8
Hazard Light SwitchPB9
Hazard LightPC10


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 a common ISR (for the prototype, we will collect information on the gas pedal through polling).

...