Skip to content

Building Embedded Software Using the LAUNCHXL-F280025C Development Kit (Using Register Level)

Notifications You must be signed in to change notification settings

talhaturac/Potentiometer_Control_PWM_Duty_Register

Repository files navigation


Logo

Building Embedded Software Using the LAUNCHXL-F280025C Development Kit

This project is developed to control the duty cycle of PWM signals with a potentiometer.
("without using EPWM_configureSignal" The PWM is controlled at register level)

Table Of Contents


About The Project

I am actively working on development kits from Texas Instruments and developing embedded software. In this post here, I wanted to share one of the projects I have done so that you can benefit from it. Enjoy!

Why are we here:

  • To create projects from Code Composer Studio IDE.
  • To be able to use the ADC unit, read and use this data.
  • To generate and configure PWM signals.
  • To be able to set the duty cycle ratio and other parameters of the PWM signal.

You can experiment by customizing the project code to your own TI development board. Or you can use the information shared here to create your own customizations that use the ADC unit and ePWM unit. The actual code is in the main.c file.



In the "Watch Expressions" section, the change of CMPA and CMPB values at the register level, that is, the values printed on it for control purposes, can be monitored as shown in the image.

Built With

It was built using the C programming language, via Code Composer Studio IDE, with the LAUNCHXL-F280025C (C2000 MCUs family) development kit from Texas Instruments.


Description

Firstly, an empty CCS project file is opened. Required adjustments and configurations are made. After selecting the target path, i.e. the target device and connection type, the software is started. The reason why I do not share about these parts in detail is that they are available on the internet and TI's own resources.

The software is started by including the libraries on the main.c file. In this section, the included libraries are "driverlib.h" and "device.h". These files contain the drivers for the microcontroller and define the device-specific constants.

#include "driverlib.h"
#include "device.h"

The prototypes of the used functions are defined in this section. This enhances the readability and maintenance of the code.

// Function Prototypes
void    ADC_init();
void    ASYSCTL_init();
void    INTERRUPT_init();
void    PinMux_init();
void    TriggerEPWM_init();
void    PWM_Setup();
void    change_duty_ratio();
extern __interrupt void adcA1ISR(void);

This section contains the definitions of global variables used in the code, such as ADC results, duty ratio, and other variables.

// GLOBALS
uint16_t   adcAResult0;
float32_t  dutyRatio;
float32_t  d_value = 0;

This function contains the necessary steps to initialize EPWM2. It configures GPIO pins, resets PWM2 peripheral, and sets up synchronization.
! These operations are done using registers !

void PWM_Setup()

This function is used to change the PWM duty ratio. It calculates the duty cycle of the PWM signal based on the ADC value and configures the PWM signal.

void change_duty_ratio(void)

This function configures EPWM1 as a trigger for ADC. It sets up timing and frequency parameters.

void TriggerEPWM_init(void)

This functions initializes and configures the ADC. It sets ADC sampling triggers, interrupts, and other settings.

__interrupt void adcA1ISR(void)
void ADC_init()
void INTERRUPT_init()

These function disables the temperature sensor output to the ADC.

void ASYSCTL_init()

This function sets up the configuration of analog pins.

void PinMux_init()

The main function initializes the device and performs necessary settings. It calls a function in an infinite loop to change the PWM duty cycle based on the ADC reading.

void main(void)

In order to test the results, a 330 ohm resistor and an LED lamp are connected in series between the GPIO2 pin and the 3.3V pin of the development board. The red end of the potentiometer is connected to 3.3V, the black end to the GND pin and the white pin to the A0/C15 pin. The connection and pinout reference of the development board can be found with F280025C LaunchPad™ quick quide resource.

Let's turn the potentiometer and see what happens!


Contact and Feedback