================================================================================ Base Timer PWM Example ================================================================================ Created by Manuel Schreiner, Copyright © 2016 io-expert.com. All rights reserved. 1. Redistributions of source code must retain the above copyright notice, this condition and the following disclaimer. This software is provided by the copyright holder and contributors "AS IS" and any warranties related to this software are DISCLAIMED. The copyright owner or contributors be NOT LIABLE for any damages caused by use of this software. ========================================================================== History Date Ver Author Description 2016-04-17 1.0 Manuel Schreiner Initial ========================================================================== This example can run on every FM microcontroller. PWM signal output is produced at TIOA0_1 This project demonstrates how to generate a PWM signal using Base Timer channel 0 in PWM mode. The PWM is generated by setting the high time and the period of the output signal. The Base Timer is started using a software trigger. PWM Output: |-------------------| |------------------- ___________________| |___________________| < high time > < period > Current Clock settings: PCLK1 : __HCLK Base Timer clock count divider : 4 Base Timer clock count : __HCLK / 4 Timer register values for high time and period are calculated by the given formulas : high time = T(m + 1) s period = T(n + 1) s T is the clock count cycle which, in this case, is 4/__HCLK. m is the value that is written to the PDUT register (PWM duty set register). n is the value that is written to the PCSR register (PWM cycle set register). The maximum value for the high time or the period that can be generated using the current clock settings is given by : (65535 + 1) / (4/__HCLK). Make sure that the value in the PDUT register is not greater than the value in the PCSR register. duty cycle can be calculated by : (PDUT / PCSR) * 100 ================================================================================ EOF (not truncated) ================================================================================