/* ################################################################### ** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT. ** Filename : PWM1.c ** Project : DMK-BC316-77-AUTO ** Processor : MC9S12ZVL32MLF ** Component : PWM ** Version : Component 02.240, Driver 01.16, CPU db: 3.00.000 ** Compiler : CodeWarrior HCS12Z C Compiler ** Date/Time : 2018-03-24, 10:58, # CodeGen: 18 ** Abstract : ** This component implements a pulse-width modulation generator ** that generates signal with variable duty and fixed cycle. ** Settings : ** Used output pin : ** ---------------------------------------------------- ** Number (on package) | Name ** ---------------------------------------------------- ** 39 | PP5_XIRQ_KWP5_PWM5 ** ---------------------------------------------------- ** ** Timer name : PWM5 [8-bit] ** Counter : PWMCNT5 [0x0491] ** Mode register : PWMCTL [0x0485] ** Run register : PWME [0x0480] ** Prescaler : PWMPRCLK [0x0483] ** Compare 1 register : PWMPER5 [0x0499] ** Compare 2 register : PWMDTY5 [0x04A1] ** Flip-flop 1 register : PWMPOL [0x0481] ** ** User handling procedure : not specified ** ** Output pin ** ** Port name : P ** Bit number (in port) : 5 ** Bit mask of the port : 0x0020 ** Port data register : PTP [0x02F0] ** Port control register : DDRP [0x02F2] ** ** Runtime setting period : none ** Runtime setting ratio : calculated ** Initialization: ** Aligned : Left ** Output level : low ** Timer : Enabled ** Event : Enabled ** High speed mode ** Prescaler : divide-by-1 ** Clock : 53333 Hz ** Initial value of period pulse width (ratio 0%) ** Xtal ticks : 4781 0 ** microseconds : 4781 0 ** milliseconds : 5 0 ** seconds (real) : 0.00478125 0.0 ** ** Contents : ** SetRatio16 - byte PWM1_SetRatio16(word Ratio); ** SetDutyUS - byte PWM1_SetDutyUS(word Time); ** SetDutyMS - byte PWM1_SetDutyMS(word Time); ** ** Copyright : 1997 - 2014 Freescale Semiconductor, Inc. ** All Rights Reserved. ** ** Redistribution and use in source and binary forms, with or without modification, ** are permitted provided that the following conditions are met: ** ** o Redistributions of source code must retain the above copyright notice, this list ** of conditions and the following disclaimer. ** ** o Redistributions in binary form must reproduce the above copyright notice, this ** list of conditions and the following disclaimer in the documentation and/or ** other materials provided with the distribution. ** ** o Neither the name of Freescale Semiconductor, Inc. nor the names of its ** contributors may be used to endorse or promote products derived from this ** software without specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ** http: www.freescale.com ** mail: support@freescale.com ** ###################################################################*/ /*! ** @file PWM1.c ** @version 01.16 ** @brief ** This component implements a pulse-width modulation generator ** that generates signal with variable duty and fixed cycle. */ /*! ** @addtogroup PWM1_module PWM1 module documentation ** @{ */ /* MODULE PWM1. */ #include "PWM1.h" #pragma DATA_SEG PWM1_DATA /* Select data segment "PWM1_DATA" */ #pragma CODE_SEG PWM1_CODE static word RatioStore; /* Ratio of L-level to H-level */ /* ** =================================================================== ** Method : SetRatio (component PWM) ** ** Description : ** The method reconfigures the compare and modulo registers of ** the peripheral(s) when the speed mode changes. The method is ** called automatically as a part of the component ** SetHigh/SetLow/SetSlow methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void SetRatio(void) { PWMDTY7 = (byte)(((0xFFUL * (dword)RatioStore) + 0x8000UL) >> 0x10U); /* Calculate new value according to the given ratio */ } /* ** =================================================================== ** Method : PWM1_SetRatio16 (component PWM) ** Description : ** This method sets a new duty-cycle ratio. Ratio is expressed ** as a 16-bit unsigned integer number. Value 0 - 65535 value ** is proportional to ratio 0 - 100%. ** Note: Calculated duty depends on the timer possibilities and ** on the selected period. ** The method is available only if method is ** not selected. ** Parameters : ** NAME - DESCRIPTION ** Ratio - Ratio to set. 0 - 65535 value is ** proportional to ratio 0 - 100% ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** =================================================================== */ byte PWM1_SetRatio16(word Ratio) { RatioStore = Ratio; /* Store new value of the ratio */ SetRatio(); /* Calculate and set up new appropriate values of the duty and period registers */ return ERR_OK; /* OK */ } /* ** =================================================================== ** Method : PWM1_Init (component PWM) ** ** Description : ** Initializes the associated peripheral(s) and the component's ** internal variables. The method is called automatically as a ** part of the application initialization code. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void PWM1_Init(void) { /* PWMCNT7: PWMCNT7=0 */ setReg8(PWMCNT7, 0x00U); /* Reset Counter */ RatioStore = 0xFFFFU; ; /* Store initial value of the ratio */ /* PWMDTY7: PWMDTY7=0x82 */ setReg8(PWMDTY7, 0x00U); /* Store initial value to the duty-compare register */ /* PWMPER7: PWMPER7=0xFF */ setReg8(PWMPER7, 0xFFU); /* and to the period register */ /* PWMPRCLK: ??=0,PCKB2=0,PCKB1=0,PCKB0=0,??=0,PCKA2=0,PCKA1=0,PCKA0=0 */ setReg8(PWMPRCLK, 0x00U); /* Set prescaler register */ /* PWMSCLB: BIT7=0,BIT6=0,BIT5=0,BIT4=0,BIT3=1,BIT2=1,BIT1=0,BIT0=0 */ setReg8(PWMSCLB, 0x0CU); /* Set scale register */ /* PWMCLK: PCLK7=1 */ setReg8Bits(PWMCLK, 0x80U); /* Select clock source */ /* PWME: PWME7=1 */ setReg8Bits(PWME, 0x80U); /* Run counter */ } /* END PWM1. */ /*! ** @} */ /* ** ################################################################### ** ** This file was created by Processor Expert 10.3 [05.09] ** for the Freescale HCS12Z series of microcontrollers. ** ** ################################################################### */