for our project we want to implement sbus capabilitys on the CF in combination with the Bigquad Deck. In order to free up USART 2_RX we want to remapp motor output 4 and use the USART 2_RX to read the SBUS signal.
In order to provide easy connection possibilities for our brushless ESC's we decided to remapp M4 to the CPPM connector on the Bigquad Deck. I desoldered the 1k pullup resistor R1 from the Bigquad Deck and resoldered it between the signal and 5V pin of the CPPM connector.
We then tested our SBUS code, getting its signal from the former M4 connector, working flawlessly.
To remapp the M4 output, we did the following changes in motors_def_cf2:
The original mapping
Code: Select all
const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
&DECK_TX2_TIM2,
&DECK_IO3,
&DECK_IO2,
&DECK_RX2_TIM2
};
Code: Select all
const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
&DECK_TX2_TIM2,
&DECK_IO3,
&DECK_IO2,
&DECK_MOSI
// &DECK_RX2_TIM2 remapped Motor4 to CPPM Connector to free up USART on E_RX2
};
Now my first question is, why states the comment in the motors_def_cf2 the following :
Code: Select all
/**
* Brushless motors mapped as on the Big-Quad deck
* M1 -> IO3
* M2 -> TX2
* M3 -> RX2
* M4 -> IO2
*/
Our main problem however is, that when trying to liftoff all the motors start spinning up but after approximately one second the CF decreases the speed of M2,M3 and M4. Only Motor 1 keeps spinning and the CF continually increase power to M1.
Even more confusing is, that according to the attached screenshot from the CF client logging M1 AND M3 are supposed to spin up, but only M1 does so. Is this behaviour explainable with incorrect motor mapping in our motors_edf_cf2?
When increasing the throttel rapidly from 0 to 50 or even 100% and then quickly lowering it back to 0%, all the motors spin up and down as expected. This leads me to believe the error isn't a hardware problem, induced by moving the pullup resitor from M4 to the CPPM Connector
As described in viewtopic.php?f=6&t=2067 , previously we tried to read the SBUS Signal from the RX pin of the I2C connector, but unfortunately we did not take account of the CrazyFlie's EEPROM on the I2C bus. This lead to errors during initialisation. Since moving away from the I2C pin, initialisation is ofcourse again succesfull on every startup and the communication with the EEPROM isn't disturbed anymore.
See below our complete motors_def_cf2:
Code: Select all
// Connector M1, PA1, TIM2_CH2
static const MotorPerifDef CONN_M1 =
{
.drvType = BRUSHED,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_1,
.gpioPinSource = GPIO_PinSource1,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_PWM_PERIOD,
.timPrescaler = MOTORS_PWM_PRESCALE,
.setCompare = TIM_SetCompare2,
.getCompare = TIM_GetCapture2,
.ocInit = TIM_OC2Init,
.preloadConfig = TIM_OC2PreloadConfig,
};
// Connector M2, PB11, TIM2_CH4
static const MotorPerifDef CONN_M2 =
{
.drvType = BRUSHED,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_11,
.gpioPinSource = GPIO_PinSource11,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_PWM_PERIOD,
.timPrescaler = MOTORS_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// Connector M3, PA15, TIM2_CH1
static const MotorPerifDef CONN_M3 =
{
.drvType = BRUSHED,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_15,
.gpioPinSource = GPIO_PinSource15,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_PWM_PERIOD,
.timPrescaler = MOTORS_PWM_PRESCALE,
.setCompare = TIM_SetCompare1,
.getCompare = TIM_GetCapture1,
.ocInit = TIM_OC1Init,
.preloadConfig = TIM_OC1PreloadConfig,
};
// Connector M4, PB9, TIM4_CH4
static const MotorPerifDef CONN_M4 =
{
.drvType = BRUSHED,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_9,
.gpioPinSource = GPIO_PinSource9,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM4,
.timPerif = RCC_APB1Periph_TIM4,
.tim = TIM4,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM4_STOP,
.timPeriod = MOTORS_PWM_PERIOD,
.timPrescaler = MOTORS_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// Connector M1, PA1, TIM2_CH2, Brushless config
static const MotorPerifDef CONN_M1_BL =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_1,
.gpioPinSource = GPIO_PinSource1,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_Low,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare2,
.getCompare = TIM_GetCapture2,
.ocInit = TIM_OC2Init,
.preloadConfig = TIM_OC2PreloadConfig,
};
// Connector M2, PB11, TIM2_CH4, Brushless config
static const MotorPerifDef CONN_M2_BL =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_11,
.gpioPinSource = GPIO_PinSource11,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_Low,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// Connector M3, PA15, TIM2_CH1, Brushless config
static const MotorPerifDef CONN_M3_BL =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_15,
.gpioPinSource = GPIO_PinSource15,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_Low,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare1,
.getCompare = TIM_GetCapture1,
.ocInit = TIM_OC1Init,
.preloadConfig = TIM_OC1PreloadConfig,
};
// Connector M4, PB9, TIM4_CH4, Brushless config
static const MotorPerifDef CONN_M4_BL =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_9,
.gpioPinSource = GPIO_PinSource9,
.gpioOType = GPIO_OType_PP,
.gpioAF = GPIO_AF_TIM4,
.timPerif = RCC_APB1Periph_TIM4,
.tim = TIM4,
.timPolarity = TIM_OCPolarity_Low,
.timDbgStop = DBGMCU_TIM4_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// Motor1, Deck TX2, PA2, TIM2_CH3
static const MotorPerifDef DECK_TX2_TIM2 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_2,
.gpioPinSource = GPIO_PinSource2,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare3,
.getCompare = TIM_GetCapture3,
.ocInit = TIM_OC3Init,
.preloadConfig = TIM_OC3PreloadConfig,
};
// Motor1, Deck TX2, PA2, TIM5_CH3
static const MotorPerifDef DECK_TX2_TIM5 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_2,
.gpioPinSource = GPIO_PinSource2,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM5,
.timPerif = RCC_APB1Periph_TIM5,
.tim = TIM5,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM5_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare3,
.getCompare = TIM_GetCapture3,
.ocInit = TIM_OC3Init,
.preloadConfig = TIM_OC3PreloadConfig,
};
// Motor4, Deck RX2, PA3, TIM2_CH4
static const MotorPerifDef DECK_RX2_TIM2 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_3,
.gpioPinSource = GPIO_PinSource3,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// Motor4, Deck RX2, PA3, TIM5_CH4
static const MotorPerifDef DECK_RX2_TIM5 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_3,
.gpioPinSource = GPIO_PinSource3,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM5,
.timPerif = RCC_APB1Periph_TIM5,
.tim = TIM5,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM5_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare4,
.getCompare = TIM_GetCapture4,
.ocInit = TIM_OC4Init,
.preloadConfig = TIM_OC4PreloadConfig,
};
// E_CS3, Deck IO1, PB8, TIM4_CH3
static const MotorPerifDef DECK_IO1_TIM4 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_8,
.gpioPinSource = GPIO_PinSource8,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM4,
.timPerif = RCC_APB1Periph_TIM4,
.tim = TIM4,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM4_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare3,
.getCompare = TIM_GetCapture3,
.ocInit = TIM_OC3Init,
.preloadConfig = TIM_OC3PreloadConfig,
};
// Motor3, Deck IO2, PB5, TIM3_CH2
static const MotorPerifDef DECK_IO2 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_5,
.gpioPinSource = GPIO_PinSource5,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM3,
.timPerif = RCC_APB1Periph_TIM3,
.tim = TIM3,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM3_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare2,
.getCompare = TIM_GetCapture2,
.ocInit = TIM_OC2Init,
.preloadConfig = TIM_OC2PreloadConfig,
};
// Motor2, Deck IO3, PB4, TIM3_CH1
static const MotorPerifDef DECK_IO3 =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOB,
.gpioPort = GPIOB,
.gpioPin = GPIO_Pin_4,
.gpioPinSource = GPIO_PinSource4,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM3,
.timPerif = RCC_APB1Periph_TIM3,
.tim = TIM3,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM3_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare1,
.getCompare = TIM_GetCapture1,
.ocInit = TIM_OC1Init,
.preloadConfig = TIM_OC1PreloadConfig,
};
// Deck SCK, PA5, TIM2_CH1
static const MotorPerifDef DECK_SCK =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_5,
.gpioPinSource = GPIO_PinSource5,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM2,
.timPerif = RCC_APB1Periph_TIM2,
.tim = TIM2,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM2_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare1,
.getCompare = TIM_GetCapture1,
.ocInit = TIM_OC1Init,
.preloadConfig = TIM_OC1PreloadConfig,
};
// Deck MISO, PA6, TIM3_CH1
static const MotorPerifDef DECK_MISO =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_6,
.gpioPinSource = GPIO_PinSource6,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM3,
.timPerif = RCC_APB1Periph_TIM3,
.tim = TIM3,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM3_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare1,
.getCompare = TIM_GetCapture1,
.ocInit = TIM_OC1Init,
.preloadConfig = TIM_OC1PreloadConfig,
};
// Deck MOSI, PA7, TIM3_CH2
// #### can be used to output Motor4 instead of E_RX2
// ### this enables USART capability to be used on E_RX2
static const MotorPerifDef DECK_MOSI =
{
.drvType = BRUSHLESS,
.gpioPerif = RCC_AHB1Periph_GPIOA,
.gpioPort = GPIOA,
.gpioPin = GPIO_Pin_7,
.gpioPinSource = GPIO_PinSource7,
.gpioOType = GPIO_OType_OD,
.gpioAF = GPIO_AF_TIM3,
.timPerif = RCC_APB1Periph_TIM3,
.tim = TIM3,
.timPolarity = TIM_OCPolarity_High,
.timDbgStop = DBGMCU_TIM3_STOP,
.timPeriod = MOTORS_BL_PWM_PERIOD,
.timPrescaler = MOTORS_BL_PWM_PRESCALE,
.setCompare = TIM_SetCompare2,
.getCompare = TIM_GetCapture2,
.ocInit = TIM_OC2Init,
.preloadConfig = TIM_OC2PreloadConfig,
};
/**
* Default brushed mapping to M1-M4 connectors.
*/
const MotorPerifDef* motorMapDefaultBrushed[NBR_OF_MOTORS] =
{
&CONN_M1,
&CONN_M2,
&CONN_M3,
&CONN_M4
};
/**
* Brushless motors mapped as on the Big-Quad deck
* M1 -> IO3
* M2 -> TX2
* M3 -> RX2
* M4 -> IO2
*/
const MotorPerifDef* motorMapBigQuadDeck[NBR_OF_MOTORS] =
{
&DECK_TX2_TIM2,
&DECK_IO3,
&DECK_IO2,
&DECK_MOSI
// &DECK_RX2_TIM2 remapped Motor4 to CPPM Connector to free up USART on E_RX2
};
/**
* Brushless motors mapped to the standard motor connectors with pull-ups (~1K) to VBAT soldered.
*/
const MotorPerifDef* motorMapDefaltConBrushless[NBR_OF_MOTORS] =
{
&CONN_M1_BL,
&CONN_M2_BL,
&CONN_M3_BL,
&CONN_M4_BL
};