1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

ASYNC software timers on separate hardware timers

Discussion in 'ARM' started by jasaleja, Jun 28, 2016.

  1. jasaleja

    jasaleja New Member

    Joined:
    Jun 28, 2016
    Messages:
    2
    Likes:
    0
    Hello everyone,

    I wrote a little code for my MSP432 to use two software timers on two separate hardware timers.

    The first hardware timer runs on SMCLK 3Mhz/64 and counts to 46875 before the interrupt. That is 1 second. And on that timer runs a software timer that counts 2 seconds, and then it triggers a red LED.

    The second hardware timer runs on SMCLK 3Mhz and counts to 3000 before the interrupt. That is 1 m second. And on that timer runs a software timer that counts 500 m seconds, and then it triggers a blue LED.

    So after i run the program the blue and red LED should both turn off after 4 seconds. But after a few minutes the 2 LEDS get async and i dont know why.

    Does someone have an explanation?

    I think it's because no 2 hardware timers can be in sync.
     

    Attached Files:

    • main.c
      File size:
      4.7 KB
      Views:
      145
  2. ronsimpson

    ronsimpson Well-Known Member Most Helpful Member

    Joined:
    Apr 17, 2007
    Messages:
    7,305
    Likes:
    969
    Location:
    Loveland, CO USA
    ONLINE
    Both hardware timers are running from the same 3mhz clock. They should stay lock together.

    I can not see your code here. (my computer)
    I have seen code where a divide by 3000 is actually 3001 or 2999 (one count off) because I did not understand numbers. LOL
    After more time do the two LEDs get back together? I am trying to determine if they are off by 1/3000 or 1/46875.
     
    • Like Like x 1
  3. jasaleja

    jasaleja New Member

    Joined:
    Jun 28, 2016
    Messages:
    2
    Likes:
    0
    Yup I just did a -1 on the hardware timer periods and now i t works like a charm. Thanks
     

Share This Page