This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Count 1 minute in RTX51-Full

Hello,
I'm using the T89C51RD2 micro with RTX51-full RTOS.
I need to count number of passed minutes and I want to know what is the prefered way to do it.
According to the user manual and data sheet the built-in UART requires 32 clock cycles (from timer 2) for each bit (of the received byte). Because the code timed an 8 bits, the value that will be needed for init the time in auto-reload mode is calculated by dividing the CPU cycle count by 32*8=256.
According to this information with a frequency of 11.0592MHz and time slice of 25msec (os_set_slice(23040)) I can wait 5 seconds max (os_wait(K_IVL, 200, 0);).
Now I thought about several options:
Option 1 – Write "os_wait(K_IVL, 200, 0);" line 12 times (5sec*12=1minute).
Option 2 – Write "os_wait(K_IVL, 200, 0);" line in "for" loop that count to 12.

Which of them is better? Are there's any other way to do it?

Thanks a lot,
Roberto.

Parents
  • You could also create a task that counts seconds. The seconds counter could be used for a number of delay operations (2 sec, 5 sec, 60 sec, ...).

    If your timer tick is set for 25mSec...


    unsigned long sec_counter = 0;
    
    void second_counter_task (void) _task_ ???
    {
    while (1)
      {
      os_wait (K_IVL, 40, 0);  // 1 second interval
      sec_counter++;
      }
    }
    


    Then, you can read sec_counter in your program to determine what the second is.

    You could, obviously, create a real time clock this way, too.

    Jon

Reply
  • You could also create a task that counts seconds. The seconds counter could be used for a number of delay operations (2 sec, 5 sec, 60 sec, ...).

    If your timer tick is set for 25mSec...


    unsigned long sec_counter = 0;
    
    void second_counter_task (void) _task_ ???
    {
    while (1)
      {
      os_wait (K_IVL, 40, 0);  // 1 second interval
      sec_counter++;
      }
    }
    


    Then, you can read sec_counter in your program to determine what the second is.

    You could, obviously, create a real time clock this way, too.

    Jon

Children
No data