Shop OBEX P1 Docs P2 Docs Learn Events
Timer problems — Parallax Forums

Timer problems

Kram11Kram11 Posts: 8
edited 2007-11-24 16:34 in Propeller 1
Can anyone help?

· I am trying to understand how I can use timers within a program without pausing the code as waitcnt seems to. I have therefore tried to sample the cnt value and compare it to my timed valve required. If the current cnt value plus my timed valve is greater I set a bit and display on the screen.
I seem to be getting a -ve value from the cnt, is this correct?

Is there an easier way of using timers


OBJ
········ tv··· :······ "TV_Text"·
VAR
·long Delay_Start
·byte Delay_Done
·byte Time_Set
·byte Timer1_Complete
·long Start_Point1

CON

··· _CLKMODE = XTAL1 + PLL16X
··· _XINFREQ = 5_000_000
·

·
PUB Main

··· tv.start(12)
repeat
···· tv.Str(string("Delay Time: ",13))
····

····· if ina[noparse][[/noparse]4]· ==1
······· Time_Set:=0·············

·······
· Check_Time
·········· tv.dec(Delay_Start)
··········· tv.out(13)
···········
···········
···· Timer1_On(9_000,1)
·········· tv.dec(Timer1_Complete)
·········· tv.out(13)
·········· tv.dec(Start_Point1)
····

·· tv.out($01)· ' back to home

····
PUB Check_Time
····· Delay_Start := cnt
·····
PUB Timer1_On (Delay1,Start1)
······ if Time_Set==0
········· Start_Point1:=cnt ' check the start time
··· Time_Set:=1· ' the timer is now running
··· if Delay1>(Start_Point1+cnt)
····· Timer1_Complete:=1
··· else
····· Timer1_Complete:=0
······
······

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-24 15:33
    If you're not careful, you can run into problems comparing time values since sometimes the sign bit is set. Better to use time differences like:
    PUB startInterval
       Delay_Start := cnt
    
    PUB checkInterval(delay)
       return (cnt - Delay_Start) > delay
    
    
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-24 15:41
    There are many ways to do these things. You generally use the hardware timer/counters, but you can of yourse also use your technique for slow und unprecise results.

    Two remnarks:
    (1) Understand that CNT is a wrap-around counter, counting up to POSX and then down from NEGX; a whole cycle takes 40 seconds @ 80 MHz...
    Checking
        if Delay1>(Start_Point1+cnt)
    

    as you did is generally a good idea, but it must rather read:
     if Delay1>(CNT -Start_Point1)
    



    You cannot detect delays longer than 25 seconds with this simple technique.

    Why is this unprecise? Because you use a lot of SPIN operations inbetwee, so you your accuracy will be araumd some hundred µs.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2007-11-24 16:07
    could this be done with one of those old light guns that sense where the gun is aimed by where the vga cathode gun is aimed at a particular time?· Could the vga method somehow feedback to another cog to determine it?
  • Kram11Kram11 Posts: 8
    edited 2007-11-24 16:19
    thanks for the help.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2007-11-24 16:34
    sorry. posted to wrong thread
Sign In or Register to comment.