-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwm.c
84 lines (64 loc) · 1.52 KB
/
pwm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* pwm.c
*
* Created: 31/10/2014
* Author:Damien
*/
#include <avr/io.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <avr/cpufunc.h>
#include "include/globaletypedef.h"
#include "include/PeriphMaster.h"
#include "include/pwm.h"
void pwm_init()
{
//disable interruption
//TCCR1A : COM1A1 COM1A0 COM1B1 COM1B0 COM1C1 COM1C0 WGM11 WGM10
TCCR1A = 0b0000011; //fast pwm 10 bits
//TCCR1B : ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10
TCCR1B = 0b0001010; //presaler clk/64 mode fast pwm
OCR1A = 0x0000; //12%
OCR1B = 0x0000;
OCR1C = 0x0000;
//TIMSK : OCIE2 TOIE2 TICIE1 OCIE1A OCIE1B TOIE1 OCIE0 TOIE0
TIMSK = 0b00011100; // validation interruption sur comparateur A et B et overflow
//ETIMSK : – – TICIE3 OCIE3A OCIE3B TOIE3 OCIE3C OCIE1C
ETIMSK = 0b00000001; //validation interruption sur comparateur C
//jetonPwm = 1; //jeton pris par defaut
}
ISR(TIMER1_COMPC_vect,ISR_NAKED)
{
__asm__("cbi 0x1b,0" );
reti();
}
ISR(TIMER1_COMPB_vect,ISR_NAKED)
{
__asm__("cbi 0x1b,2" );
reti();
}
ISR(TIMER1_COMPA_vect,ISR_NAKED)
{
__asm__("cbi 0x1b,1" );
reti();
}
ISR(TIMER1_OVF_vect) //naked suprimé sinon ça marche pas...
{
//allume les 3 leds
/*__asm__("sbi 0x1b,0" );
__asm__("sbi 0x1b,1" );
__asm__("sbi 0x1b,2" );*/
PERIPH_LED_PORT|= 0x07;
}
uint set_color(uint R,uint G,uint B,uint Alpha)
{
uint erreur = 0;
if (Alpha == 0)
TIMSK &= !_BV(TOIE1);
else
TIMSK |= _BV(TOIE1);
OCR1A = R*Alpha/63;
OCR1B = G*Alpha/63;
OCR1C = B*Alpha/63;
return erreur;
}