Answered step by step
Verified Expert Solution
Link Copied!

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 MSP-EXP430FR5994 and the LaunchPadBOOSTXL-EDUMKII 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:
6. 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
7. Modify the code in step 6 to use the joystick to vary the tone (i.e., 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 JOYSTICk_THRESHOLD 2000
#define MAX_FREQUENCY 10000// Maximum frequency of the buzzer
#define MIN_FREQUENCY 1000// Minimum frequency of the buzzer
#define MAX_VOLUME 1000// Maximum volume (duty cycle) of the buzzer
void MAKEADC()
{
//Configuring ADC Pins for Lab
//Configure Joystick
//Set P3.3, P1.2 as ADC inputs
P3SEL0|= BIT3;
P3SEL1|= BIT3;
P1SEL0|= BIT2;
P1SEL1|= BIT2;
//Configure Pushbutton
//Set P6.2 as ADC input
P6SEL0|= BIT2;
P6SEL1|= BIT2;
P5REN = ~(BIT5 & BIT6);// Enable pull-up/pull-down resistor for P5.6 and P5
P5OUT = ~(BIT5 & BIT6);// Set pull-up resistor for P5.6 and P5.5
//Configure RGB Led
//Set P3.4, P3.5, P3.6 outputs
P3DIR |= BIT4|BIT5|BIT6;
P3OUT &= ~BIT4|BIT5|BIT6;//Clear Output
//Configure Buzzer
//Set P3.7 as ADC input
P3DIR |= BIT7;
P3SEL0|= BIT7;
P3SEL1 &= BIT7;
P3OUT &= BIT7;
// Configure ADC settings
ADC12CTL0 &= ~ADC12ENC; // turn off ADC before change
ADC12CTL0= ADC12SHT0_12| ADC12ON; // sample-and-hold time and turn
ADC12CTL1= ADC12SHP; // sample timer
ADC12CTL2|= ADC12RES_2; // Set ADC resolution to 12-bit
ADC12MCTL0= ADC12INCH_14; // Select A0 pin as ADC input for x coordinate
ADC12MCTL1= ADC12INCH_15| ADC12EOS; // Select A1 pin .as ADC input for
//ADC12MCTL2= ADC12INCH_14; // Select A2 pin as ADC input for z coordinate
ADC12IER0|= ADC12IE0| ADC12IE1; // Enable ADC conversions
ADC12CTL0|= ADC12ENC; // Enable ADC after configuration
}
unsigned int readADC(unsigned int a)
{
ADC12CTL0 &= ~ADC12ENC; // Disable ADC before reading
ADC12MCTL0=(a |0x0C);// Configure register for the specified channel
ADC12CTL0|= ADC12ENC | ADC12SC;// Enable ADC and start conversion
while (ADC12CTL1 & ADC12BUSY); // Wait for conversion to complete
return ADC12MEM0; // Return conversion result
}
void configurePWM(unsigned int volume, unsigned int frequency)
{
// Configure Timer A0 for PWM generation
TA0CCR0= frequency; // Set frequency
TA0CCR1= volume; // Set duty cycle (volume)
TA0CCTL1= OUTMOD_7; // Reset/Set mode for PWM
TA0CTL = TASSEL_2+ MC_1; // SMCLK, Up mode
}
int main(void){
// Stop watchdog timer
WDTCTL = WDTPW | WDTHOLD;
PM5CTL0 &= ~LOCKLPM5;// Disable the GPIO power-on default high-impedance mode
printf("HELLO");
P3OUT &= ~(BIT4|BIT5|BIT6);// Turn off RGB LEDs
// Initialize ADC for accelerometer reading
MAKEADC();
// Initialize Timer A0 for PWM output to the buzzer
TA0CTL = TASSEL_2+ MC_0; // SMCLK, Stop mode
TA0CCR0= MAX_FREQUENCY; // Set initial frequency to maximum
TA0CCR1=0; // Set initial volume (duty cycle) to 0
TA0CCTL1= OUTMOD_7; // Reset/Set mode for PWM
// Main loop
while (1){
// Read accelerometer data from ADC
unsigned int xvalue = readADC(ADC12INCH_14);
unsigned int yvalue = readADC(ADC12INCH_15);
//unsigned int zvalue = readADC(2);
//printf("x%d
", xvalue);
//printf("y%d
", yvalue);
// Adjust volume based on joystick position
unsigned int volume =(yvalue * MAX_VOLUME)/4095;
unsigned int frequency =0;
// Adjust frequency based on joystick position
//unsigned int frequency = MIN_FREQUENCY +(xvalue *(MAX_FREQUENCY - MIN_FREQUENCY))/4095;
// Configure PWM signal for buzzer
//configurePWM(volume, frequency);
if (!(P5IN & BIT6)/ if button connected to P5.6 is pressed/ only works if pressed
{
P3OUT |= BIT6;//RED on
P3OUT &= ~BIT5;//GREEN off
P3OUT &= ~BIT4;//BLUE off
frequency = MIN_FREQUENCY;
}
else if (xvalue <2000)
{
printf("
");
printf("Joystick LEFT
");
//printf("%d
",xvalue);
P3OUT |= BIT4;// led on
P3OUT &= ~BIT5; // led off for RIGH
frequency =2000;
}
else if (xvalue >3000)
{
printf("Joystick RIGHT");
//printf("%d",xvalue);
P3OUT|= BIT5;// led on
frequency=4000;
}

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago