0% found this document useful (0 votes)
7 views1 page

Interfacing Tiva Board With Example Codes

The document provides a code example for generating a 1KHz PWM signal on GPIO pin PF2 with a 20% duty cycle using the TM4C123GH6PM microcontroller. It includes steps for enabling the PWM module, configuring the GPIO pin, and setting the PWM parameters. The main loop keeps the PWM signal running indefinitely.

Uploaded by

kguruprasad590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Interfacing Tiva Board With Example Codes

The document provides a code example for generating a 1KHz PWM signal on GPIO pin PF2 with a 20% duty cycle using the TM4C123GH6PM microcontroller. It includes steps for enabling the PWM module, configuring the GPIO pin, and setting the PWM parameters. The main loop keeps the PWM signal running indefinitely.

Uploaded by

kguruprasad590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Task 5 - Generate 1KHz PWM signal on any GPIO pin with 20% duty cycle.

-
PWM+GPIO
#include "TM4C123GH6PM.h"
int main(void)
{
SYSCTL->RCGCPWM |= 2; // Enable clock to PWM1 module
SYSCTL->RCGCGPIO |= 0x20; // Enable clock for Port F
SYSCTL->RCC |= 0x00100000 | 0x00080000; // Enable PWM divider and set divider
to 8 (16MHz / 8 = 2MHz)
GPIOF->AFSEL |= (1 << 2); // Enable alternate function on PF2
GPIOF->PCTL &= ~0x00000F00; // Clear previous function settings
on PF2
GPIOF->PCTL |= 0x00000500; // Set PF2 to M1PWM6 function
GPIOF->DEN |= (1 << 2); // Enable digital function on PF2
PWM1->_3_CTL &= ~(1 << 0); // Disable Generator 3 while setting
it
PWM1->_3_CTL &= ~(1 << 1); // Select down-count mode
PWM1->_3_GENA = 0x0000008C; // Set high at LOAD, low at CMPA (in
down count)
PWM1->_3_LOAD = 2000 - 1; // Set period to 1ms
PWM1->_3_CMPA = 1600 - 1; // Set duty to 20% (ON for 0.2ms)
PWM1->_3_CTL |= (1 << 0); // Enable Generator 3
PWM1->ENABLE |= (1 << 6); // Enable PWM output on M1PWM6 (PF2)
while (1)
{
// PWM keeps running on PF2
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy