cancel
Showing results for 
Search instead for 
Did you mean: 

timer reset counter on falling edge

con3
Senior
Posted on April 28, 2018 at 01:37

Hey everyone,

I can not seem to get this right and any help would really be appreciated!

I'm using a stm32f722ze

I have a counter that toggles it's output on every 10th rising clock edge of an external clock that fed into its ETR pin. It also has a slave mode set as rising.

Here's the code for the timer:

static void MX_TIM8_Init(void)

{

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_SlaveConfigTypeDef sSlaveConfig;

TIM_MasterConfigTypeDef sMasterConfig;

TIM_OC_InitTypeDef sConfigOC;

TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;

htim8.Instance = TIM8;

htim8.Init.Prescaler = 0;

htim8.Init.CounterMode = TIM_COUNTERMODE_UP;

htim8.Init.Period = 9;

htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim8.Init.RepetitionCounter = 0;

htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim8) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_ETRMODE2;

sClockSourceConfig.ClockPolarity = TIM_CLOCKPOLARITY_NONINVERTED;

sClockSourceConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;

sClockSourceConfig.ClockFilter = 0;

if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_OC_Init(&htim8) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;

sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;

sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_FALLING;

sSlaveConfig.TriggerFilter = 0;

if (HAL_TIM_SlaveConfigSynchronization(&htim8, &sSlaveConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sConfigOC.OCMode = TIM_OCMODE_TOGGLE;

sConfigOC.Pulse = 9;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

if (HAL_TIM_OC_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;

sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;

sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;

sBreakDeadTimeConfig.DeadTime = 0;

sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;

sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;

sBreakDeadTimeConfig.BreakFilter = 0;

sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;

sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;

sBreakDeadTimeConfig.Break2Filter = 0;

sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;

if (HAL_TIMEx_ConfigBreakDeadTime(&htim8, &sBreakDeadTimeConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

HAL_TIM_MspPostInit(&htim8);

}

I want the falling edge of a reset signal to reset the counter, but it doesn't seem to happen.

This is what's currently happening, no matter what I do to sSlaveConfig.TriggerPolarity.( I can also see the values changing in the register)

So these are the signals in the image:

0690X00000604cwQAA.jpg

purple = clock

Yellow = reset

blue = output of timer

when the reset signal goes high, it seems to count the clock edge that goes high with it, then the following 9 rising edges after which it toggles the output.

Here's one that occurs after the reset;

0690X00000604RRQAY.jpg

Here it toggles after 10 rising edges .

Here's another one:

0690X00000604dVQAQ.jpg

How can I get the falling edge of the reset to trigger the reset, because I don't want the edge that rises with the reset signal to be counter?

Thanks in advance for any help

stm32f7

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 28, 2018 at 09:33

Read out and check/post the relevant TIM and GPIO registers content.

Observe in GPIO_IDR whether the relevant bit follows external changes of pin voltage (i.e. to check the pin is physically connected where you think it is).

JW

View solution in original post

2 REPLIES 2
Posted on April 28, 2018 at 09:33

Read out and check/post the relevant TIM and GPIO registers content.

Observe in GPIO_IDR whether the relevant bit follows external changes of pin voltage (i.e. to check the pin is physically connected where you think it is).

JW

Posted on April 29, 2018 at 06:12

Thank you WJ as soon as I get a chance I'll run through this and post the results here