2020-07-18 02:26 PM
I've configured my STM32F303RE to send the COMP4 to the output (PB1) as well as to TIM4_Ch2. I also am running an external signal generator in from PB6 to TIM4_Ch1.
I can see the COMP4 output on PB1 but not at the TIM4_Ch2. I can see the external signal being captured from TIM2_Ch1.
[Q] Can the COMP4 output be directed simultaneously to both the output pin and to the TIM4_Ch2 ?
If I modify the TIM4 initialization to send Ch1 to IC2 and Ch2 to IC1 I do see the signal generator capture move to the other capture register but the COMP4 is still not detected.
P.S. My comparator output also has multiple crossings from zero-crossing chatter.
static void MX_TIM4_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_IC_InitTypeDef sConfigIC = {0};
htim4.Instance = TIM4;
htim4.Init.Prescaler = 32;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 23500;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
/* sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; */
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim4, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_ConfigChannel(&htim4, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_Base_Start(&htim4);
}
COMP4 Init:
static void MX_COMP4_Init(void)
{
/*##-1- Configure the COMP4 peripheral ################################*/
hcomp4.Instance = COMP4;
hcomp4.Init.InvertingInput = COMP_INVERTINGINPUT_DAC1_CH1;
hcomp4.Init.NonInvertingInput = COMP_NONINVERTINGINPUT_IO1;
hcomp4.Init.Output = COMP_OUTPUT_TIM4IC2;
hcomp4.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp4.Init.BlankingSrce = COMP_BLANKINGSRCE_NONE;
hcomp4.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
hcomp4.Init.Hysteresis = COMP_HYSTERESIS_NONE;
hcomp4.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
if (HAL_COMP_Init(&hcomp4) != HAL_OK)
{
Error_Handler();
}
/*##-2- Start the comparator process ###############################*/
if (HAL_COMP_Start(&hcomp4) != HAL_OK)
{
Error_Handler();
}
}
Solved! Go to Solution.
2020-07-25 10:48 AM
> When I do this BOTH TIM4_Ch1 and TIM4_Ch2 start capturing in CCR1 and CCR2 the same value. It's almost like IC1 and IC2 are both receiving TIM4_Ch1 input.
And don't they? What's the CCMR1 setting?
Is this still the Nucleo board? Maybe you could strip down the code to an absolute minimal but compilable example, preferrably not depending on Cube or any other "library", and post.
JW
2020-07-19 10:47 AM
Maybe TIM2_CH4 is unavailable in the 'F303xE. The 'F3 OPAMP and COMP chapters are full of errors.
@Imen DAHMEN , can this please be clarified?
Thanks,
JW
PS. AN4651 is not helpful, it appears to be a verbatim copy of the interconnections chapter which is not helpful either, as the exclusions are not detailed in the COMP-to-TIM table at all.
2020-07-20 03:11 AM
Hello,
Regarding the RM0316, the contradiction notes have been removed on the latest RM Rev8.
Best Regards,
Imen
2020-07-20 07:39 AM
When I saw this I got my hopes up .... but I'm already using RM0316 Rev8. Still can't seem to get COMP4 to run TIM4_IC2. Yet can get external GPIO to run TIM4_IC1 or TIM4_IC2. Also, I do see COMP4 on output PB1.
Nice to know my RM0316 Rev 8 is latest copy though, thanks !
2020-07-20 11:38 AM
Huh, I failed to keep up with the RM update on this particular machine... :blushing: ... sorry for the noise, and thanks for the prompt clarification, Imen!
BTrem.1,
Read out and check/post the content of relevant COMP and TIM registers.
JW
@Imen DAHMEN
2020-07-20 12:58 PM
Hi ,
I'm attaching snapshots of COMP4 Reg and TIM4 Reg,
2020-07-20 03:14 PM
This all looks reasonable, the channels' crossing is a bit weird but that's probably the experiment you've described in your initial post.
Also, you have DMA enabled on both CC1 and CC2, why's that? Is there any difference if you don't enable that DMA?
Please double-check in GPIO registers that you don't have any TIM4_CH2 input enabled in the GPIO matrix (PA12, PB7, PD13 - please check GPIOD even if that pin is not present on your package).
As a test, can you please try to use another timer, e.g. TIM15_CH2?
JW
2020-07-20 04:50 PM
I'll need a day to get back to this. But for now, I did disable the DMA on both CC1 and CC2 with no change. The reason I am using these is I am capturing the TIM4 count for both Ch1 and Ch2 and using this to compute a phase error. I'm running a motor and will be using the phase error between Ch1 and Ch2 to modify the speed command to align the two edges together.
You're right the channels were crossed as a result of my previous test
I will double check the GPIO registers and try another timer as well.
Thanks,
Brian
2020-07-20 10:34 PM
I went through some older files and it appears that I've experimented with COMP4->TIM4_CH2 in the past. I would have noticed and wrote down if it wouldn't work. However, this was on a 'F303RB, which is a different silicon than the 'F303RE... Could that remark in the older RM be right, after all?
JW
2020-07-23 02:26 PM
Since I also planned to use TIM4_Ch1 for another input to the timer I tried a test where I connected the COMP4 Out (PB1) to TIM4_Ch1 input PB6. To my surprise both CCR1 and CCR2 are now simultaneously running and capturing the identical count value. I expected CCR1 to start capturing but didn't think this would affect CCR2, which wasn't responding to COMP4?