Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_dualpwm_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Paparazzi Team
3  *
4  * This file is part of Paparazzi.
5  *
6  * Paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
26 //VALID TIMERS IS TIM5 ON THE LISA/M
27 
29 #include "subsystems/actuators/actuators_dualpwm_arch.h"
31 
32 #include <libopencm3/stm32/gpio.h>
33 #include <libopencm3/stm32/rcc.h>
34 #include <libopencm3/stm32/timer.h>
35 #include <libopencm3/cm3/nvic.h>
36 
37 #include "mcu_periph/gpio_arch.h"
38 
40 
41 
43 
47 
48  /*-----------------------------------
49  * Configure timer peripheral clocks
50  *-----------------------------------*/
51 #if PWM_USE_TIM1
52  rcc_periph_clock_enable(RCC_TIM1);
53 #endif
54 #if PWM_USE_TIM2
55  rcc_periph_clock_enable(RCC_TIM2);
56 #endif
57 #if PWM_USE_TIM3
58  rcc_periph_clock_enable(RCC_TIM3);
59 #endif
60 #if PWM_USE_TIM4
61  rcc_periph_clock_enable(RCC_TIM4);
62 #endif
63 #if PWM_USE_TIM5
64  rcc_periph_clock_enable(RCC_TIM5);
65 #endif
66 #if PWM_USE_TIM8
67  rcc_periph_clock_enable(RCC_TIM8);
68 #endif
69 #if PWM_USE_TIM9
70  rcc_periph_clock_enable(RCC_TIM9);
71 #endif
72 #if PWM_USE_TIM12
73  rcc_periph_clock_enable(RCC_TIM12);
74 #endif
75 
76  /*----------------
77  * Configure GPIO
78  *----------------*/
79 #ifdef DUAL_PWM_SERVO_5
80  gpio_setup_pin_af(DUAL_PWM_SERVO_5_GPIO, DUAL_PWM_SERVO_5_PIN, DUAL_PWM_SERVO_5_AF, TRUE);
81 #endif
82 #ifdef DUAL_PWM_SERVO_6
83  gpio_setup_pin_af(DUAL_PWM_SERVO_6_GPIO, DUAL_PWM_SERVO_6_PIN, DUAL_PWM_SERVO_6_AF, TRUE);
84 #endif
85 
86 #if DUAL_PWM_USE_TIM5
88 
89  nvic_set_priority(NVIC_TIM5_IRQ, 2);
90  nvic_enable_irq(NVIC_TIM5_IRQ);
91  timer_enable_irq(TIM5, TIM_DIER_CC1IE);
92 #endif
93 
94  //calculation the values to put into the timer registers to generate pulses every 4ms and 16ms.
95  ratio_4ms = (ONE_MHZ_CLK / 250)-1;
96  ratio_16ms = (ONE_MHZ_CLK / 62.5)-1;
97 
98 }
99 
100 
103 #if DUAL_PWM_USE_TIM5
104 void tim5_isr(void){
105 
106  dual_pwm_isr();
107 }
108 #endif
109 
110 
111 
112 
115 void clear_timer_flag(void){
116 
117 #if DUAL_PWM_USE_TIM5
118  timer_clear_flag(TIM5, TIM_SR_CC1IF);
119 #endif
120 }
121 
122 
124 
125 #if DUAL_PWM_USE_TIM5
126  timer_set_period(TIM5, period);
127 #endif
128 }
129 
130 
132 
133 #if DUAL_PWM_USE_TIM5
134  timer_set_oc_value(DUAL_PWM_SERVO_5_TIMER, DUAL_PWM_SERVO_5_OC, oc_value);
135 #endif
136 }
137 
138 
139 
140 
141 void dual_pwm_isr(void){
142 
143  static int num_pulse = 0; //status of the timer. Are we controling the first or the second servo
144 
146 
147  if(num_pulse == 1){
148 
150  set_dual_pwm_timer_s_oc(actuators_dualpwm_values[FIRST_DUAL_PWM_SERVO]);
151 
152  num_pulse = 0;
153  }else{
154 
156  set_dual_pwm_timer_s_oc(actuators_dualpwm_values[SECOND_DUAL_PWM_SERVO]);
157 
158  num_pulse = 1;
159  }
160 }
161 
162 
166 
167  //we don't need to commit the values into this function as far as it's done in the interuption
168  //(wich is called every 4ms and 16ms alternatively (twice every 20ms))
169 
170 }
timer_clear_flag(TIM6, TIM_SR_UIF)
void dual_pwm_isr(void)
void actuators_dualpwm_commit(void)
Set pulse widths from actuator values, assumed to be in us.
void clear_timer_flag(void)
Interuption called at the end of the timer.
#define NVIC_TIM5_IRQ
void set_dual_pwm_timer_s_period(uint32_t period)
void set_servo_timer(uint32_t timer, uint32_t period, uint8_t channels_mask)
Set Timer configuration.
unsigned long uint32_t
Definition: types.h:18
uint32_t ratio_4ms
#define PWM_TIM5_CHAN_MASK
Definition: krooz_sd.h:354
uint32_t actuators_dualpwm_values[ACTUATORS_PWM_NB]
#define ACTUATORS_PWM_NB
STM32 PWM and dualPWM servos shared functions.
#define TRUE
Definition: imu_chimu.h:144
void gpio_setup_pin_af(uint32_t port, uint16_t pin, uint8_t af, bool_t is_output)
Setup a gpio for input or output with alternate function.
#define ONE_MHZ_CLK
void actuators_dualpwm_arch_init(void)
Arch dependent init file.
CM3_WEAK tim5_isr(void)
uint32_t ratio_16ms
void set_dual_pwm_timer_s_oc(uint32_t oc_value)
#define TIM5_SERVO_HZ