2976 views|0 replies

27

Posts

0

Resources
The OP
 

MSP430F5529LP's P1.4 port outputs a single PWM wave [Copy link]

This post was last edited by Min丨Dayu on 2019-8-30 12:46

This content is originally created by EEWORLD forum user Min Da. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

This post is to answer the help post I sent yesterday. Here is a small record. 2019.08.30 Help post link: https://en.eeworld.com/bbs/forum.php?mod=viewthread&tid=1088275&extra=

Output single PWM

The routine in the MSP430Ware package—timer_a_ex1_pwmSingle can output a single PWM wave with a duty cycle of 0.75 and a frequency of ** (if you forget, you can use an oscilloscope to measure it). The output pin is P2.0. After the code is successfully burned, press the reset button of the microcontroller and use an oscilloscope to observe the waveform to verify whether the code is correct.

By referring to Table 4-1 of the MSP430F5529 data sheet, P1.4 also has PWM output capability. Now I want to modify the original routine P2.0 pin to P1.4 pin to output PWM.

Configuring peripherals is a routine, which I personally summarize into three steps: configuring peripheral clocks; configuring GPIO ports; initializing peripheral modules.

Configure peripheral clocks: Each peripheral module must have clock control to work, so before using each peripheral module, you must understand the maximum clock frequency of the peripheral. The peripheral clock is obtained by dividing the system clock. After knowing the system clock frequency, you need to pay attention to the actual clock frequency of the peripheral. You must be able to read the clock tree when learning to use each microcontroller.

Configure GPIO port: GPIO (General-purpose Input Output) is a general-purpose digital input and output port. The GPIO peripheral is the only bridge that communicates MUC with the outside world.

Initialize peripheral modules: Each peripheral module has a lot of registers. If you want to achieve a certain goal through these registers, you need to set them in advance. For example, if a person needs to go to Beijing and is required to arrive at Tiananmen Square in 5 days, this person can have many different options. Arriving at Tiananmen Square in Beijing can be considered as the goal, and various different options can be considered as register configurations. If there are only the first two steps without configuring registers, that is, this person cannot arrive at Tiananmen Square and the goal cannot be achieved.

Now let's configure the PWM module to help understand the three-step method.

Step 1. Configure the PWM module clock

Step 2. Configure GPIO port

Step 3. Initialize the PWM module

MSP430F5529 does not have an independent PWM module, so there is no PWM module clock. Here we need to mention DSP28335, this MUC is also from TI. It has an independent PWM module, which includes a time base module, a comparison module, an action module, etc. Back to here, the MSP430F5529 peripheral configuration can slightly modify steps 1 and 3 and merge them after step 2.

Configure the PWM module of MSP430F5529 in two steps

Step 1. Configure GPIO port

Step 2. Initialize Timer_A register

Step 1: Configure P1.4 as PWM output pin

GPIO_setAsPeripheralModuleFunctionOutputPin(

GPIO_PORT_P1,

GPIO_PIN4);

Step 2: Check the data sheet to see that P1.4 corresponds to the TimerA register, so configure the register to PWM mode

//Generate PWM - Timer runs in Up mode

Timer_A_outputPWMParam param = {0}; //Upward counting mode. param is a structure variable.

param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;//Timer_A clock source

param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; // No frequency division

param.timerPeriod = TIMER_PERIOD; //PWM period count value

param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_3; //Look up the table to know that P1.4 corresponds to CCR3

param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; //Automatic reload mode

param.dutyCycle = DUTY_CYCLE; //duty cycle count value

Timer_A_outputPWM(TIMER_A0_BASE, m); //Look up the table to know that P1.4 corresponds to TimerA0

Summary: There are a total of 3 places in the routine code that need to be modified.

GPIO_setAsPeripheralModuleFunctionOutputPin(

GPIO_PORT_P1,

GPIO_PIN4);

param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_3; //Look up the table to know that P1.4 corresponds to CCR3

Timer_A_outputPWM(TIMER_A0_BASE, m); //Look up the table to know that P1.4 corresponds to TimerA0

The source code is attached:

timer_a_ex1_pwmSingle.rar (589.76 KB, downloads: 12)

image-20190830124328-1.png (176.97 KB, downloads: 0)

image-20190830124328-1.png
This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list