cancel
Showing results for 
Search instead for 
Did you mean: 

Generating the pulses for thyristors implemented in 3 phase ac dc control

LFerr.7
Associate II

Hello to everyone! I am an electronic engineer but iam new on stm32.

At the moment iam talking only for one phase. i have a square wave of 50Hz => 20ms of period with dutycycle 50% that is implemented in INPUT CAPTURE CH2(PE11) and i have choose the OUTPUT COMPARE CH1(PE9). Firstable i want to use only a positive edges triggered to generate my first pulse and not the zero crossing. this is a code that i implemented watching tutorials on internet but it is zero crossing .

#define SCR_PULSE_WIDTH 500 // Duration of SCR trigger pulse in µs

static void MX_TIM1_Init(void)

{

{

  __HAL_RCC_TIM1_CLK_ENABLE(); // Enable Timer 1 clock

  TIM1->CR1  = 0x0089;    // Auto-reload, One-Pulse-Mode

  TIM1->CR2  = 0x0000;    // Idle-state configuration

  TIM1->SMCR = 0x0066;    // Trigger-Mode, Timer input 2

  TIM1->DIER = 0x0000;    // Disable interrupts

  TIM1->SR  = 0x0000;    // Clear status register

  TIM1->EGR  = 0x0000;    // Clear event generation register

  TIM1->CCMR1 = 0x0178;    // OC1: PWM2-Mode, Preload, IC2: IC2 on TI2

  TIM1->CCMR2 = 0x0000;    // OC3/OC4, IC3/IC4 off

  TIM1->CCER = 0x00A1;    // OC1: On, AH; IC2: On, Both edges

  TIM1->CNT  = 0;       // Clear timer 1 counter

  TIM1->PSC  = 168-1;     // Set prescaler to 168

  TIM1->ARR  = 0x0000;    // Initialize Auto-reload register

  TIM1->RCR  = 0x0000;    // Clear repetition counter

  TIM1->CCR1 = 0x0000;    // Initialize Capture/Compare register 1

  TIM1->CCR2 = 0x0000;    // Clear Capture/Compare register 2

  TIM1->CCR3 = 0x0000;    // Clear Capture/Compare register 3

  TIM1->CCR4 = 0x0000;    // Clear Capture/Compare register 4

  TIM1->BDTR = 0x8000;    // Main output enable

  TIM1->DCR  = 0x0000;    // Clear DMA configuration (DMA not needed)

  // TIM1->DMAR = ......;   // NOT WRITE TO THIS REGISTER

  TIM1->CR1 |= 0x0001;    // Timer 1 Enable

}

int main(void)

{

  float x=2.3;

  HAL_Init();          // Initialize STM32 HAL

  SystemClock_Config();     // Configure core clock

  MX_TIM1_Init();        // Initialize Timer 1 (OC1 / IC2)

  MX_GPIO_Init();        // Initialize GPIOs

  MX_ADC1_Init();

while ( 1 )

{

int alpha,y=10;

    HAL_ADC_Start(&hadc1);

       HAL_ADC_PollForConversion(&hadc1,1);

 alpha=HAL_ADC_GetValue(&hadc1);

 alpha=(alpha+y);

 TIM1->CCR1 = (alpha*x);

 TIM1->ARR = ((alpha*x) + SCR_PULSE_WIDTH );

 HAL_Delay(1);

  }

in this case the result consists in the pulse at 10ms of period ,but i want the pulse only on positive edge triggered so i want the pulse only in 20 ms.Can anybody help me in this? what can i change?

0 REPLIES 0