Académique Documents
Professionnel Documents
Culture Documents
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
P.Gurang
FICHIER : atmel mode pwl.pdf
Microcontrleur ATMEL
Comment dterminer
FPWM
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
Microcontrleur ATMEL
TCCR1B
Registre de comparaison :
OCR1AL
(Rsolution 8 bit)
OCR1AH,OCR1AL
Cette valeur est ajuste en fonction du
rapport cyclique dsir
Microcontrleur ATMEL
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
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
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
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
Complter :
Fck
N
Rsolution
Fct1
8 bits
Fpwm
9 bits
Fpwm
10 bits
Fpwm
10 000 000 Hz
64
256
1 024
10
Microcontrleur ATMEL
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
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
Microcontrleur ATMEL
dclarations locales de
pwm et retard
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)
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