I have some STM32F103C8T6 code to receive an RC servo signal
on PB6 (TIM4.CH1) using timer 4 in PWM mode. The problem I
have encountered with the API is that there seems to be missing API
to configure the values shown in yellow below. The following
is the configuration code I used that got it working:
rcc_periph_clock_enable(RCC_TIM4); // Need TIM4 clock
// PB6 == TIM4.CH1
rcc_periph_clock_enable(RCC_GPIOB); // Need GPIOB clock
gpio_set_mode(GPIOB,GPIO_MODE_INPUT, // Input
GPIO_CNF_INPUT_FLOAT,GPIO6); // PB6=TIM4.CH1
// TIM4:
timer_disable_counter(TIM4);
timer_reset(TIM4);
nvic_set_priority(NVIC_DMA1_CHANNEL3_IRQ,2);
nvic_enable_irq(NVIC_TIM4_IRQ);
timer_set_mode(TIM4,
TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE,
TIM_CR1_DIR_UP);
timer_set_prescaler(TIM4,72);
timer_ic_set_input(TIM4,TIM_IC1,TIM_IC_IN_TI1);
timer_ic_set_input(TIM4,TIM_IC2,TIM_IC_IN_TI1);
timer_ic_set_filter(TIM4,TIM_IC_IN_TI1,TIM_IC_CK_INT_N_2);
timer_ic_set_prescaler(TIM4,TIM_IC1,TIM_IC_PSC_OFF);
timer_slave_set_mode(TIM4,TIM_SMCR_SMS_RM);
timer_slave_set_trigger(TIM4,TIM_SMCR_TS_TI1FP1);
TIM_CCER(TIM4) &= 0b110011; // .CCxP and .CCxE cleared
TIM_CCER(TIM4) |= 0b110001;
timer_ic_enable(TIM4,TIM_IC1);
timer_ic_enable(TIM4,TIM_IC2);
timer_enable_irq(TIM4,TIM_DIER_CC1IE|TIM_DIER_CC2IE);
timer_enable_counter(TIM4);
What appears to be missing is a way to establish TIM_CCER(TIM4).CC1E,
.CC1P, .CC2E, .CC2P
etc. for *input mode.* In PWM Mode CC1E enables capture mode, but CC1P sets
the polarity. I see
functions for OC in this regard but it seems to be missing for IC.
I can use the macros as is but suspect that there was intended a C function
for this.
There is a function timer_ic_enable/disable() along the lines of:
void timer_ic_disable(uint32_t timer_peripheral, enum tim_ic_id ic)
{
TIM_CCER(timer_peripheral) &= ~(0x1 << (ic * 4));
}
which configures CCER for input *enables*, but I didn't find anything for
the .CC1E/.CC1P bits,
for input.
The procedure is outlined in RM0008 p383-384, section 15.3.6 PWM Input Mode
for reference.
Warren
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
libopencm3-devel mailing list
libopencm3-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel