2024-11-17 06:02 AM - edited 2024-11-19 02:37 AM
I haven't been able to wait 500ms without affecting the timers for 7 days.
In this block, doesn't PB14 become "0" after 500ms?
Even if I use comment lines, it doesn't work.
Note: volatile uint32_t Counter = 0;
The "Counter" variable is incremented every 1ms with Timer16.
** STM32F030C6T6 I'm using.
** Own PCB board..
*** Note: Card of a working system.. There is no card design error.
if(htim->Instance==TIM16)
{
Counter++;
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==0)
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2)==0)
{
if(PA10_On==0)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,GPIO_PIN_SET);
Counter=0;
PA10_On=1;
// Tick_PA10_On= HAL_GetTick();
// PA10_On=1;
}
else
{
if(Counter>500) // if((HAL_GetTick()-Tick_PA10_On)>=500)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,GPIO_PIN_RESET);
Counter=501;
}
}
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_SET);
}
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_RESET);
}
}
Solved! Go to Solution.
2024-11-19 03:48 AM
@XooM wrote:timer16 and SerialWire what do you want me to do
Ahh boy select as on my image Chekbox on serial wire when you used debuger this is good point and select TIM16 as your application timebase , MX then for you after generate code changes delay control from systick to TIM16 and setup 1ms. No more is required. Test toggle with this
2024-11-17 08:04 AM
It would rely on PC13 and PA2 being low before it gets to the timeout. And presumably you want it to turn off either way
Do all your INPUTs and OUTPUTs work otherwise? And it's just the sequencing logic that's broken?
2024-11-17 08:29 AM
Is your
PA10_On
volatile? When not and optimize level is more as 0 your code never will work. Optimizer remove line
PA10_On=1;
2024-11-17 08:45 AM - edited 2024-11-17 08:47 AM
PA10_On=1;
If I remove this line, PB14 will always remain in the SET position.
As long as PA2+PC13 continues to come, PB14 will be SET.
2024-11-17 08:51 AM
You dont ask this ? PB14 not go to 0 say is always 1.
And i recommend add volatile not remove
volatile int PA10_On = 0;
, but i mean we next 7 days try show you mistakes. Better is try help you create working code.
What you mean?
2024-11-17 10:21 AM
Try this code changes: in your main.c from rar
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_Base_Start_IT(&htim3);
// HAL_TIM_Base_Start_IT(&htim14);
// HAL_TIM_Base_Start_IT(&htim16);
// HAL_TIM_Base_Start_IT(&htim17);
/* Infinite loop */
/* USER CODE BEGIN WHILE */
unint32_t out_Start[8]; //delay storage for 8 outs
while (1)
{
//first here from your code Q3 output handler
_Bool outx = 0;
outx = ( HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==0 && HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2)==0 );
outx |= (Q3_GPIO_Port->ODR&Q3_Pin)!=0 && (HAL_GetTick()-out_Start[0])<500;
if(((Q3_GPIO_Port->ODR&Q3_Pin)==0 && outx) || ((Q3_GPIO_Port->ODR&Q3_Pin)!=0 && !outx) ) {
HAL_GPIO_WritePin(Q3_GPIO_Port, Q3_Pin, outx);
if(outx) out_Start[0] = HAL_GetTick();
}
//next for example Q1 try you or ask
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
2024-11-17 10:07 PM
I couldn't understand the code. I'm a bit of a beginner.
so I can't try it.
2024-11-18 01:49 AM
if(htim->Instance==TIM16)
{
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)==0)
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2)==0)
{
if(PA10_On==0)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14,GPIO_PIN_SET);
Tick_PA10_On = HAL_GetTick(); // Başlangıç zamanını kaydet
PA10_On = 1; // PA10 aktif duruma geçer
}
else
{
if ((HAL_GetTick() - Tick_PA10_On) >= 500)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
//PA10_On = 0; // PA10 pasif duruma geçer
}
}
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_SET);
}
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_RESET);
}
where is my mistake here?
Can you fix my mistake in my code?
I want to RESET the PA10 pin after 500ms.
2024-11-18 03:01 AM
Ctrl C Ctrl V and comment out timers. When it works i explain it for you.
2024-11-18 03:02 AM
@XooM wrote:I couldn't understand the code. I'm a bit of a beginner.
so I can't try it.
Ctrl C Ctrl V and comment out timers. When it works i explain it for you.