...
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 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 |
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:
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:
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 Device | Pin |
---|---|
Power | PC0 |
Gas Pedal | PC1 |
Direction Selector | PC2 - PC3 |
Cruise Control | PC4 |
Cruise Control Increase | PC5 |
Cruise Control Decrease | PC6 |
Turn Signal | PB7 - PB8 |
Hazard Light Switch | PB9 |
Hazard Light | PC10 |
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).
...