Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_shared_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
27
28#include <libopencm3/stm32/timer.h>
29// for timer_get_frequency
30#include "arch/stm32/mcu_arch.h"
31
32
52
53
60{
61 /* Timer global mode:
62 * - No divider.
63 * - Alignement edge.
64 * - Direction up.
65 */
66 if ((timer == TIM9) || (timer == TIM12))
67 //There are no EDGE and DIR settings in TIM9 and TIM12
68 {
70 } else {
72 }
73
74
75 // By default the PWM_BASE_FREQ is set to 1MHz thus the timer tick period is 1uS
78
80
82
83 timer_set_period(timer, (PWM_BASE_FREQ / freq) - 1);
84
85 /* Disable outputs and configure channel if needed. */
86 if (bit_is_set(channels_mask, 0)) {
88 }
89 if (bit_is_set(channels_mask, 1)) {
91 }
92 if (bit_is_set(channels_mask, 2)) {
94 }
95 if (bit_is_set(channels_mask, 3)) {
97 }
98
99 /*
100 * Set initial output compare values.
101 * Note: Maybe we should preload the compare registers with some sensible
102 * values before we enable the timer?
103 */
104 //timer_set_oc_value(timer, TIM_OC1, 1000);
105 //timer_set_oc_value(timer, TIM_OC2, 1000);
106 //timer_set_oc_value(timer, TIM_OC3, 1000);
107 //timer_set_oc_value(timer, TIM_OC4, 1000);
108
109 /* -- Enable timer -- */
110 /*
111 * ARR reload enable.
112 * Note: In our case it does not matter much if we do preload or not. As it
113 * is unlikely we will want to change the frequency of the timer during
114 * runtime anyways.
115 */
117
118 /* Counter enable. */
120
121}
122
void actuators_pwm_arch_channel_init(uint32_t timer_peripheral, enum tim_oc_id oc_id)
Set PWM channel configuration.
void set_servo_timer(uint32_t timer, uint32_t freq, uint8_t channels_mask)
Set Timer configuration.
STM32 PWM and dualPWM servos shared functions.
#define PWM_BASE_FREQ
uint16_t foo
Definition main_demo5.c:58
uint32_t timer_get_frequency(uint32_t timer_peripheral)
Get Timer clock frequency (before prescaling) Only valid if using the internal clock for the timer.
Definition mcu_arch.c:311
stm32 arch dependant microcontroller initialisation functions.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.