programming

programming

• Use the sample example ADC project file as a starting point. You can re-use the same project for all these exercises by replacing the ‘C’ files. Remove the previous ‘C’ file and add the new ‘C’ file. Removing a file from a project does not delete the file!
• Layout your program neatly – look at the layout in the example programs and read the C style guide for further guidance.
• You will be required to demonstrate the example lab questions you have completed as part of the assessment for the module, make sure you save the c source file for each question separately.
ADC Lab questions

Q1 Connect an external potentiometer between 3V and GND on the STM32F4 discovery baord and feed the wiper output (Vout) into a suitable ADC input on the microcontroller (see diagram below). The potentiometer should generate a voltage from 0 to +3 volts to simulate a sensor signal.
Download the example ADC program and alter the value of the potentiometer – what’s happening in your program. Confirm the correct conversion is taking place using a DMM.
Q2 Save the example program as a new source file and add it to your project (remember to remove the old file). Modify the program to do the following:

Read the input voltage from the pot every 50ms

If the input voltage is < =1V switch on the Green LED
If the input voltage is > 1V & < 2 switch on the Red LED
If the input voltage is >= 2 switch on the Blue LED
Q3 Assume that the input to the ADC channel is from a temperature sensor which generates 0 to 3 volts for the temperature range 0 ºC to 100 ºC. Modify the program to print out the temperature in degrees centigrade. Calculate the resolution of your temperature value and print it out to an appropriate number of decimal places. Remember the ADC is 12-bit and the ADC reference voltages are????? .
Q4 Copy the first Binky example program and modify it so that the delay is determined by the analogue input on ADC. This will enable the speed of the flashing LED sequence to be modified while the program is executing by turning the potentiometer connected to ADC.

READ ALSO :   FAITH ESSAY

A number of the pins can be used as analogue I/O for full details see the excel spread sheet Kornak-(STM32-Discovery-F4)-0001 Rev n.nn Module Pinouts & Functions.xls and/or use the datasheet for the chip.

Below are some suggested pins where the alternate functions are primarily for the more complex peripherals (Ethernet & USB) and which will probably not be used. These therefore make ideal ADC inputs.

STM32F4 Pin Discovery F4 Pin LQFP100 Pin Name and Function
PB0 P1.22 35 PB0-ADC12_IN8
PB1 P1.21 36 PB1-ADC12_IN9
PC1 P1.7 16 PC1-ADC123_IN11
PC2 P1.10 17 PC2-ADC123_IN12
PC4 P1.20 33 PC4-ADC12_IN14
PC5 P1.19 34 PC5-ADC12_IN15