1598 views|2 replies

3836

Posts

19

Resources
The OP
 

MSP-EXP430F5529LP Development Board 005-PWM Library Function + Clock Configuration [Copy link]

The most difficult thing for me to switch from 32 to MSP430 is its clock configuration. After referring to some online information and reading for a few days, I finally got a general understanding. The above 6 points are the key, and they should be referred to when initializing the clock later. The purpose of this experiment is to realize the output of 10kHz PWM at P2.0 port, which is also the common working frequency of motor control in applications. To output accurate frequency, it is very necessary to understand each clock clearly. First of all, make it clear that there are three clocks in 430: auxiliary clock ACLK, which has a lower frequency and is selected by software as the clock signal of each peripheral module, generally used for low-speed peripherals; system main clock MCLK, which has a higher frequency and is mainly used for CPU and system, similar to the main frequency; subsystem clock SMCLK, which is mainly used for high-speed peripheral modules. Here we use TIMER_A to generate PWM and select SMCLK as the clock source of the module, so the setting of SMCLK is the key. The XT2 of LaunchPad 430 is connected to a 4MHz clock source, and the T1 is connected to a 32.768kHz clock source. In addition to outputting 10kHz PWM, the goal of this experiment is to configure ACLK to 32.768kHz, MCLK to 24MHz, and SMCLK to 4MHz. The overall code is as follows: //************************************************************************************ #include "driverlib.h" //************************************* ****************************************** / / //Target frequency for MCLK in kHz // //************ *************************************************** ******************* #define UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ 24000 //**************************** *************************************************[ /size] // //MCLK/FLLRef Ratio // //******************************************* ************************************ #define UCS_MCLK_FLLREF_RATIO 6[/size ] //************************************ ************************************************ [size =4]// //Variable to store current Clock values // //******************************** ********************************************* [ size=4]uint32_t clockValue = 0; //************************ *************************************************** ****** // //Variable to store status of Oscillator fault flags // //****************** *************************************************** ****************** //**************************** *************************************************** ** // //XT1 Crystal Frequency being used // //******************************** ********************************************* [ size=4]#define UCS_XT1_CRYSTAL_FREQUENCY 32768 //************************ *************************************************** ***** // //XT2 Crystal Frequency being used // //***** *************************************************** ************************ #define UCS_XT2_CRYSTAL_FREQUENCY 4000000 //******************************************* ************************************ // [ size=4]//Desired Timeout for XT1 initialization // //************************ *************************************************** ********** #define UCS_XT1_TIMEOUT 50000 #define TIMER_PERIOD 399 #define DUTY_CYCLE 100 #define UCS_XT2_TIMEOUT 50000 uint16_t status; uint8_t returnValue = 0; void main (void) { //Stop WDT WDT_A_hold(WDT_A_BASE); [ /size] //Set VCore = 1 for 12MHz clock PMM_setVCore(PMM_CORE_LEVEL_1);//After the main frequency is increased, the VCore voltage also needs to be configured accordingly //Initializes the XT1 and XT2 crystal frequencies being used UCS_setExternalClockSource(UCS_XT1_CRYSTAL_FREQUENCY,UCS_XT2_CRYSTAL_FREQUENCY);//Set the frequency of the external clock source, no actual setting //Initialize XT1. Returns STATUS_SUCCESS if initializes successfully GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN4 + GPIO_PIN5);//XT1 port is not used as a normal IO returnValue = UCS_turnOnLFXT1WithTimeout(UCS_XT1_DRIVE_0,UCS_XCAP_3,UCS_XT1_TIMEOUT);//Start XT1 //Startup HF XT2 crystal Port select XT2 GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN2 + GPIO_PIN3);//XT2 port is not used as normal IO //Initialize XT2. Returns STATUS_SUCCESS if initializes successfully returnValue = UCS_turnOnXT2WithTimeout(UCS_XT2_DR IVE_4MHZ_8MHZ,UCS_XT2_TIMEOUT);//Start XT2 //Set DCO FLL reference = REFO UCS_initClockSignal(UCS_FLLREF,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//XT2 as FLL reference //Set Ratio and Desired MCLK Frequency and initialize DCO UCS_initFLLSettle(UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ,UCS_MCLK_FLLREF_RATIO);//MCLK is set to 24MHz //Set ACLK = REFO UCS_in itClockSignal(UCS_ACLK,UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1);//ACLK is set to 32.768kHz UCS_initClockSignal(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//SMCLK is set to 4MHz //P2.0 as PWM output GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0); //Generate PWM - Timer runs in Up mode Timer_A_outputPWMParam param = {0}; [size=4 ] param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; param.timerPeriod = TIMER_PERIOD; param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; param.dutyCycle = DUTY_CYCLE; Timer_A_outputPWM(TIMER_A1_BASE, m); // Enable global interrupt __bis_SR_register(GIE); //Verify if the Clock settings are as expected clockValue = UCS_getMCLK(); clockValue = UCS_getACLK(); clockValue = UCS_getSMCLK(); [ =4] //Loop in place while (1) ; }UCS_XT1_TIMEOUT);//Startup XT1 //Startup HF XT2 crystal Port select XT2 GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN2 + GPIO_PIN3 );//XT2 port is not used as normal IO //Initialize XT2. Returns STATUS_SUCCESS if initializes successfully returnValue = UCS_turnOnXT2WithTimeout (UCS_XT2_DRIVE_4MHZ_8MHZ,UCS_XT2_TIMEOUT);//Start XT2 //Set DCO FLL reference = REFO UCS_initClockSignal(UCS_FLLREF,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//XT2 as FLL reference //Set Ratio and Desired MCLK Frequency and initialize DCO [size =4] UCS_initFLLSettle(UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ,UCS_MCLK_FLLREF_RATIO);//MCLK is set to 24MHz //Set ACLK = REFO UCS_initClockSignal (UCS_ACLK,UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1);//ACLK is set to 32.768kHz UCS_initClockSignal(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//SMCLK is set to 4MHz //P2.0 as PWM output GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0); //Generate PWM - Timer runs in Up mode Timer_A_outputPWMParam param = {0}; param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; param.timerPeriod = TIMER_PERIOD; param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;[/size ] param.dutyCycle = DUTY_CYCLE; Timer_A_outputPWM(TIMER_A1_BASE, m); // Enable global interrupt __bis_SR_register(GIE); //Verify if the Clock settings are as expected clockValue = UCS_getMCLK(); clockValue = UCS_getACLK(); clockValue = UCS_getSMCLK(); //Loop in place while (1) ; }UCS_XT1_TIMEOUT);//Startup XT1 //Startup HF XT2 crystal Port select XT2 GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN2 + GPIO_PIN3 );//XT2 port is not used as normal IO //Initialize XT2. Returns STATUS_SUCCESS if initializes successfully returnValue = UCS_turnOnXT2WithTimeout (UCS_XT2_DRIVE_4MHZ_8MHZ,UCS_XT2_TIMEOUT);//Start XT2 //Set DCO FLL reference = REFO UCS_initClockSignal(UCS_FLLREF,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//XT2 as FLL reference //Set Ratio and Desired MCLK Frequency and initialize DCO [size =4] UCS_initFLLSettle(UCS_MCLK_DESIRED_FREQUENCY_IN_KHZ,UCS_MCLK_FLLREF_RATIO);//MCLK is set to 24MHz //Set ACLK = REFO UCS_initClockSignal (UCS_ACLK,UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1);//ACLK is set to 32.768kHz UCS_initClockSignal(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//SMCLK is set to 4MHz //P2.0 as PWM output GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0); //Generate PWM - Timer runs in Up mode Timer_A_outputPWMParam param = {0}; param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; param.timerPeriod = TIMER_PERIOD; param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;[/size ] param.dutyCycle = DUTY_CYCLE; Timer_A_outputPWM(TIMER_A1_BASE, m); // Enable global interrupt __bis_SR_register(GIE); //Verify if the Clock settings are as expected clockValue = UCS_getMCLK(); clockValue = UCS_getACLK(); clockValue = UCS_getSMCLK(); //Loop in place while (1) ; }UCS_MCLK_FLLREF_RATIO);//MCLK is set to 24MHz //Set ACLK = REFO UCS_initClockSignal(UCS_ACLK,UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1);//ACLK is set to 32.768kHz UCS_initClockSignal(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//SMCLK is set to 4MHz //P2.0 as PWM output GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0); //Generate PWM - Timer runs in Up mode Timer_A_outputPWMParam param = {0} ; param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; param.timerPeriod = TIMER_PERIOD; param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;[/size ] param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; param.dutyCycle = DUTY_CYCLE; Timer_A_outputPWM(TIMER_A1_BASE, m); [size= 4] // Enable global interrupt __bis_SR_register(GIE); //Verify if the Clock settings are as expected clockValue = UCS_getMCLK();[/ size] clockValue = UCS_getACLK(); clockValue = UCS_getSMCLK(); //Loop in place while (1) ; }UCS_MCLK_FLLREF_RATIO);//MCLK is set to 24MHz //Set ACLK = REFO UCS_initClockSignal(UCS_ACLK,UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1) ;//ACLK is set to 32.768kHz UCS_initClockSignal(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_1);//SMCLK is set to 4MHz //P2.0 as PWM output GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0); //Generate PWM - Timer runs in Up mode Timer_A_outputPWMParam param = {0} ; param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; param.timerPeriod = TIMER_PERIOD; param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; param.dutyCycle = DUTY_CYCLE; Timer_A_outputPWM(TIMER_A1_BASE, m); [size= 4] // Enable global interrupt __bis_SR_register(GIE); //Verify if the Clock settings are as expected[ /size] clockValue = UCS_getMCLK(); clockValue = UCS_getACLK(); clockValue = UCS_getSMCLK(); [size =4] //Loop in place while (1) ; }

This post is from Microcontroller MCU

Latest reply

Do you have relevant documents?  Details Published on 2019-8-8 07:38
 

6366

Posts

4936

Resources
2
 
The clock system of 430 is really powerful. I have seen an introduction that the clock of 430 is the clock system, while the clock of some microcontrollers is the system clock. Although the order of the two words "clock system" and "system clock" is just reversed, the difference is huge.
This post is from Microcontroller MCU
 
 

1

Posts

0

Resources
3
 
Do you have relevant documents?
This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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