#include "timer.h" #include "tm4c123gh6pm.h" void PWM0A_Init(uint16_t period, uint16_t duty) { SYSCTL_RCGCPWM_R |= 0x01; // 1) activate PWM0 SYSCTL_RCGCGPIO_R |= 0x02; // 2) activate port B while ((SYSCTL_PRGPIO_R & 0x02) == 0) {}; GPIO_PORTB_AFSEL_R |= 0x40; // enable alt funct on PB6 GPIO_PORTB_PCTL_R &= ~0x0F000000; // configure PB6 as PWM0 GPIO_PORTB_PCTL_R |= 0x04000000; GPIO_PORTB_AMSEL_R &= ~0x40; // disable analog functionality on PB6 GPIO_PORTB_DEN_R |= 0x40; // enable digital I/O on PB6 SYSCTL_RCC_R = 0x00100000 | // 3) use PWM divider (SYSCTL_RCC_R & (~0x000E0000)); // configure for /2 divider PWM0_0_CTL_R = 0; // 4) re-loading down-counting mode PWM0_0_GENA_R = 0xC8; // low on LOAD, high on CMPA down // PB6 goes low on LOAD // 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 PWM0_ENABLE_R |= 0x00000001; // enable PB6/M0PWM0 } // change duty cycle of PB6 // duty is number of PWM clock cycles output is high (2<=duty<=period-1) void PWM0A_Duty(uint16_t duty) { PWM0_0_CMPA_R = duty - 1; // 6) count value when output rises } void shhh(void) { timer0_stop(); PWM0A_Init(1000000, 0); } void tick(void) { PWM0A_Init(300000, 150000); timer0_start(shhh, 25, false); } void tock(void) { PWM0A_Init(310000, 150000); timer0_start(shhh, 25, false); } void AHHHH(void) { PWM0A_Init(250000, 1250000); }