Shop OBEX P1 Docs P2 Docs Learn Events
programming question / system clock — Parallax Forums

programming question / system clock

agfaagfa Posts: 295
edited 2008-07-26 13:54 in Propeller 1

Is there a way to time events, such as toggle an output at a given interval, while doing other "processes", instead of using the waitcnt command which, if i understand, pauses program flow?

More specifically I am trying to create output pulses (1 to 2 ms on then 20 ms off) to drive a continuous rotation servo (the servo on the boe bot) while toggling an LED to indicate a wheel encoder input.

I've attached my programming efforts. I'm not sure if I've nested the repeats correctly.· I'm sure the way i used the system clock wouldn't work but was hoping someone could suggest another way.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-25 03:44
    This sort of thing should be done by starting up another cog using COGNEW and letting it do its own timing independently. If you have a process running in its own cog, it doesn't matter if it waits using a WAITCNT because that's what it's supposed to do.

    There already is an "object" that handles servos (up to 32 of them). Take a look at Servo32 in the Propeller Object Exchange. It will take care of the timing and pulse generation for you. There's another object called Servo-4 which is written entirely in Spin and has some additional features.

    There are other tools for independent functionality. In particular, each cog has two identical counters that can generate output pulses, do timing, do analog to digital and digital to analog conversions, all pretty much independently from other code running in the cog. Download the application note (AN001) on the counters from the Propeller download page.
  • agfaagfa Posts: 295
    edited 2008-07-25 04:01
    I will take a look at those resources.· Thanks

    I knew·that it could be done with another cog, and I plan on trying that. I was trying to get familiar with spin and I was trying to get creative and get as much out of a single cog as I could.

    Thanks again
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-07-25 05:38
    If you read cnt and add the number of clocks you desire to this register, you can then compare the register to cnt as you go round your normal loop.


    c := cnt + delay
    repeat
      ...do your stuff
      if cnt => c
         !out[noparse][[/noparse]led]
         c := cnt + delay
      ...more stuff if you like
    
    



    I am not good at spin so there may be syntax errors, but hope this helps.
  • agfaagfa Posts: 295
    edited 2008-07-25 11:38
    Thanks.· I'll try that tonight.
  • agfaagfa Posts: 295
    edited 2008-07-26 12:24
    would'nt using the system clock to time events in this way be prone to problems.· If an event is set to use 100 clock cycles (a delay of cnt + 100), and the actual value of cnt is 11111111_11111111_11111111_11111110 would the clock over-run make that impossible or would the interpreter compensate for that?



    Cluso99-after a closer look, looks like basically the same thing i'm trying to do.
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-07-26 13:54
    The arithmetic will work so basically the compiler will take care of it.

    Attached is a sampe program which outputs the the serial using the FullDuplexSerial. It output shows what happens with wraparound.
Sign In or Register to comment.