Answered step by step
Verified Expert Solution
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
INTRODUCTION:
In this week's tutorial you will use TCA and ADC You will use these
peripherals to control the brightness of the 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
EX:
TASK: Write a function named pwminit" which will configure TCA to
produce a
X HzY 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 n then you should configure
TCA to produce a
Hz duty cycle output on the DISP EN net.
CODE: Write your code for Ex above this line.
EX:
TASK: Write a function named "adcinit" below which will configure
ADC in bit single conversion mode.
The ADC should be configured to sample the voltage on the POT net, be
placed in freerunning mode, and start sampling immediately.
CODE: Write your code for Ex above this line.
int mainvoid
Variable to store the result of the ADC conversion
uintt result;
serialinit;
PORTA.DIRSET PINbm;
PORTA.PINCTRL PORTPULLUPENbm;
EX:
TASK: Call the two initialisation functions you have written above
such that the TCA and ADC are enabled and operational.
On completion of this exercise, the segment display should show
a dimly lit on the RHS
You can then test your ADC configuration via the serial terminal
using the instructions below.
CODE: Write your code for Ex above this line.
printfTurn the potentiometer R fully counterclockwise, then press S
;
while VPORTAIN & PINbm; result ADCRESULT; printfEx : result xX expected x
result;
printfTurn the potentiometer R fully clockwise, then press S
;
while VPORTAIN & PINbm; result ADCRESULT; printfEx : result xX expected xFF
result;
printfTurn the potentiometer R to the halfway position, then press S
;
while VPORTAIN & PINbm; result ADCRESULT; printfEx : result xX expected x
result;
Main loop
while
EX:
TASK: Write code below such that the position of the
potentiometer controls the brightness of the segment display
in reverse.
The display should be:
fully bright when the potentiometer is turned fully counterclockwise
fully dim when the potentiometer is turned fully clockwise
NOTE: ADCRESULT yields a value of when the potentiometer is
turned fully counterclockwise, and a value of when turned
fully clockwise.
You will need to reverse this range of values using a
mathematical expression to achieve the desired functionality.
HINTS:
Scale the bit value from ADCRESULT to a value between
and the TOP value of TCA
Reverse the direction of the potentiometer by subtracting the
scaled value from the TOP value of TCA
Alternatively,
Reverse the direction of the potentiometer by subtracting the
bit value from ADCRESULT from
Scale the reversed value to a value between and the TOP
value of TCA
TIPS:
Avoid floatingpoint 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 above this line.
EX:
TASK: Write code below to drive the buzzer when the
potentiometer's position is between and where
is fully CCW and is fully CW
When the pot position is outside of this range the buzzer should
be silent.
The buzzer should be driven with a:
duty cycle square wave when active
duty cycle square wave when inactive
TIP: You will need to modify the code in pwminit to achieve
this functionality.
NOTE: The buzzer will produce the frequency specified in Ex
CODE: Write your code for Ex above this line.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started