Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

On a TI MSP432 board (with a 48 MHz crystal), study the \"Clock system\" and \"T

ID: 3812758 • Letter: O

Question

On a TI MSP432 board (with a 48 MHz crystal), study the "Clock system" and "Timer_A" sections of the MSP432P4xx Reference Manual. For the following two problems you must use the microcontroller registers directly without using the TI driver library functions. Do not use any interrupt unless necessary. In each problem, you must use time_A and have to clearly identify in your comments the clock resources, the clock signals, the prescaler (if any), and the final clock frequency to timer_A. write a C function, delay_one_min(void), with suitable comments. The function, when called, would block for one minute. Write a C function, generate_PWM(void), with suitable comments that would produce a 1 KHz, 25% duty cycle PWM waveform on a digital I/O pin. Clearly identify the pin your code uses.

Explanation / Answer

1ANS:

#include <REG52.h> // include reg52.h

void delay_one_min(void); // one min functn

void main(void){ // main

// while

while (1)

{

// p1

P1=0x55;

// function

delay_one_min();

// p1

P1=0xAA;

delay_one_min();

}

}

void delay_one_min(){

TMOD=0x01; // timer_0 & mode_1

TL0=0x00; // loads_TL0

TH0=0x35; // loads_TH0

TR0=1; // turns on the Timer0

while (TF0==0); // wait for the TF_0 to roll_over

TR0=0; // turn off the timer

TF0=0; // clear the TF_0

}

////////////

2ANS.

// generate pwm signl

#define GENERATE_PWM

// ifdef

#ifdef GENERATE_PWM

//rate

#define PWM_RATE 250 //PWM rate

#define SCT_PIN_OUT 3 //output_pin

#define SCT_INDEX 1 //SCT match_register

// funct sct2

void SCT2_init(void)

{

// chip init

Chip_SCTPWM_Init(LPC_SCT2); //init SCT2

// setrate

Chip_SCTPWM_SetRate(LPC_SCT2, PWM_RATE);//set cycle (in SCT Match0 register)

// enable_peripheral_clock

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);//enable SWM

// enanle fixed pin

Chip_SWM_EnableFixedPin(SWM_FIXED_SCT2_OUT3); //switch_outpt: SCT2OUT3 = PIO0_6

// SetuoutputPin

Chip_SCTPWM_SetOutPin(LPC_SCT2, SCT_INDEX, SCT_PIN_OUT);//setoutput

// setdutycycle

Chip_SCTPWM_SetDutyCycle(LPC_SCT2, SCT_INDEX, LPC_SCT2->MATCHREL[0].U/3);//set duty

// Start

Chip_SCTPWM_Start(LPC_SCT2); //start

}

//endif

#endif

void SCT0_IRQHandler(void)

{

if(LPC_SCT0->EVFLAG & SCT_EVT_1 ) //event?

{

Board_LED_Toggle(0); //toggle LED

valid =1; //set valid flag

LPC_SCT0->EVFLAG = SCT_EVT_1; //reset event

} //end event

}

//Sys_Tick_interrupt

// handler

void SysTick_Handler(void)

{

// ticks

ticks++;

// 2nd timer

if(ticks >= 10)

{

// reset ticks

ticks =0;

// sec

sec =1;

// end toggle

Board_LED_Toggle(0);

}

}

void SCT0_init(void)

{

//input capture PIO0_17

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_MODE_PULLDOWN));

Chip_SCT_Init(LPC_SCT0);

//unified 32bit counter, SYNC all inputs, enable prescaler in CTRL register

LPC_SCT0->CONFIG = SCT_CONFIG_32BIT_COUNTER | (1<<9);

LPC_SCT0->LIMIT = SCT_EVT_1; //events to limit counter

//set prescaler 72 to count µs

Chip_SCT_SetControl(LPC_SCT0,SCT_CTRL_PRE_L(72-1));

//input capture setting

LPC_INMUX->SCT0_INMUX[0] = 2; //SCT0_IN0 = P0IO_17

LPC_SCT0->REGMODE = (SCT_EVT_1); //set capture register(s)

LPC_SCT0->CAPCTRL[1].U = (SCT_EVT_1); //set capture control event

LPC_SCT0->EVENT[1].STATE = (SCT_EVT_1); // event_happens in the state

LPC_SCT0->EVENT[1].CTRL = (0) | // captre.. not_used

(0 << 5) | // OUTSEL[5] = selects_input

(0 << 6) | // IOSEL[9:6] = 0 to select SCT 0_IN0

(1 << 10) | // IOCOND[11:10] = 1_rising

(2 << 12) | // COMBMODE[13:12] = IO_condition

(1 << 14) | // STATELD[14] = STATEV is_loaded

(1 << 15); // STATEV[19:15] = new_state_1

LPC_SCT0->STATE =1; //start state

//interrupts: rising

// EVFLAG

LPC_SCT0->EVFLAG = (SCT_EVT_1); //reset flags

// EVEN

LPC_SCT0->EVEN = (SCT_EVT_1); //enable interrupts

// SetPriority

NVIC_SetPriority(SCT0_IRQn, 0); //set priority

//EnableIRQ

NVIC_EnableIRQ(SCT0_IRQn);

// ClearControl

Chip_SCT_ClearControl(LPC_SCT0, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);//and start

}

// maiun

int main(void)

{

// Clockupdate

SystemCoreClockUpdate();

// init

Board_Init();

Board_LED_Set(0, true);

//init SCT0 to capture PIO0_17

SCT0_init(); //init SCT0

#ifdef GENERATE_PWM

//init SCT2 to generate PWM

SCT2_init();

#endif

//initialisation Sys_Tick to 10Hz

SysTick_Config(SystemCoreClock/10);

NVIC_SetPriority(SysTick_IRQn,2); //set priority

while(1) //loop

{

// sec

if(sec) //second timer

{

sec =0; //reset second flag

// if

if(valid) //valid data

{

// valid

valid=0;

// capture1 //reset valid

capture1 = LPC_SCT0->CAP[1].U; //get the capturevalue

freq = SystemCoreClock / capture1 /72; //calculates_frequency

printf("C1: %d ",capture1);

printf("F: %d Hz ",freq);

}

//else //end valid

else

{

// prinf

printf("No_valid_data ");

}

} //end second timer

} //end loop

// return

return 0 ;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote