Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
PWM_Set_Duty
PWM_Start
324
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Description
The N variable represents the prescaler factor (1, 8, 64, 256, or 1024). Some
modules also support 32 and 128 prescaler value, but for this you will need to
check the datasheet for the desired MCU)
PWM_Init must be called before using other functions from PWM Library.
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):
DDRB.3 = 1; // set PORTB pin 3 as output for the PWM
This code example is for ATmega16, for different MCU please consult datasheet
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
procedure PWM_Set_Duty(duty : 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 
(Percent*255)/100
.
Requires
PWM module must to be initialised (PWM_Init) before using PWM_Set_Duty
function.
Example
For example lets set duty ratio to 75%:
PWM_Set_Duty(192);
Prototype
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.
Example
PWM_Start();