Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include qutyserial.h / * * Tutorial 0 8 INTRODUCTION: In this week's tutorial you will use TCA 0 and ADC 0

#include
#include
#include
#include "qutyserial.h"
/** Tutorial 08
INTRODUCTION:
In this week's tutorial you will use TCA0 and ADC0. You will use these
peripherals to control the brightness of the 7-segment display, produce
a tone from the buzzer, and read the position of the potentiometer.
Interfacing with these hardware devices on the QUTy is a core
requirement for Assessment 2.
*/
/** EX: 8.0
TASK: Write a function named "pwm_init" which will configure TCA0 to
produce a
3X0 Hz,1Y % duty cycle output on the DISP EN net
where XY are the last two digits of your student number.
Your function should take no arguments and return no values.
EXAMPLE: If your student number was n12345678 then you should configure
TCA0 to produce a
370 Hz,18% duty cycle output on the DISP EN net.
*/
/** CODE: Write your code for Ex 8.0 above this line. */
/** EX: 8.1
TASK: Write a function named "adc_init" below which will configure
ADC0 in 8-bit single conversion mode.
The ADC should be configured to sample the voltage on the POT net, be
placed in free-running mode, and start sampling immediately.
*/
/** CODE: Write your code for Ex 8.1 above this line. */
int main(void)
{
// Variable to store the result of the ADC conversion
uint8_t result;
serial_init();
PORTA.DIRSET = PIN1_bm;
PORTA.PIN7CTRL = PORT_PULLUPEN_bm;
/** EX: 8.2
TASK: Call the two initialisation functions you have written above
such that the TCA0 and ADC0 are enabled and operational.
On completion of this exercise, the 7-segment display should show
a dimly lit 8 on the RHS.
You can then test your ADC configuration via the serial terminal
using the instructions below.
*/
/** CODE: Write your code for Ex 8.2 above this line. */
printf("Turn the potentiometer R1 fully counter-clockwise, then press S4.
");
while (VPORTA.IN & PIN7_bm); result = ADC0.RESULT0; printf("Ex 8.2.0: result =0x%02X, expected =0x00
", result);
printf("Turn the potentiometer R1 fully clockwise, then press S4.
");
while (VPORTA.IN & PIN7_bm); result = ADC0.RESULT0; printf("Ex 8.2.1: result =0x%02X, expected =0xFF
", result);
printf("Turn the potentiometer R1 to the half-way position, then press S4.
");
while (VPORTA.IN & PIN7_bm); result = ADC0.RESULT0; printf("Ex 8.2.2: result =0x%02X, expected =0x80
", result);
// Main loop
while (1)
{
/** EX: 8.3
TASK: Write code below such that the position of the
potentiometer controls the brightness of the 7-segment display
in reverse.
The display should be:
- fully bright when the potentiometer is turned fully counter-clockwise
- fully dim when the potentiometer is turned fully clockwise
NOTE: ADC0.RESULT yields a value of 0 when the potentiometer is
turned fully counter-clockwise, and a value of 255 when turned
fully clockwise.
You will need to reverse this range of values using a
mathematical expression to achieve the desired functionality.
HINTS:
1. Scale the 8-bit value from ADC0.RESULT to a value between 0
and the TOP value of TCA0.
2. Reverse the direction of the potentiometer by subtracting the
scaled value from the TOP value of TCA0.
Alternatively,
1. Reverse the direction of the potentiometer by subtracting the
8-bit value from ADC0.RESULT from 255.
2. Scale the reversed value to a value between 0 and the TOP
value of TCA0.
TIPS:
- Avoid floating-point arithmetic by using integer
approximations.
- Some integer operations should be performed before others to
prevent loss of precision.
- Recall type conversion rules when using arithmetic operators.
*/
/** CODE: Write your code for Ex 8.3 above this line. */
/** EX: 8.4
TASK: Write code below to drive the buzzer when the
potentiometer's position is between 87.5% and 100%, where 0%
is fully CCW and 100% is fully CW.
When the pot position is outside of this range the buzzer should
be silent.
The buzzer should be driven with a:
-50% duty cycle square wave when active
-0% duty cycle square wave when inactive
TIP: You will need to modify the code in pwm_init() to achieve
this functionality.
NOTE: The buzzer will produce the frequency specified in Ex 8.0.
*/
/** CODE: Write your code for Ex 8.4 above this line. */
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

5. Save raster im?

Answered: 1 week ago