Msp432--timera (main instructions on how to implement an adjustable PWM)

Source: Internet
Author: User

---restore content starts---

16-bit Timer timer_a output Precision PWM

1. Mode operation

Timer_a support: Multi-channel capture/Compare, PWM output, timing
Simultaneous support: Interrupts

Timer_a Features: Asynchronous 16-bit timer/counter with four modes
                selectable, configurable clock resources
                Up to 7 configurable capture/comparison registers
               Features with PWM configuration
               asynchronous input and output self-locking
               Interrupt vector Register Fast decoding timer interrupt
2. Basic operating mode
Three modes: continuous count mode
           increment count mode
            Increment/Decrement count mode
Timera_initcompare () Initialize comparison mode  /* require necessary parameters */
TIMERA_GENERATEPWM () generate pwm        /* requires necessary parameters */

/* Configure Timera PWM parameters */
Timer_a_pwmconfig Pwmconfig =
{
TIMER_A_CLOCKSOURCE_SMCLK,
Timer_a_clocksource_divder_1,
32000,
Timer_a_capturecompare_register_0,
Timer_a_outputmode_toggle,
3200
};

Parameter details:
typedef struct _TIMER_A_PWMCONFIG
{
uint_fast16_t Clocksource; Clock resource, choose which clock to do the source of the timer, the same as 430 in the TASSELX
uint_fast16_t clocksourcedivider;//min. frequency
uint_fast16_t timerperiod;//Cycle
uint_fast16_t compareregister;//Select Comparison Register
uint_fast16_t compareoutputmode;//Comparison module output mode
uint_fast16_t dutycycle;//High level accounted for
} timer_a_pwmconfig;

/* Configure Timera PWM parameters */

/* Program Instance */


/* Configuration MCLK to Refo at 128Khz for LF mode
* Configuration SMCLK is 64Khz */
Map_cs_setreferenceoscillatorfrequency (cs_refo_128khz);
Map_cs_initclocksignal (CS_MCLK, Cs_refoclk_select, cs_clock_divider_1);
Map_cs_initclocksignal (CS_SMCLK, Cs_refoclk_select, cs_clock_divider_2);
Map_pcm_setpowerstate (PCM_AM_LF_VCORE0);
/* Set GPIO7.3 to PWM output pin, P1.1 bit key
* Interrupt */
Map_gpio_setasperipheralmodulefunctionoutputpin (GPIO_PORT_P7, gpio_pin3, gpio_primary_module_function);
Map_gpio_setasinputpinwithpullupresistor (GPIO_PORT_P1, gpio_pin1);
Map_gpio_clearinterruptflag (GPIO_PORT_P1, gpio_pin1);
Map_gpio_enableinterrupt (GPIO_PORT_P1, gpio_pin1);
/* Configure timer A for a period of 500ms, the initial duty cycle is 10% (3200 ticks) */
MAP_TIMER_A_GENERATEPWM (Timer_a0_module, &pwmconfig);

/* Program Instance */

