|
@@ -51,7 +51,7 @@ void TIM4_IRQHandler(void)
|
51
|
51
|
* @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
|
52
|
52
|
* @retval None
|
53
|
53
|
*/
|
54
|
|
-void Timer_IT_Enable(TIM_TypeDef * timer)
|
|
54
|
+void Timer_IT_enable(TIM_TypeDef * timer)
|
55
|
55
|
{
|
56
|
56
|
LL_TIM_EnableIT_UPDATE(timer);
|
57
|
57
|
}
|
|
@@ -63,7 +63,7 @@ void Timer_IT_Enable(TIM_TypeDef * timer)
|
63
|
63
|
* @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
|
64
|
64
|
* @retval None
|
65
|
65
|
*/
|
66
|
|
-void Timer_IT_Disable(TIM_TypeDef * timer)
|
|
66
|
+void Timer_IT_disable(TIM_TypeDef * timer)
|
67
|
67
|
{
|
68
|
68
|
LL_TIM_DisableIT_UPDATE(timer);
|
69
|
69
|
}
|
|
@@ -76,7 +76,7 @@ void Timer_IT_Disable(TIM_TypeDef * timer)
|
76
|
76
|
* int Prio : priorité associée à l'interruption
|
77
|
77
|
* @retval None
|
78
|
78
|
*/
|
79
|
|
-void Timer_IT_Conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
|
|
79
|
+void Timer_IT_conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
|
80
|
80
|
{
|
81
|
81
|
// affectation de la fonction
|
82
|
82
|
if (timer == TIM1) it_callback_TIM1 = it_callback;
|
|
@@ -114,7 +114,6 @@ void Timer_IT_Conf(TIM_TypeDef * timer, void (*it_callback) (void), int prio)
|
114
|
114
|
*/
|
115
|
115
|
void Timer_start(TIM_TypeDef * timer)
|
116
|
116
|
{
|
117
|
|
- Timer_IT_Enable(timer);
|
118
|
117
|
LL_TIM_EnableCounter(timer);
|
119
|
118
|
}
|
120
|
119
|
|
|
@@ -126,7 +125,6 @@ void Timer_start(TIM_TypeDef * timer)
|
126
|
125
|
*/
|
127
|
126
|
void Timer_stop(TIM_TypeDef * timer)
|
128
|
127
|
{
|
129
|
|
- Timer_IT_Disable(timer);
|
130
|
128
|
LL_TIM_DisableCounter(timer);
|
131
|
129
|
}
|
132
|
130
|
|
|
@@ -138,9 +136,9 @@ void Timer_stop(TIM_TypeDef * timer)
|
138
|
136
|
* int Psc : valeur à placer dans PSC
|
139
|
137
|
* @retval None
|
140
|
138
|
*/
|
141
|
|
-void Timer_conf(TIM_TypeDef * timer, int arr, int psc, void (*it_callback) (void))
|
|
139
|
+void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
|
142
|
140
|
{
|
143
|
|
- LL_TIM_InitTypeDef My_LL_Tim_Init_Struct;
|
|
141
|
+ LL_TIM_InitTypeDef init_struct;
|
144
|
142
|
|
145
|
143
|
// Validation horloge locale
|
146
|
144
|
if (timer == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
|
@@ -149,16 +147,17 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc, void (*it_callback) (void
|
149
|
147
|
else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
150
|
148
|
|
151
|
149
|
// chargement structure Arr, Psc, Up Count
|
152
|
|
- My_LL_Tim_Init_Struct.Autoreload = arr;
|
153
|
|
- My_LL_Tim_Init_Struct.Prescaler = psc;
|
154
|
|
- My_LL_Tim_Init_Struct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
155
|
|
- My_LL_Tim_Init_Struct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
156
|
|
- My_LL_Tim_Init_Struct.RepetitionCounter = 0;
|
|
150
|
+ init_struct.Autoreload = arr;
|
|
151
|
+ init_struct.Prescaler = psc;
|
|
152
|
+ init_struct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
|
153
|
+ init_struct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
|
154
|
+ init_struct.RepetitionCounter = 0;
|
157
|
155
|
|
158
|
|
- LL_TIM_Init(timer,&My_LL_Tim_Init_Struct);
|
159
|
|
-
|
160
|
|
- Timer_IT_Conf(timer, it_callback, 3);
|
|
156
|
+ LL_TIM_Init(timer,&init_struct);
|
161
|
157
|
|
|
158
|
+ // Blocage interruptions
|
|
159
|
+ Timer_IT_disable(timer);
|
|
160
|
+
|
162
|
161
|
// Blocage Timer
|
163
|
162
|
Timer_stop(timer);
|
164
|
163
|
}
|
|
@@ -172,14 +171,31 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc, void (*it_callback) (void
|
172
|
171
|
* PWM OUTPUT
|
173
|
172
|
***************************************************************************/
|
174
|
173
|
|
175
|
|
-void PWMo_conf(TIM_TypeDef * timer, int channel, int arr, int psc)
|
|
174
|
+int getArrFromFreq(float freq_khz)
|
176
|
175
|
{
|
177
|
|
-
|
|
176
|
+ return (72000 / freq_khz) - 1;
|
178
|
177
|
}
|
179
|
178
|
|
180
|
|
-void PWMo_setDutyCycle(TIM_TypeDef * timer, int dutyCycle)
|
|
179
|
+void PWMo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle)
|
181
|
180
|
{
|
|
181
|
+ Timer_conf(timer, getArrFromFreq(freq_khz), 0);
|
|
182
|
+ LL_TIM_OC_InitTypeDef init_struct;
|
|
183
|
+ LL_TIM_OC_StructInit(&init_struct);
|
|
184
|
+
|
|
185
|
+ init_struct.OCMode = LL_TIM_OCMODE_PWM1;
|
|
186
|
+ init_struct.OCState = LL_TIM_OCSTATE_ENABLE;
|
|
187
|
+ init_struct.CompareValue= dutyCycle * getArrFromFreq(freq_khz);
|
182
|
188
|
|
|
189
|
+ LL_TIM_OC_Init(timer, channel, &init_struct);
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+void PWMo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle)
|
|
193
|
+{
|
|
194
|
+ int compare = dutyCycle * getArrFromFreq(freq_khz);
|
|
195
|
+ if (channel == LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(timer, compare);
|
|
196
|
+ else if (channel == LL_TIM_CHANNEL_CH2) LL_TIM_OC_SetCompareCH2(timer, compare);
|
|
197
|
+ else if (channel == LL_TIM_CHANNEL_CH3) LL_TIM_OC_SetCompareCH3(timer, compare);
|
|
198
|
+ else LL_TIM_OC_SetCompareCH4(timer, compare);
|
183
|
199
|
}
|
184
|
200
|
|
185
|
201
|
/****************************************************************************
|