MSP430F149 TimerA outputs pwm signal C program code

Publisher:温馨如家Latest update time:2016-08-21 Source: eefocusKeywords:MSP430F149  TimerA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
MSP430F149 TimerA outputs pwm signal 
Note the corresponding relationship between the register settings and the PWM signal output pins: P1.2-TA1, TACCR1, TACCTL1; P1.3-TA2, TACCR2, TACCTL2.
 
#include
 
#define uint unsigned int
#define uchar unsigned char
 
 
void int_clk()
{
  uchar i;
  BCSCTL1 &= ~XT2OFF; //Turn on XT oscillator
  BCSCTL2 |= SELM1+SELS; //MCLK is 8MHz, SMCLK is 8MHz
  do
  {
     IFG1&=~OFIFG; //Clear oscillation error flag
     for(i=0;i<100;i++)
      _NOP(); //Delay waiting
   }
   while((IFG1&OFIFG)!=0); //If the flag is 1, continue to loop and wait
   IFG1&=~OFIFG;
}
 
void int_pwm()
{
  P1SEL |= BIT2 + BIT3 ; //Select p1.2-TA1, P1.3-TA2 as the second function of PWM output
  P1DIR |= BIT2 + BIT3 ;
  TACCR0 = 800; //PWM signal frequency 10KHZ
  TACCR1 = 400; // Duty cycle 1:1
  TACCTL1 = OUTMOD_7;
  TACCR2 = 400 ;
  TACCTL2 = OUTMOD_7;
  TACTL |= TASSEL1 +ID1 + ID0 + MC0 ; //Select SMCLK increase mode
}
 
void main()
{
  WDTCTL = WDTPW + WDTHOLD;
  int_clk();
  int_pwm();
  while(1);
}

Keywords:MSP430F149  TimerA Reference address:MSP430F149 TimerA outputs pwm signal C program code

Previous article:MSP430F149 and 1602LCD module program
Next article:msp430F149 and cc2500 communication enable USART1, SPI initialization

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号