0
\$\begingroup\$

I am a new hand to STM32F1x and I am trying to do a project that really needs to use the RTC/TIM function.

What I am trying to do is to display a 20 second count-up timer on the LCD. Something that looks like:

TIMER: 12.34 s

So what I want to write in the program is:

var s =0
if "counted 1s " 
{    
  drawchar (3, 1, s)
  s++ 
}
if "counted 10s" 
{    
  drawchar(3, 0, x)
  x++ 
}

So the problem is what to write in order to get:

if (counted 1s); 

Thank you very much and sorry, that I don't really have much knowledge on it.

Let me explain more, base on my little knowledge. What I know is like, when I press a button, I can do sth/ interrupt.

while(1){

    if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==1){

        LCD_DrawString(0, 0, name, 8);

    }
}

Thats basically what I can do.

So, instead of pressing a button to draw sth, I would like to make it draw when the timer/RTC rising edge.

\$\endgroup\$
  • \$\begingroup\$ What is your development environment? (library, IDE) \$\endgroup\$ – Bence Kaulics Nov 11 '16 at 9:23
  • 1
    \$\begingroup\$ What did you try so far? \$\endgroup\$ – Batuu Nov 11 '16 at 9:29
  • 1
    \$\begingroup\$ It is not clear, you want to count with 1 second resolution or 0.01 second resolution. \$\endgroup\$ – Bence Kaulics Nov 11 '16 at 9:33
  • \$\begingroup\$ I use IAR embedded system workbench So far I dun know anything any RTC but i did use the TIM3 to generate a 100Hz impulse train. \$\endgroup\$ – Tse Kelvin Nov 11 '16 at 14:05
  • 1
    \$\begingroup\$ Search for Timer examples using SPL. \$\endgroup\$ – Bence Kaulics Nov 11 '16 at 14:29
1
\$\begingroup\$

You should use one of the hardware timers for this, not a RTC. The RTC is useful for keeping track of the actual time-of-day and the calendar day (absolute time). But you are just trying to count a relative time period of 20 seconds.

Configure and enable the hardware timer so that it provides an interrupt every 10 milliseconds. (Read the datasheet or find examples of how to do this.) In the timer's ISR, increment a counter so that the counter value represents the number of 10 ms periods that have occurred since the counter was reset. Draw the four digits from the counter value on the display and draw a decimal point between the middle digits. There's many different ways to do this. For example you could use sprintf to convert the counter value into a string and then call LCD_DrawString. Or you could repeatedly divide the counter value by 10 to extract a single digit and then call drawchar for each digit.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.