Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
PWM16bit_Stop
Library Example
The example changes PWM duty ratio continually by pressing buttons on PORTC (0-3). If LED is
connected to PORTB.1 or PORTB.2 ,you can observe the gradual change of emitted light. This
example is written for ATmega168. This AVR MCU has only Timer/Counter1 split over two chan-
nels A and B. In this example we are changing the duty ratio on both of these channels.
program PWM16bit_Test;
var current_duty : byte;
current_duty1 : byte;
begin
DDRC.B0 := 0;                  // Set PORTC pin 0 as input
DDRC.B1 := 0;                  // Set PORTC pin 1 as input
DDRC.B2 := 0;                  // Set PORTC pin 2 as input
DDRC.B3 := 0;                  // Set PORTC pin 3 as input
current_duty := 255;           // initial value for current_duty
current_duty1 := 255;          // initial value for current_duty
DDRB.B1 := 1;                   // Set PORTB pin 1 as output pin for the PWM
(according to datasheet)
DDRB.B2 := 1;                // Set PORTB pin 2 as output pin for the PWM
(according to datasheet)
PWM16bit_Init(_PWM16_FAST_MODE_9BIT, _PWM16_PRESCALER_16bit_1, _PWM16_INVERTED,
255, 1);
while TRUE do
begin
if (PINC.B0 <> 0) then
// Detect if PORTC pin 0 is pressed
begin
335
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
procedure PWM16_Stop(timer : byte);
Returns
Nothing.
Description
Stops the PWM-16bit module, connected to Timer/Counter set in this stop function. 
Requires
MCU must have CMO module to use this library. Like in PWM16bit_Start
before, PWM16bit_Init must be called before using this routine , otherwise it will
have no effect as the PWM module is not running. 
Example
PWM16bit_Stop(_TIMER1 );
// Stops the PWM-16bit module on
Timer/Counter1
or
PWM16bit_Stop(_TIMER3 );
// Stops the PWM-16bit module on
Timer/Counter3