cancel
Showing results for 
Search instead for 
Did you mean: 

Switch relay synchronously in 0 passage (50Hz)

ATürk.11
Associate II

i am trying to switch a relay via the stm8s001 processor synchronously in the 0 pass. how could I realize that.

i have an imput signal of 50 Hz. I can also start the timer, but I don't know how to switch the relay on exactly in the 0 cycle.

(i watch the action on the oscilloscope).

The Code.:

main.c .:

(only the most important areas)

##################################################################

void main(void)

{

  

CONFIG_UNUSED_PINS_STM8S001;

//STARTUP_SWIM_DELAY_5S; 

GPIO_Config();

CLK_Config();

TIMER_Config();

EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOD, EXTI_SENSITIVITY_RISE_ONLY);

enableInterrupts();

while(1)

{

if (flagfortimer == 1 )

GPIO_WriteReverse(GPIOA, GPIO_PIN_3);

flagfortimer = 0;

}

}

static void TIMER_Config(void)

{

  TIM1_DeInit();

TIM1_TimeBaseInit(1, TIM1_COUNTERMODE_UP,1,0); how is the dimensioning here ???

TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);

  TIM1_Cmd(ENABLE);

}

#############################################################

interrupt_vector :

{0x82, EXTI_PORTD_IRQHandler}, /* irq6 */

.........

{0x82, TIM1_UPD_OVF_TRG_BRK_IRQHandler}, /* irq11 */

#############################################################

interrupt routine

##############################################################

INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6) // here is my input of 50 Hz on Pin D6

{

  

if(GPIO_ReadInputPin(GPIOD , GPIO_PIN_6))

{

timer1start = 1;

   }

}

INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)

{

 if (timer1start == 1)

 {  

TIM1_ClearITPendingBit(TIM1_IT_UPDATE);

flagfortimer = 1;

timer1start = 0;

 }

}

###############################################################

This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Cristian Gyorgy
Senior III

Here you need to know your setup. Do you use an external zero crossing detector, or a pin through a R-C directly? What's your signal? What's the relay's switch time?

You need to figure out these things first, some basic theory, than you'll see things get quite simple...

Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.