Freescale's PWM output controls the direction of the servo motor

Publisher:数字梦想Latest update time:2016-01-19 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
resource:
1. Servo motor. When the PWM output cycle is within a certain range, the steering direction of the servo will be proportional to the PWM duty cycle.
2. PWM output of HCS12.
Solution:
1. The PWM module in HCS12 performs PWM output through hardware.
2. The comparison output module of ECT in HCS12 performs PWM output through comparison output.
Since the PWM module is a dedicated module for output PWM, PWM output can be achieved by setting the corresponding registers, which is simple, convenient and accurate. Therefore, the PWM module is selected for PWM output.
Description:
1. The steering angle of the servo is controlled by PWM. The servo interface generally has 3 wires, black ground wire and red power wire, generally using 4.8V and 6V standards. The other wire is the control signal line.
2. 16-bit PWM output is achieved through cascading.
3. The cycle is 18MS~20MS, that is, the output cycle is 56Hz~50Hz.
4. The alignment method is PWM left alignment.
5. The output polarity is the starting high level.
6. The pulse width varies from 1100us to 1900us, achieving a steering angle of -45° to 45°.
7. Achieve 16-bit PWM output through cascading. Channel PWM45 forms channel A.
8. Clock source selection.
  BusBlock: 24MHz.
  void pllclk(void) //24MHz
  {
      SYNR=0x02;     //PLLCLK =2*OSCCLK*(SYNR + 1)/(REFDV + 1)
      REFDV=0x01;
      CLKSEL=0x80;   //Select PLL clock
  }
9. PWM clock.
  Channel clock period 2us
  Output period 20MS
  PWM output frequency: 50Hz.
  Pre-division: 8-division     3MHz
  PWMPRCLK=0x66
  Division: 6-division 500kHz
  ClockSX=ClockX/(2*PWMSCLX)
  PWMSCLx=ClockX/ClockSX*2=3M/(500k*2)=3=0x03
  Through two divisions, the channel clock period is: 100US, i.e. 10KHZ
  Channel A clock frequency selects PWMPRCLK and PWMSCLA;
  Channel B clock frequency selects PWMPRCLK and PWMSCLB;
  Period calculation formula:
  Left alignment:
    Output period = channel clock period * (PWMPERx+1)
    PWMPERx=output period/channel clock period-1
    =20MS/2us-1
    =9999=0x270f
10. Duty cycle setting:
  Left alignment starts with output high level:
  Duty cycle = [(PWMDTYx+1)/(PWMPERx+1)]*100%
  PWMDTYx=duty cycle*(PWMPERx+1)/100%
According to the formula:
[(PWMDTYx+1)/(PWMPERx+1)]*100%=pulse width/output period*100%
  PWMDTYx=(pulse width*PWMPERx)/output period-1
        =(pulse width*9999)20000-1Pulse

width=rotation angle*(400)/45+1500   (us)
  Through the loop, the PWMDTx value corresponding to the rotation angle of the servo motor can be calculated.
PWMDTYx[28]={859,855,850,846,841,837,832,828,824,819,815,810,806,801,797,792,788,784,779,775,
770,766,761,757,752,748,744,740,735,731,726,722,717,713,708,704,700,695,691,686,
682,677,673,668,664,660,655,651,646,642,637}
The program to calculate the PWMDTYx value is as follows:
#include
void main()
{
long int i,X,y; } } CODE
: #include <  hidef.h  > #include  < 
MC9S12XS128.h >  #pragma LINK_INFO  DERIVATIVE  " mc9s12xs128 " // =========================================================== // //16-bit PWM output controls the rotation of the servo motor //author: yangtze //time:2009/4/21/ //==============================================================// #define PWMPERx  0x270F; unsigned int PWMDTYxtable[]={
 
  
      
  




     
   







 

