Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify function for this Lab Goal is to read analog voltage. Use the value to set the duration of the LED on the LauchPad On.

Modify function for this Lab

Goal is to read analog voltage. Use the value to set the duration of the LED on the LauchPad On.

When done, all functions and code unrelated to this goal should be deleted. Comments at top should only be a few line related to this lab and include your name.

Make 2 global variables in (near top above main), both integer (int) called ledPeriod and ledPulseWidth. Set initial value of ledPeriod to 0x3ff, and ledPulseWidth to be 0x0

In the infinite loop in main (while), delete any code and replace as follows.

Turn the LED ON (P1.0)

Delay by counting up to ledPulseWidth

Turn the LED OFF

Calculate a new integer called remainPeriod by subtracting ledPulseWidth from ledPeriod (the goal is constant blink period with variable time ON).

Delay by counting up to remainPeriod.

In the ADC Interrupt Handler, find the curADCResult variable. Divide by 0x10 (goal is a fast blinking rate, so fast the eye cannot really detect, but will result in perception of bright-to-dim) and set the resulting value to ledPulseWidth.

Compile, Run. Repeat the same test as with the demo code. Ensure the hex value changes when pause the program at the line of code. When running and input 3V3, the LED should appear bright. When input GND, the LED should appear almost OFF (maybe tiny).

If works, then make potentiometer (pot) circuit to vary input value between 0 V to 3 V.

Outside pins of pot go to 3V3 and GND. The middle pin of pot is the analog value, wire to P5.5

When running, the LED should gradually brighten (as voltage rises) or dims (as voltage decreases).

Ensure code

Has unrelated code (from the original demo) deleted

Find all the code related to floating point calculations (FPU). We did not use this, so delete all FPU and floating point code.

After delete code, run again to ensure function still works.

Is professionally indented and commented

Has proper header comments (just a few lines) at top

MY CODE:

#include

/* Standard Includes */

#include

#include

#include

/* Statics */

static volatile uint16_t curADCResult;

static volatile float normalizedADCRes;

int main(void)

{

/* Halting the Watchdog */

MAP_WDT_A_holdTimer();

/* Initializing Variables */

curADCResult = 0;

/* Setting Flash wait state */

MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);

MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);

/* Setting DCO to 48MHz */

MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1);

MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);

/* Enabling the FPU for floating point operation */

MAP_FPU_enableModule();

MAP_FPU_enableLazyStacking();

//![Single Sample Mode Configure]

/* Initializing ADC (MCLK/1/4) */

MAP_ADC14_enableModule();

MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4,

0);

/* Configuring GPIOs (5.5 A0) */

MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,

GPIO_TERTIARY_MODULE_FUNCTION);

/* Configuring ADC Memory */

MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);

MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,

ADC_INPUT_A0, false);

/* Configuring Sample Timer */

MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);

/* Enabling/Toggling Conversion */

MAP_ADC14_enableConversion();

MAP_ADC14_toggleConversionTrigger();

//![Single Sample Mode Configure]

/* Enabling interrupts */

MAP_ADC14_enableInterrupt(ADC_INT0);

MAP_Interrupt_enableInterrupt(INT_ADC14);

MAP_Interrupt_enableMaster();

while (1)

{

MAP_PCM_gotoLPM0();

}

}

//![Single Sample Result]

/* ADC Interrupt Handler. This handler is called whenever there is a conversion

* that is finished for ADC_MEM0.

*/

void ADC14_IRQHandler(void)

{

uint64_t status = MAP_ADC14_getEnabledInterruptStatus();

MAP_ADC14_clearInterruptFlag(status);

if (ADC_INT0 & status)

{

curADCResult = MAP_ADC14_getResult(ADC_MEM0);

normalizedADCRes = (curADCResult * 3.3) / 16384;

MAP_ADC14_toggleConversionTrigger();

printf ("The new Hex value is %x ", curADCResult );

}

}

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

More Books

Students also viewed these Databases questions

Question

1. Explain how new technologies are influencing training.

Answered: 1 week ago