Simple and efficient functions for PWM configuration and usage. More...
Go to the source code of this file.
Simple and efficient functions for PWM configuration and usage.
Simple and efficient functions for PWM configuration and usage. The SBC66 Netcruzer boards have 9 PWM channels. They can be assigned to any of the Relocatable Ports. For the location of the Relocatable Ports, see modtronix.com/product/sbc66ec/ To use a PWM channel, first call pwmOpenDefault() function, and then pwmSetDutyCycle() and pwmSetPercent() functions to set PWM duty cycle or percentage.
When channel is configured for 16kHz (default), duty cycle percentages can be changed in 0.1% steps. For example, pwmSetPercent(2, 1.5) will set PWM 2 to 1.5% duty cycle. In this mode, 0.1% is not possible, and will result in a duty cycle of 0%. From 0.2% all values work as expected.
When channel is configured for 160kHz, duty cycle percentages can be changed in 1% steps. For example, pwmSetPercent(1, 5) will set PWM 1 to 5% duty cycle. In this mode, 1% is not possible, and will result in a duty cycle of 0%. From 2% all values work as expected.
When channel is configured for 1.6kHz, duty cycle percentages can be changed in 0.01% steps. For example, pwmSetPercent(1, 1.42) will set PWM 1 to 1.42% duty cycle. In this mode, 0.01% is not possible, and will result in a duty cycle of 0%. From 0.02% all values work as expected.
Each PWM module has it's own timer, implemented as a 16-bit timer. The clock for each timer is configured by this module to be 16MHz, giving a 62.5ns period. Each PWM channel has two registers, OCxRS (period) and OCxR (duty cycle). The PWM timer will count from 0 upwards, and when equal to the value of OCxRS, will reset to 0 on next clock. For example, when OCxRS=999, it will count from 0-999 (1000 steps). This determines the frequency(period) of the PWM channel, and is calculated (1/((OCxRS+1)*62.5ns)). For example, a OCxRS value of 999 gives a frequency of 16kHz.
The value of the OCxR register determines the duty cycle of the PWM. When the PWM timer resets to 0, the output goes high (if OCxR!=0). It will remain high until OCxR = PWM timer, and then on the NEXT clock it will go low. This means that the PWM output can NOT be configured to be high for a single clock, but minimum 2 clocks.
The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.
The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.
THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
File History
2010-06-06, David Hosken (DH):