0x035b,0x0357,0x0352,0x034e,0x0349,0x0345,
0x0340,0x033c,0x0338,0x0333,0x032f,0x032a,
0x0326,0x0321,0x031d,0x0318,0x0314,0 x0310,
0x030b,0x0307,0x0302,0x02fe,0x02f9,0x02f5,
0x02f0, 0x02ec,0x02e8,0x02e4,0x02df,0x02db,
0x02d6,0x02d2,0x02cd,0x02c9,0x02c4,0x02c0,
​​0x02bc,0x02b7,0x02b3,0x02ae,0x02aa,0x02a5,
0x02a1,0x029c,0x0298,0x0294,0x028f,0x 028b,
0x0286,0x0282,0x027d};
void pllclk(void)// 24MHz
{
  SYNR=0x02;     //PLLCLK =2*OSCCLK*(SYNR + 1)/(REFDV + 1)
  REFDV=0x01;
  CLKSEL=0x80;   //Selected PLL clock
}
  
  
void PWMServoMotor_init(void) //PWM initialization settings
{
  PWMPRCLK=0X66; //Set channel period
  PWMSCLA=0X03;
  PWMSCLB=0X03;
  PWMCLK=0XFF;
  
  PWMPOL=0X00; //Start output high level
  PWMCAE=0X00; // Waveform left-aligned
  PWMCTL=0XFC; //Select cascade output
}

void PWM_Pulse(unsigned int PWMPERx,unsigned int PWMDTYx) //PWM output period and duty cycle setting
{
    PWMPERH=(PWMPERx>>8)&0X00FF;
    PWMPERL=PWMPERx&0X00FF ;
    
    PWMPER4=PWMPERH;   //Set the output period
    PWMPER5=PWMPERL;
    
    PWMDTYH=(PWMDTYx>>8)&0X00FF;
    PWMDTYL=PWMDYx&0X00FF;
    
    PWMDTY4=PWMDTYH;   //Set pulse width
    PWMDTY5=PWMDTYL;
    
    PWME=0X18; //Channel 45 is enabled
}
void main(void)
{
  unsigned int PWMDTYx;
  PWMDTYx=PWMDTYxtable[5];
  pllclk();
  PWMServoMotor_init();
  PWM_Pulse(PWMPERx,PWMDTYx);
  
  EnableInterrupts;
  for(;;) {}
  
}

      //Last time I wrote a program for driving a DC motor, I originally used 16-bit PWM modulation, but in the end I only used 8-bit. The second time I used the PWM module, I carefully studied the usage of this module and found that the biggest difference between 16-bit and 8-bit is not the length of the cycle or the size of the duty cycle. The biggest impact is the modulation accuracy. The larger the number of bits, the smaller the channel period that can be set, so that the set period and duty cycle can be more accurate. Large output cycle.
Keywords:Freescale Reference address:Freescale's PWM output controls the direction of the servo motor

Previous article:C51 Programming Style
Next article:Freescale's Discrete Photoelectric Tube Path Identification

Recommended ReadingLatest update time:2024-11-16 14:59

Airbag solution based on Freescale MCU
Description of the program: The control unit is the core component of the airbag system and consists of a 16- or 32-bit MCU and a set of local acceleration sensors. Satellite sensors can be added according to the complexity of the system to provide auxiliary collision information through standard sensor buses s
[Embedded]
Airbag solution based on Freescale MCU
Freescale Smart Car - Electromagnetic Tracking (Energy Saving Group)
Design ideas of electromagnetic tracking part: Inductor collects electromagnetic signals, amplifies, rectifies, filters, and collects AD signals Electromagnetic signal amplification circuit: The operational amplifier uses TI's TL084, which can amplify two input signals at the same time. The amplification factor can
[Microcontroller]
Freescale Smart Car - Electromagnetic Tracking (Common to All Groups)
Design ideas of electromagnetic tracking part: Inductor collects electromagnetic signals, amplifies, rectifies, filters, and collects AD signals Electromagnetic signal amplification circuit: The operational amplifier uses NE5532 to amplify the signal twice. The amplification factor can be adjusted by the potentiomet
[Microcontroller]
Freescale 9S12 Series MCU Application Notes (ECT Module) 2
Experiment 2: Output Compare Function The so-called output compare function is to set the value of the output compare register as needed. The value of the free-running counter is compared with the value of the output compare register every 4 bus cycles. When the two are equal, a predetermined level will be output on
[Microcontroller]
Freescale 9S12 Series MCU Application Notes (ECT Module) 2
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号