3. Description of related library functions
(1) void Timer_a_clearcapurecompareinterrupt (uint32_t Timer,
uint_fast16_t capturecompareregister)//l1047 allow timed interrupts
Timer:timer_a0_module
Timer_a1_module
Timer_a2_module
Timer_a3_module
Capturecompareregister:timer_a_capturecompare_register_n (n=0,1,2,3,4,5,6)
Returns None
(2) void Timer_a_clearinterruptflag (uint32_t timer)//Clear Timer TAIFG interrupt flag bit
Timer: Slightly
Returns None
(3) void Timer_a_cleartimer (uint32_t timer)//restart/clear timer divider, counting direction, etc.
Timer: Slightly
Returns None
(4) void Timer_a_configurecontinuousmode (uint32_t Timer,
Const timer_a_continuousmodeconfig *CONFIG)//Configure timer A for continuous mode
Timer: Slightly
Returns None
Config: Data structure as follows
/********************************************
typedef struct _TIMER_A_CONTINUOUSMODECONFIG
{
uint_fast16_t clocksource;//Clock Resource, choose which clock to do the source of the timer, the same as 430 in the TASSELX
uint_fast16_t clocksourcedivider;//Crossover
uint_fast16_t timerinterruptenable_taie;//timer interrupt allow bit 0 Forbidden 1 allowed
uint_fast16_t timerclear;//Clear Bit
}timer_a_continuousmodeconfig;
********************************************/
(5) void Timer_a_configureupdownconfig (uint32_t Timer,
Const timer_a_upmodeconfig *config)//increment/Decrement count mode configuration
Timer: Slightly
Returns None
Config: Data structure as follows
/********************************************
typedef struct _TIMER_A_UPDOWNMODECONFIG
{
uint_fast16_t clocksource;//Ibid.
uint_fast16_t Clocksourcedivider;
uint_fast16_t Timerperiod;
uint_fast16_t Timerinterruptenable_taie;
uint_fast16_t Capturecompareinterruptenable_ccr0_ccie;
uint_fast16_t timerclear;
}timer_a_updownmodeconfig;
*********************************************/
(6) void Timer_a_configureupmode (uint32_t Timer,
Const timer_a_upmodeconfig *config)//Add-count mode configuration
Timer: Slightly
Returns None
Config: Data structure as follows
/********************************************
typedef struct _TIMER_A_UPMODECONFIG
{
uint_fast16_t clocksource;//Ibid.
uint_fast16_t Clocksourcedivider;
uint_fast16_t Timerperiod;
uint_fast16_t Timerinterruptenable_taie;
uint_fast16_t Capturecompareinterruptenable_ccr0_ccie;
uint_fast16_t timerclear;
}timer_a_upmodeconfig;
**********************************************/
(7) void Timer_a_disablecapturecompareinterrupt (uint32_t Timer,
uint_fast16_t capturecompareregister)//

The function part has not been continued---

The following is a modification of the official routine, which mainly produces an adjustable pwm with a period of 5ms,p2.4 output.

There are comment errors in the routines, and there are many problems to be aware of in the application.

For example interrupt function Port1_isr ()

The official routine does not declare an external file to be used, and the interrupt function is required to break the interface

Introduced into the MSP432_STARTUP_EWARM.C file __root const uvectorentry __vector_table[] @ ". Intvec" ={};

In Therefore, there will be some problems in the actual application, and private messages can be discussed together.

#include"Driverlib.h"#include"Delay.h"#include<stdint.h>#include<stdbool.h>int32_t Test=0; Timer_a_pwmconfig Pwmconfig={timer_a_clocksource_smclk, timer_a_clocksource_divider_1, the, timer_a_capturecompare_register_1, Timer_a_outputmode_reset_set,288}; //Configuring PWM Output ParametersintMainvoid) {Map_wdt_a_holdtimer ();    Map_cs_setreferenceoscillatorfrequency (cs_refo_128khz);    Map_cs_initclocksignal (CS_MCLK, Cs_refoclk_select, cs_clock_divider_1);    Map_cs_initclocksignal (CS_SMCLK, Cs_refoclk_select, cs_clock_divider_2);    Map_pcm_setpowerstate (PCM_AM_LF_VCORE0); Map_gpio_setasperipheralmodulefunctionoutputpin (GPIO_PORT_P2, Gpio_pin4, gpio_primary_module_function);//configuring P2.4 for Output PWMMap_gpio_setasinputpinwithpullupresistor (GPIO_PORT_P1, gpio_pin1);//P1.1 for KeysMap_gpio_clearinterruptflag (GPIO_PORT_P1, gpio_pin1);            Map_gpio_enableinterrupt (GPIO_PORT_P1, gpio_pin1);    Map_interrupt_enableinterrupt (INT_PORT1);    Map_interrupt_enablesleeponisrexit ();        Map_interrupt_enablemaster ();  while(1) {map_pcm_gotolpm0 (); }}extern voidPORT1_ISR (void)//Interrupt Function{uint32_t status=Map_gpio_getenabledinterruptstatus (GPIO_PORT_P1);    Map_gpio_clearinterruptflag (GPIO_PORT_P1, status); if(Status &gpio_pin1) {MAP_TIMER_A_GENERATEPWM (Timer_a0_module,&pwmconfig); if(Pwmconfig.dutycycle = =288) Pwmconfig.dutycycle= +; Elsepwmconfig.dutycycle+= +; Test=pwmconfig.dutycycle; }   }

---restore content ends---

Msp432--timera (main instructions on how to implement an adjustable PWM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.