forked from poppy-project/poppy_com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwm.c
90 lines (71 loc) · 1.86 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
84
85
86
87
88
89
/*
* 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"
static uint PowerledR,PowerledV,PowerledB;
void pwm_init(void)
{
//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)
{
//l'ajout des instruction retarde l'allumage des leds et permet de masquer la latence à vérifier
OCR1A = PowerledR; //mise à jour systématique
OCR1B = PowerledV;
OCR1C = PowerledB;
if (system_data.led.R!=0)
PERIPH_LED_PORT|= _BV(PERIPH_RED_PIN);
if (system_data.led.G!=0)
PERIPH_LED_PORT|= _BV(PERIPH_GREEN_PIN);
if (system_data.led.B!=0)
PERIPH_LED_PORT|= _BV(PERIPH_BLUE_PIN);
}
// calcul la valeur à donneé a la pwm
uint set_color(uint R,uint G,uint B,uint Alpha)
{
PowerledR = R*Alpha/64;//todo corriger le type de R en uint
PowerledV = G*Alpha/64;
PowerledB = B*Alpha/64;
uint erreur = 0;
return erreur;
}
void set_color_s(led_power lp)
{
set_color(lp.R,lp.G,lp.B,lp.A);
}