Mikroelektronika MIKROE-350 Fiche De Données
PWM_Set_Duty
PWM_Start
311
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Requires
You need a CMO on the given MCU (that supports PWM).
Before calling this routine you must set the output pin for the PWM (according
to the datasheet):
to the datasheet):
DDRB.3 = 1; // set PORTB pin 3 as output for the PWM
This code oxample is for ATmega16, for different MCU please consult datasheet
for the correct pinout of the PWM module or modules.
for the correct pinout of the PWM module or modules.
Example
Initialize PWM module:
PWM_Init(_PWM_FAST_MODE, _PWM_PRESCALER_8, _PWM_NON_INVERTED,
127)
Prototype
sub procedure PWM_Set_Duty(dim duty as byte)
Returns
Nothing.
Description
Changes PWM duty ratio. Parameter duty takes values from 0 to 255, where 0
is 0%, 127 is 50%, and 255 is 100% duty ratio. Other specific values for duty
ratio can be calculated as
is 0%, 127 is 50%, and 255 is 100% duty ratio. Other specific values for duty
ratio can be calculated as
(Percent*255)/100
.
Requires
PWM module must to be initialised (PWM_Init) before using PWM_Set_Duty
function.
function.
Example
For example lets set duty ratio to 75%:
PWM_Set_Duty(192)
Prototype
sub procedure PWM_Start()
Returns
Nothing.
Description
Starts PWM.
Requires
MCU must have CMO module to use this library. PWM_Init must be called
before
using this routine.
before
using this routine.
Example
PWM_Start()