Search for question
Question

Supposed you are tasked to build a simple carbon monoxide sensor that functions in the following way:

1. Measure the CO2 sensor, which gives an analog output of 0 to 1.0V

2. A value of more than 0.5V represents a dangerous level of CO2 (0.0V means no CO2)

3. In the case of a dangerous condition, an alert must be given in the form of illuminating an

external LED connected to any GPIO pin.

4. The sampling rate of the sensor must be 1kHz.

5. Use must use an ATTINY84 Microcontroller, which is also an 8-bit AVR processor similar (but

different) to our 32u4 (datasheet attached).

1. Take a few minutes to review the datasheet to familiarize yourself with the available GPIO pins,

available timers, and ADC setup. Review the address mappings in section 22 as well. For this part of

the exam, you can not use known registers like PORTB etc. You must use unsigned char pointers to

the correct addresses.

2. Write a function called void SetupTimer() that sets up any timer to function as a 1kHz timer (no

PWM generation, no pins connected). The timer should reset every 1ms. Be sure to set up the

appropriate registers in section 11.9 of the datasheet.

3. Write a function called void SetupLED() which sets up the selected GPIO pin (you can select any

appropriate pin) for the LED alert.

4. Write a function called void SetupADC() which sets up the ADC to the appropriate MUX channel (you

can choose any one you want). Set up the ADC to use a prescaler of 16, and use your timer overflow

as an Auto Trigger Source for the ADC. See section 16.13.4 (Table 16.7)

5. Write the setup function that calls your functions described above.

6. Write the loop function that reads the ADC and performs the logic to illuminate the LED

appropriately. Don't make the LED flicker if the ADC hovers around 0.5V!

7. Sketch the schematic that shows which pins you used and the interconnect diagram of the LED,

ATTINY, and the CO2 sensor.

8. Now, using Platform IO, start a new project and use the board "Generic ATTINY84". Import the code

you developed in 1. through 7., but now you can use the defined registers like PORTA etc. Submit

the .cpp file with your code.