cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER doesnt work when i link the lcd

LFerr.7
Associate II
#define TRIAC_PULSE_WIDTH  500  // Duration of TRIAC trigger pulse in µs
 
lcd_init();
 
  lcd_send_cmd (0x80|0x00);
  lcd_send_string("HELLO WORLD");
 
  lcd_send_cmd (0x80|0x40);
  lcd_send_string("LCD 20x4 DEMO");
 
  lcd_send_cmd (0x80|0x1C);
  lcd_send_string("BY");
 
  lcd_send_cmd (0x80|0x54);
    lcd_send_string("powertechnologies");
 
void timer1_init( void )
{
   __HAL_RCC_TIM1_CLK_ENABLE(); // Enable Timer 1 clock
   TIM1->CR1   = 0x0088;        // 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 = ......;      
   TIM1->CR1  |= 0x0001;        // Timer 1 Enable
}
 
void gpio_init( void )
{
   __HAL_RCC_GPIOE_CLK_ENABLE();    // Enable GPIOE clock
   GPIOE->MODER   = 0x00880000;     // Enable PE9/PE11 alternate function mode
   GPIOE->AFR[1]  = 0x00001010;     // Select PE9/PE11 alternate function AF1
   GPIOE->AFR[0]  = 0x00000000;     // Clear AFRL
   GPIOE->OTYPER  = 0x00000000;     // Set all outputs to push-pull mode (default)
   GPIOE->OSPEEDR = 0x00000000;     // Set all outputs to low-speed (default)
   GPIOE->PUPDR   = 0x00000000;     // Disable all pull-ups and pull-downs
}
 
 
void set_alpha( int alpha )
{
   TIM1->CCR1 = alpha;
   TIM1->ARR = alpha + TRIAC_PULSE_WIDTH;     
}

I use STM32F429ZI and stmcube ide to write the code. I have activate the timer 1 (ch1 at output compare PE9 and ch2 input capture PE11 ).

On PE11 i put a quare wave of 50 hz and in the output(PE9 i have the pulses every rising and falling edges.)The lcd works very fine (i2c but i have tried also spi and it works.) but when i connect the lcd to send strings(for example when i write lcd init(), the timer output(PE9 ) go up at 3.3v and the pulse misses.

Can you help me please? if you want more information , i can be more clear.

8 REPLIES 8

> for example when i write lcd init(), the timer output(PE9 ) go up at 3.3v and the pulse misses

Read out and check/compare GPIOE and timer registers content between working and non-working cases.

JW

thanks for your answer, i have tried a lot , reading manual , changing things on code but without result.

That's why I say, read out the content of registers and check/compare/post.

JW

@LFerr.7​  "The lcd works very fine (i2c but i have tried also spi and it works.) but when i connect the lcd to send strings(for example when i write lcd init(), the timer output(PE9 ) go up at 3.3v and the pulse misses."

Not quite clear what you're saying here - is this purely a software change, or are you also changing hardware?

As @Community member​ says, whenever you have one working and one non-working case, the thing to do is to compare them side-by-side - step through, and see where things are different.

Or, perhaps, go back to the working case and just make small, incremental changes - so you don't have much to debug at the point that it stops working...

LFerr.7
Associate II

It is a software change. I see on the oscilloscope that in the output of timer i have Constant voltage 3,3V instead of the pulses

Blind writing all the pin configuration,etc, looks like it will cause headaches and waste time.

Think harder, and tread more carefully..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thank you

so compare & contrast your timer setup in the 2 cases