Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Note: Not all of the MCUs have 16bit PWM, and not all of the MCUs have both Timer/Counter1
and Timer/Counter3. Sometimes, like its the case with ATmega168, MCU has only
Timer/Counter1 and channels A and B. Therefore constants that have in their name Timer3 or
channel C are invalid (for ATmega168) and will not be visible from Code Assistant. It is highly
advisable to use this feature, since it handles all the constants (available) and eliminates any
chance of typing error.
PWM16bit_Init
319
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure PWM16bit_Init(dim wave_mode as bytedim prescaler as
byte
dim inverted as bytedim duty as worddim timer as byte)
Returns
Nothing.
Description
Initializes the PWM module. Parameter 
wave_mode
is a desired PWM-16bit
mode. 
There are several modes included :
- PWM, Phase Correct, 8-bit 
- PWM, Phase Correct, 9-bit 
- PWM, Phase Correct, 10-bit 
- Fast PWM, 8-bit 
- Fast PWM, 9-bit 
- Fast PWM, 10-bit 
Parameter 
prescaler
chooses prescale value N = 1,8,64,256 or 1024 (some
modules support 32 and 128, but for this you will need to check the datasheet
for the desired MCU). Paremeter 
inverted
is for choosing between inverted
and non inverted PWM signal. Parameter 
duty
sets duty ratio from 0 to TOP
value (this value varies on the PWM wave mode selected). PWM signal graphs
and formulas are shown below.