Shop OBEX P1 Docs P2 Docs Learn Events
pov timing question — Parallax Forums

pov timing question

mikeamikea Posts: 283
edited 2013-08-24 07:31 in Propeller 1
I'm attempting to build a pov clock. Right now i'm only trying to make a simple smiley face with one spinning led. I was hoping someone could take a look at my code to find a timing problem. The led will do random things for around a minute or so then work when I only try a smile and one eye, when I add the second eye it all goes random. Any suggestions would be appreciated. Thanks! (there are percent signs where they need to be in the code, they wont display correctly on this forum post)
CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000
var
long start_time
long end_time
long cycle
long piece
                                           'hall effect is high, magnet makes it low
pub circle 
dira[0..4]~~    
start_time:=end_time:=cycle:=piece:=0   
   repeat 
     waitpeq(%100000000000, |< 11, 0)  'wait for high hall sensor
     waitpeq(%000000000000, |< 11, 0)  'wait for low  hall sensor
     end_time:=cnt                       '
     cycle:=end_time-start_time          'figure time for one revolution
     start_time:=cnt                     'piece is one degree resolution of 360 degrees
     piece:=cycle/360
     
              
     outa:= %100                       'turn on red led
     waitcnt(piece*80+cnt)             'leave on for 80 pieces of circle
     outa:=%0000                       'turn off led
    
     waitcnt(piece*80+cnt)             'go around circle 80 pieces
     outa:= %100                       'turn on led
     waitcnt(piece*20+cnt)             'leave on 20 pieces
     outa:=%0000                       'turn off
     waitcnt(piece*40+cnt)             'go around circle 40 pieces
     outa:=%100                        'turn on led
     waitcnt(piece*20+cnt)             'leave on 20 pieces
     outa:=%0000                       'turn off until beginning of loop 
      

Comments

  • cavelambcavelamb Posts: 720
    edited 2013-07-07 12:48
    Hi Mikea
    By "Random" do you mean blinky spots, or solid arcs/circles?

    One thing? I see where you pick up end_time := cnt.
    But start_time is assigned zero?
    What's the cnt when that happens? And happens again the next time?


    I was doing a POV with a QuickStart on the ceiling fan but never found an easy way to sync it.
    (details of you Hall circuit would be sweet!)
    So I thought I'd use IR Remote control to "adjust" timing.
    It has possibilities, but a hard index would be the way to go.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-07 12:51
    I don't understand what you're doing with start_time and end_time. Normally you'd have something like this pseudo-code:
    ' wait for Hall-effect sensor pulse
    start_time := cnt   ' mark time for 1st cycle
    repeat
       ' wait for Hall-effect sensor pulse
       end_time := cnt   ' mark time
       cycle := end_time - start_time   ' compute length of cycle
       start_time := end_time   ' set up for next cycle
       piece := cycle / 360   ' time per degree of cycle
       ' now do your stuff
    
  • mikeamikea Posts: 283
    edited 2013-07-07 13:27
    Yes, streaks and circles that should be stationary. It seems like it should sink up right away, but it takes the better part of a minute. I tried commenting out the initializing the variables to zero and it doesn't seem to have an effect. I haven't thought of a way to keep track of cnt yet. I'm using a proto board usb on top of a small computer fan, with a copper clad board in between and wires for brushes to get power to the protoboard. There is a 3/8 magnet stationary on the fan body, and a hall sensor(17cat948...orB?) soldered to the end of the protoboard. I used the recommended circuit on the datasheet for the hall sensor, which included a small cap, and a resistor. Also there is a larger cap on the protoboard side of the brushes/commutator.
  • mikeamikea Posts: 283
    edited 2013-07-07 13:50
    Thanks Mike, that straightened it out. I also added a delay to get the usb cord unplugged and up to speed, otherwise the display seems to dance around for a while before it looks like it's supposed to. It does the same dancing when I stop the rotation of the fan and start it again without re-booting the program, which I don't understand. It seems like it should adjust right away after the first repeat of the code to get the timing back once it's spinning again.
  • cavelambcavelamb Posts: 720
    edited 2013-07-07 16:22
    Probably because the fan speed is not constant at that time.
    If you get ANY recognizable pattern the speed is pretty close.
    But might "roll" slowly.
  • mikeamikea Posts: 283
    edited 2013-08-24 06:29
    Do I need to use a float object with this code for division? I'm getting inconsistent results.
    CON
            _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
            _xinfreq = 5_000_000
          'spinning p.o.v. project
          'p0 through p 29 are r.g.b leds
          'p 30 is hall effect sensor
          'p 31 is i.r receiver
    var   
    long start_time
    long end_time
    long cycle
    long piece
    pub  grid
    dira[0..29]~~
         waitpeq(%0000000000000000000000000000000,|<30,0)  'hall sensor for lap time
         start_time:=cnt
      repeat 
         
        waitpeq(%0000000000000000000000000000000,|<30,0)
         
        end_time:=cnt                                      'calculate lap time
        cycle:=end_time-start_time                         '
        start_time:=end_time                               '
        piece:=cycle/60                                    'divide lap by 60 
        outa[0..29]~~                                      'lights on for one third of a lap 
        waitcnt(piece*20)
        outa~
    
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2013-08-24 07:31
    Nope. The counter numbers are still pretty large, so you should be able to divide by 360 and get a pretty good integer number without worrying about floats. If 360 is too tight (which it shouldn't be) - well, who said that a circle has to be divided into 360 - you can divide it by 256 or 100 or something.
Sign In or Register to comment.