Vous êtes sur la page 1sur 15

Microcontrleur ATMEL

Le signal PWM ou MLI

TON

TOFF

TPWM
La priode est fixe

TPWM = constante
Le rapport cyclique est variable

n=
P.Gurang
FICHIER : atmel mode pwl.pdf

TON

TPWM
1

Microcontrleur ATMEL

Principe de gnration
TOP

$0000
Un compteur interne au C balaye
les valeurs depuis $0000 jusqu'
une valeur maximale note TOP
TOP

$0000
Cette valeur sera ensuite compare
la valeur de comparaison comprise
entre $0000 et TOP
P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Choix de deux modes PWM :


Mode PWM

Mode PWM invers

P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Comment dterminer

FPWM

Rsolution : choix de la valeur TOP:


PWM
Rsolution
8-bit
9-bit
10-bit

Timer TOP
Value
$00FF (255)
$01FF (511)
$03FF (1023)

Frquence

FPWM
Fct1/510
Fct1/1022
Fct1/2046

Choix du prdiviseur :
La frquence du timer1 est obtenue
par division de la frquence du uC
note Fck par une valeur N

FCT1= FCK / N
N= 1,8,64,256,1024

FCK= 4 MHz pour les kits STK200


P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Bilan pour le 2313 :


Registre de comptage : Timer1
Registre de configuration :
TCCR1A

Choix du mode PWM


Choix de la rsolution

TCCR1B

Choix du facteur de prdivision

Registre de comparaison :
OCR1AL

(Rsolution 8 bit)

OCR1AH,OCR1AL
Cette valeur est ajuste en fonction du
rapport cyclique dsir

Signal PWM sur le PortB,3


P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Configuration des registres


TCCR1A

7
0 0
1
1

0
1

0 0

mode PWM
mode PWM invers
PWM sur 8 bit
PWM sur 9 bit
PWM sur 10 bit

P.Gurang
FICHIER : atmel mode pwl.pdf

0
1
1

1
0
1

Microcontrleur ATMEL

Configuration des registres


TCCR1B

7
0

0
0

Choix du facteur de
prdivision N
N=1
N=8
N = 64
N = 256
N = 1024

P.Gurang
FICHIER : atmel mode pwl.pdf

0
0
0
1
1

0
1
1
0
0

1
0
1
0
1
7

Microcontrleur ATMEL

Dtermination de N :

N8 bit =
N9 bit =
N10 bit=

FCK

FPWM

510

FCK

FPWM

1022

FCK

FPWM

2046

Il faut choisir N= 1,8,64,256,1024


et la rsolution correspondante

P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Exemple de configuration :

FPWM =

20 KHz

FCK = 10 MHz
Mode PWM

Valeur de N :

Rsolution :

P.Gurang
FICHIER : atmel mode pwl.pdf

Microcontrleur ATMEL

Frquences FPWM possibles :


Fck

4 000 000 Hz

64

256

1 024

Rsolution

Fct1

4 000 000

500 000

62 500

15 625

3 906

8 bits

Fpwm

7 843

980

123

31

9 bits

Fpwm

3 914

489

61

15

10 bits

Fpwm

1 955

244

31

FPWM en Hz avec FCK= 4MHZ

Complter :
Fck

N
Rsolution

Fct1

8 bits

Fpwm

9 bits

Fpwm

10 bits

Fpwm

10 000 000 Hz

64

256

1 024

FPWM en Hz avec FCK= 10MHZ


P.Gurang
FICHIER : atmel mode pwl.pdf

10

Microcontrleur ATMEL

Commande d'un servomoteur :

TON

T
Signal de commande
Priode = 20 mS ( Radio commande )
TON = 1,5 mS position neutre
Course utile
1 mS <= TON <= 2 mS
P.Gurang
FICHIER : atmel mode pwl.pdf

11

Microcontrleur ATMEL

Choix de la frquence de travail :

Rsolution = 10 Bits
N = 64

FCK

= 4 MHz

Mode PWM

Donner :
TCCR1A
TCCR1B

Complter :
T = 31 mS
TON = 1 mS Valeur PWM = 0x1F
TON = 1,5 mS Valeur PWM = 0x-TON = 2 mS
P.Gurang
FICHIER : atmel mode pwl.pdf

Valeur PWM = 0x--

Microcontrleur ATMEL

Mise en oeuvre du servomoteur


#include <90s2313.h>
#include <delay.h>

On inclus la librairie delay

// Declare your global variables here


void main(void)
{
// Declare your local variables here
unsigned char pwm = 0x1F;
unsigned char retard = 1000;

dclarations locales de
pwm et retard

// Input/Output Ports initialization Initialisation des


// Port B initialization
(code wizard)
PORTB=0x00;
DDRB=0x08;

ports

// Port D initialization
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 62,500 kHz
// Mode: Ph. correct PWM top=03FFh
// OC1 output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x83;
TCCR1B=0x03;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1H=0x00;
OCR1L=0x00;

P.Gurang
FICHIER : atmel mode pwl.pdf

Initialisation du timer 1
PWL (code wizard)

13

Microcontrleur ATMEL
Programme principal
while (1)
Boucle principale
{
// Place your code here

(perptuelle)

while ( pwm < 0x3F )


{
pwm = pwm + 1;
OCR1AL = pwm;
OCR1AH = 0;
delay_ms(retard);
}
while ( pwm > 0x1F )
{
pwm = pwm - 1;
OCR1AL = pwm;
OCR1AH = 0;
delay_ms(retard);
}
};
}

Que fait le programme prcdent ?

P.Gurang
FICHIER : atmel mode pwl.pdf

14

Microcontrleur ATMEL

Exemple de programmation :
INIT:
ldi R16,$C2
out TCCR1A
ldi R16,$01
out TCCR1B

--------

Initialisation
faite une fois
pour toute
quel est le mode
et la rsolution
initialis ii ?

MAIN:

-------ldi R16,$00
out OCR1AH
ldi R16,$42
out OCR1AL
P.Gurang
FICHIER : atmel mode pwl.pdf

Envoi de la valeur
du rapport cyclique
chaque fois que
ncessaire

15

Vous aimerez peut-être aussi