Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Im using MSP - EXP 4 3 0 FR 5 9 9 4 and the LaunchPadBOOSTXL - EDUMKII with Code Composier Studio. Im haveing trouble
Im using MSPEXPFR and the LaunchPadBOOSTXLEDUMKII with Code Composier Studio. Im haveing trouble getting the Piezo buzzer working, right now im getting nothing from the buzzer, it should complete these two objectives:
Configure the ADC results from either the vertical or horizontal joystick positions to create a variable PWM signalfrom a compare mode timer output that outputs to buzzer. Observe the effects of the joystick on the volume
Modify the code in step to use the joystick to vary the tone ie frequency of the buzzer as well as the volume.
Currently the code changes the RGB collor depending on the joystick postion, with the changes need to be made is making the buzzer work.
My Current Code:
#include
#include
#define JOYSTICkTHRESHOLD
#define MAXFREQUENCY Maximum frequency of the buzzer
#define MINFREQUENCY Minimum frequency of the buzzer
#define MAXVOLUME Maximum volume duty cycle of the buzzer
void MAKEADC
Configuring ADC Pins for Lab
Configure Joystick
Set P P as ADC inputs
PSEL BIT;
PSEL BIT;
PSEL BIT;
PSEL BIT;
Configure Pushbutton
Set P as ADC input
PSEL BIT;
PSEL BIT;
PREN ~BIT & BIT; Enable pulluppulldown resistor for P and P
POUT ~BIT & BIT; Set pullup resistor for P and P
Configure RGB Led
Set P P P outputs
PDIR BITBITBIT;
POUT & ~BITBITBIT;Clear Output
Configure Buzzer
Set P as ADC input
PDIR BIT;
PSEL BIT;
PSEL & BIT;
POUT & BIT;
Configure ADC settings
ADCCTL & ~ADCENC; turn off ADC before change
ADCCTL ADCSHT ADCON; sampleandhold time and turn
ADCCTL ADCSHP; sample timer
ADCCTL ADCRES; Set ADC resolution to bit
ADCMCTL ADCINCH; Select A pin as ADC input for x coordinate
ADCMCTL ADCINCH ADCEOS; Select A pin as ADC input for
ADCMCTL ADCINCH; Select A pin as ADC input for z coordinate
ADCIER ADCIE ADCIE; Enable ADC conversions
ADCCTL ADCENC; Enable ADC after configuration
unsigned int readADCunsigned int a
ADCCTL & ~ADCENC; Disable ADC before reading
ADCMCTLa xC; Configure register for the specified channel
ADCCTL ADCENC ADCSC; Enable ADC and start conversion
while ADCCTL & ADCBUSY; Wait for conversion to complete
return ADCMEM; Return conversion result
void configurePWMunsigned int volume, unsigned int frequency
Configure Timer A for PWM generation
TACCR frequency; Set frequency
TACCR volume; Set duty cycle volume
TACCTL OUTMOD; ResetSet mode for PWM
TACTL TASSEL MC; SMCLK Up mode
int mainvoid
Stop watchdog timer
WDTCTL WDTPW WDTHOLD;
PMCTL & ~LOCKLPM; Disable the GPIO poweron default highimpedance mode
printfHELLO;
POUT & ~BITBITBIT; Turn off RGB LEDs
Initialize ADC for accelerometer reading
MAKEADC;
Initialize Timer A for PWM output to the buzzer
TACTL TASSEL MC; SMCLK Stop mode
TACCR MAXFREQUENCY; Set initial frequency to maximum
TACCR; Set initial volume duty cycle to
TACCTL OUTMOD; ResetSet mode for PWM
Main loop
while
Read accelerometer data from ADC
unsigned int xvalue readADCADCINCH;
unsigned int yvalue readADCADCINCH;
unsigned int zvalue readADC;
printfxd
xvalue;
printfyd
yvalue;
Adjust volume based on joystick position
unsigned int volume yvalue MAXVOLUME;
unsigned int frequency ;
Adjust frequency based on joystick position
unsigned int frequency MINFREQUENCY xvalue MAXFREQUENCY MINFREQUENCY;
Configure PWM signal for buzzer
configurePWMvolume frequency;
if PIN & BIT if button connected to P is pressed only works if pressed
POUT BIT;RED on
POUT & ~BIT;GREEN off
POUT & ~BIT;BLUE off
frequency MINFREQUENCY;
else if xvalue
printf
;
printfJoystick LEFT
;
printfd
xvalue;
POUT BIT; led on
POUT & ~BIT; led off for RIGH
frequency ;
else if xvalue
printfJoystick RIGHT";
printfdxvalue;
POUT BIT; led on
frequency;
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