Question: I need this programm build and run through in code composer (CCS Edit) . the progarm below shows the correct code , but with some

I need this programm build and run through in code composer (CCS Edit) . the progarm below shows the correct code , but with some error saying unit16 notdefined. Fix this error. Also, i need this program to be changed to 60% duty cyle and bus clock is 2000KHZ. Show me how u change duty cycle to 60% and bus clock to 2000KHz.

Original Question

We call PWM0A_Init once to turn it on, and then call PWM0A_Duty to adjust the duty cycle. Assume the bus clock is 50MHz, we call PWM0A_Init (25000,125000); to creat a 1 ms period 50% duty cycle output on PWM0A (PB6)

//period is 16-bit number of PWM clock cycles in one period (3<=period) //duty is number of PWM clock cycles output is high (2<=duty=period-1) //PWM clock rate = processor clock rate/SYSCTL_RCC_PWMDIV // = BusClock/2

#include "C:\ti\TivaWare_C_Series-2.1.4.178\inc\tm4c123gh6pm.h" #include #include #include "C:\ti\TivaWare_C_Series-2.1.4.178\inc/hw_types.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\inc/hw_memmap.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\driverlib/sysctl.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\driverlib/gpio.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\inc/hw_ints.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\driverlib/interrupt.h" #include "C:\ti\TivaWare_C_Series-2.1.4.178\driverlib/timer.h" #include

void PWM0A_Init(unit16_t period, unit16_t duty) { SYSCTL_RCGCGPIO_R |=0x00000001; //1)activate clock for PWM0 //allow time to finish activating while((SYSCTL_PRPWM_R&0x00000001)==0){}; SYSCTL_RCGCGPIO_R |=0x00000002; // activate clock for Port B //allow time to finish activating while ((SYSCTL_PRGPIO_R&0x00000002)==0){}; GPIO_PORTB_AFSEL_R |=0x40; //2)enable alt function on PB6 GPIO_PORTB_ODR_R &= ~0x40; // disable open drain on PB6 GPIO_PORTB_DEN_R |=0x40; //enable digital I/O on PB6 GPIO_PORTB_AMSEL_R &= ~0x40; //disable analog function on PB6 // configure PB6 as PWM

GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0XF0FFFFFF) + 0X04000000; SYSCTL_RCC_R = 0x00100000 | // 3) use PWM divider ((SYSCTL_RCC_R & ( ~ 0x000E0000)) + //clear PWM divider field 0x00000000); //configure for /2 divider PWM0_0_CTL_R = 0; // 4)re-loading down-counting mode // PB6 goes low on LOAD

PWM0_0_GENA_R = 0x000000C8; // PB6 goes high on CMPA down PWM0_0_LOAD_R = period -1; // 5) cycles needed to count down to 0 PWM0_0_CMPA_R = duty -1; //6) count value when output rises PWM0_0_CTL_R |= 0x00000001; //7)start PWM0 Generator 0 PWM0_ENABLE_R |= 0x00000001; //enable PWM0 Generator 0 } //Change duty cycle //Duty cycle is the number of PWM clock cycles out is high (2<=duty<=period -1) void PWM0A_Duty (unit16_t duty){ PWM0_0_CMPA_R = duty -1; // 6) count value when output rises }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!