Announcement

Collapse
No announcement yet.

ME Lab Trainer Timer1 Interrupt assistance needed

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hi, Larry

    just forget about ON INTERRUPT : it won't do anything good with " real time " systems ...

    I saw you want to deal with 10 servo signals ...

    10 x 2.0 ms = 20 ms ... what is very close to a frame duration, so ... not much free time to do something - even blink some leds - !!!

    the way to go is to have an " arduino style " ( lol ) clock , better say a free running timer, and flag rising and falling signal edges.

    that way, you can use dead time between edges ... just follow richard's advice !

    Alain

    Alain

    Comment


    • #17
      Another possible approach is to generate a 50Hz interrupt. When it fires you set all the servo outputs high and then soft- (or hard)ware time the length of each output signal, while staying IN the ISR.

      Since the longest time is 2ms you won't ever stay in the ISR longer than 2ms every 20ms. The resolution of the output signals obviously depends on how tight you can Control the timing within the ISR and how many outputs you have.

      /Henrik.

      Comment


      • #18
        Yet another way would be to set the outputs, change the timer for 1ms interrupt (or slightly less due to the latency (since that's the shortest pulse duration)) and get out of the ISR.

        Then when the 1ms interrupt fires you spend (up to) a millisecond in the ISR timing each of the pulses. That should amount to slightly more than 5% of the available CPU cycles (1ms every 20ms), no matter how many outputs you have. But again, the resolution will suffer as you go up in the number of outputs.

        /Henrik.

        Comment


        • #19
          I think my code in post #7 is a pretty good start,it can service more servos or less as long as they can handle the resulting frame time . I only have two servo types to test with but they both seem happy to be refreshed anywhere between 15 and 30mS. the code even gives a subtle hint on how the " dead time " between pulses can be used to update pulse-widths in a glitch free manner.
          To service 10 servos say on outputs b.6:7 through to c.0:7 (note consecutive ) modify the isrs as follows, refresh would now be 25mS

          Code:
          
          serv:
          tmr0=tmr0+100
          latb.6[servo]=1
          Timer1 = -servo_t[servo]
          pir1.0=0
          t1con=$31
          @ int_return
          
          
          
          st:
          t1con=0
          latb.6[servo]=0
          servo= servo+1
          if servo ==10 then   servo=0
          if buffer_dirty then   
              servo_t[0]=buffer
             buffer_dirty=0
             endif
          '    lata.4=!lata.4
          'endif
          @ int_return
          ps the 2.5 mS interval could be adjusted also

          Comment

          Working...
          X