mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Working on the PPM functionality. Getting there but it is still not 100% correct.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@411 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
abd77939e5
commit
f1694527cc
@ -138,6 +138,7 @@ SRC += $(PIOSSTM32F10X)/pios_adc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_servo.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_i2c.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_spi.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_ppm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||
|
@ -290,7 +290,7 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
#define PIOS_PPM_TIM TIM1
|
||||
#define PIOS_PPM_TIM_IRQ TIM1_CC_IRQn
|
||||
#define PIOS_PPM_NUM_INPUTS 8 //Could be more if needed
|
||||
#define PIOS_PPM_SUPV_ENABLED 0
|
||||
#define PIOS_PPM_SUPV_ENABLED 1
|
||||
#define PIOS_PPM_SUPV_TIMER TIM6
|
||||
#define PIOS_PPM_SUPV_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE)
|
||||
#define PIOS_PPM_SUPV_HZ 25
|
||||
@ -378,8 +378,8 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5
|
||||
/* Sample time: */
|
||||
/* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */
|
||||
/* Tconv = 239.5 + 12.5 = 252 cycles = 18µs */
|
||||
/* (1 / (ADCCLK / CYCLES)) = Sample Time (µS) */
|
||||
/* Tconv = 239.5 + 12.5 = 252 cycles = 18<EFBFBD>s */
|
||||
/* (1 / (ADCCLK / CYCLES)) = Sample Time (<EFBFBD>S) */
|
||||
#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH
|
||||
|
||||
//-------------------------
|
||||
|
@ -96,6 +96,8 @@ int main()
|
||||
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
//PIOS_PPM_Init();
|
||||
|
||||
PIOS_PWM_Init();
|
||||
|
||||
PIOS_USB_Init(0);
|
||||
@ -171,6 +173,7 @@ static void TaskTesting(void *pvParameters)
|
||||
*/
|
||||
|
||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%u,%u,%u,%u,%u,%u,%u,%u uS\r", PIOS_PWM_Get(0), PIOS_PWM_Get(1), PIOS_PWM_Get(2), PIOS_PWM_Get(3), PIOS_PWM_Get(4), PIOS_PWM_Get(5), PIOS_PWM_Get(6), PIOS_PWM_Get(7));
|
||||
//PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "%u,%u,%u,%u,%u,%u,%u,%u uS\r", PIOS_PPM_Get(0), PIOS_PPM_Get(1), PIOS_PPM_Get(2), PIOS_PPM_Get(3), PIOS_PPM_Get(4), PIOS_PPM_Get(5), PIOS_PPM_Get(6), PIOS_PPM_Get(7));
|
||||
|
||||
/* This blocks the task until there is something on the buffer */
|
||||
/*xSemaphoreTake(PIOS_USART1_Buffer, portMAX_DELAY);
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
static TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||
static uint8_t PulseIndex;
|
||||
static uint8_t CaptureState;
|
||||
static uint16_t RiseValue;
|
||||
static uint16_t FallValue;
|
||||
static uint32_t PreviousValue;
|
||||
static uint32_t CurrentValue;
|
||||
static uint32_t CapturedValue;
|
||||
static uint32_t CaptureValue[PIOS_PPM_NUM_INPUTS];
|
||||
|
||||
static uint8_t SupervisorState = 0;
|
||||
@ -54,9 +54,9 @@ void PIOS_PPM_Init(void)
|
||||
int32_t i;
|
||||
|
||||
PulseIndex = 0;
|
||||
CaptureState = 0;
|
||||
RiseValue = 0;
|
||||
FallValue = 0;
|
||||
PreviousValue = 0;
|
||||
CurrentValue = 0;
|
||||
CapturedValue = 0;
|
||||
|
||||
for(i = 0; i < PIOS_PPM_NUM_INPUTS; i++) {
|
||||
CaptureValue[i] = 0;
|
||||
@ -172,47 +172,31 @@ int32_t PIOS_PPM_Get(int8_t Channel)
|
||||
void TIM1_CC_IRQHandler(void)
|
||||
{
|
||||
/* Do this as it's more efficient */
|
||||
if(TIM_GetITStatus(PIOS_PWM_CH1_TIM_PORT, RECEIVER1_CCR) == SET) {
|
||||
if(CaptureState == 0) {
|
||||
RiseValue = TIM_GetCapture2(PIOS_PWM_CH1_TIM_PORT);
|
||||
} else {
|
||||
FallValue = TIM_GetCapture2(PIOS_PWM_CH1_TIM_PORT);
|
||||
}
|
||||
if(TIM_GetITStatus(PIOS_PPM_TIM_PORT, PIOS_PPM_TIM_CCR) == SET) {
|
||||
PreviousValue = CurrentValue;
|
||||
CurrentValue = TIM_GetCapture2(PIOS_PPM_TIM_PORT);
|
||||
}
|
||||
|
||||
/* Clear TIM3 Capture compare interrupt pending bit */
|
||||
TIM_ClearITPendingBit(PIOS_PWM_CH1_TIM_PORT, RECEIVER1_CCR);
|
||||
TIM_ClearITPendingBit(PIOS_PPM_TIM_PORT, PIOS_PPM_TIM_CCR);
|
||||
|
||||
/* Simple rise or fall state machine */
|
||||
if(CaptureState == 0) {
|
||||
/* Switch states */
|
||||
CaptureState = 1;
|
||||
|
||||
/* Switch polarity of input capture */
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
|
||||
TIM_ICInitStructure.TIM_Channel = RECEIVER1_CH;
|
||||
TIM_ICInit(PIOS_PWM_CH1_TIM_PORT, &TIM_ICInitStructure);
|
||||
|
||||
} else {
|
||||
/* Capture computation */
|
||||
if (FallValue > RiseValue) {
|
||||
//need to change
|
||||
CaptureValue[0] = (FallValue - RiseValue);
|
||||
if (CurrentValue > PreviousValue) {
|
||||
CapturedValue = (CurrentValue - PreviousValue);
|
||||
} else {
|
||||
//need to change
|
||||
CaptureValue[0] = ((0xFFFF - RiseValue) + FallValue);
|
||||
CapturedValue = ((0xFFFF - PreviousValue) + CurrentValue);
|
||||
}
|
||||
|
||||
/* Switch states */
|
||||
CaptureState = 0;
|
||||
|
||||
/* Increase supervisor counter */
|
||||
CapCounter[0]++;
|
||||
|
||||
/* Switch polarity of input capture */
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||
TIM_ICInitStructure.TIM_Channel = RECEIVER1_CH;
|
||||
TIM_ICInit(PIOS_PWM_CH1_TIM_PORT, &TIM_ICInitStructure);
|
||||
/* sync pulse */
|
||||
if(CapturedValue > 8000) {
|
||||
PulseIndex = 0;
|
||||
/* trying to detect bad pulses, not sure this is working correctly yet. I need a scope :P */
|
||||
} else if(CapturedValue > 750 && CapturedValue < 2500) {
|
||||
if(PulseIndex < PIOS_PPM_NUM_INPUTS) {
|
||||
CaptureValue[PulseIndex] = CapturedValue;
|
||||
CapCounter[PulseIndex]++;
|
||||
PulseIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
33
flight/PiOS/inc/pios_ppm.h
Normal file
33
flight/PiOS/inc/pios_ppm.h
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pios_ppm.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief PWM Input functions header.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PIOS_PPM_H
|
||||
#define PIOS_PPM_H
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_PPM_Init(void);
|
||||
extern int32_t PIOS_PPM_Get(int8_t Channel);
|
||||
|
||||
#endif /* PIOS_PPM_H */
|
@ -73,6 +73,7 @@
|
||||
#include <pios_servo.h>
|
||||
#include <pios_i2c.h>
|
||||
#include <pios_spi.h>
|
||||
#include <pios_ppm.h>
|
||||
#include <pios_pwm.h>
|
||||
#include <pios_usb.h>
|
||||
#include <pios_usb_hid.h>
|
||||
|
Loading…
Reference in New Issue
Block a user