Shop OBEX P1 Docs P2 Docs Learn Events
RPM Tester — Parallax Forums

RPM Tester

RagtopRagtop Posts: 406
edited 2015-03-15 07:32 in Robotics
I have had a hall effect sensor for awhile that I got for a bike computer project that
I never started.

So I decided to make a RPM tester for my garage sale drill motor finds as an excuse
to play with the part.

I learned that the hall effect sensor latches it's output pin high when exposed to one pole of
a magnet and only latches low when exposed to opposite pole.

So I made a spinner with two magnets across from each other with opposite poles facing
sensor. Each half revolution one of the sensors flies by the sensor.

I count each time the state of the hall effect sensor's output pin changes and divide that
number in half for my revolution count.

Don't know how accurate this thing is, but it will at least give me comparable data on my
drill motor collection.

attachment.php?attachmentid=113500&d=1426428630
1024 x 734 - 633K

Comments

  • RagtopRagtop Posts: 406
    edited 2015-03-15 07:32
    Hard part of the project so far was that I had lost the driver for the lcd screen some time back in
    2010 and it never made the OBEX. Luckily it was still in the forums here: http://forums.parallax.com/showthread.php/117544-128x64-graphics-module?p=855774#post855774
    CON
             _clkmode        = xtal1 + pll16x
             _xinfreq        = 5_000_000
      clockfreq = ((_CLKMODE - XTAL1) >> 6) * _XINFREQ
      _1mS  = clockfreq /     1_000 'Divisor for  1 mS
    
      sdo     = 14     'lcd screen
      sck     = 15
    
      rows  = 64
      cols  = 128
      lines = 5
      thickness = 2
    
      screen        = $7000
      atr           = $7f00         
    VAR
      long counter
      long rotations,old,new,seconds,rpm,temprpm
    
      long  bufwr,col,row,tx,ty,xmar,ymar  'for lcd screen
      byte  x[lines]
      byte  y[lines]
      byte  xs[lines]
      byte  ys[lines]
    
    OBJ
         vp       : "Conduit"    
         timer   : "Timer32"
         gr      : "LcdGraphics"
    
    PUB Program
        StartViewport
        startLCD
        Main
    PUB StartViewport
        vp.config(string("start:dso"))  
        vp.config(string("var:counter,rotations,old,new,seconds,rpm"))   
        vp.share(@counter,@rpm)
    
    pub startLCD | i, j, k, kk, dx, dy, pp, pq, rr, numx, numchr,h,text
      cognew(@st7920,screen)
      gr.start
      gr.setup(16, 4, cols/2, rows/2, screen)
      xmar := 8
    
        byte[atr] := 0
        gr.clear
        gr.colorwidth(3,0)
        gr.textmode(2,2,6,0)
        ms(100)
        'byte[atr] |= $10    'inversed
        byte[atr] &= !$10  'normal
        tx := xmar
        ty := ymar
        str16(string("  RPM   "))   ' print in Parallax font    
    PUB main
       timer.init
       dira[0]~
       counter := 0
       rotations:=0
       rpm := 0
       old := 0
       timer.mark
       repeat
         timer.tick
         seconds := timer.PassedS
         new := ina[0]
         if old<>new
            rotations++
            old := new
         if timer.PassedS > 2
            rotations := rotations / 2 'hall effect sensor flips twice a rotation
            rpm := rotations * 30
            gr.clear                'screen is refreshed every 2 seconds
            tx := xmar
            ty := ymar
            str16(string("  RPM   "))   ' print in Parallax font
            printdecimal(rpm)
            timer.mark
            rotations := 0
         
         counter++
    pub dp
        tx -=5
        font16(".")
        tx -=6
    
    pub str16(str) | ch
      repeat while byte[str]
        ch := byte[str]
        if ch == "."
          dp
        else
          font16(ch)
        str++
    
    pub font16(code) | ptr,ix,iy,ch,sh
      ptr := ((code/2)<<7) + $8000
      sh := code&1
      repeat iy from 0 to 31        ' 32 lines
        ch := long[ptr]             ' read combo font for this line
        ptr +=4                     ' update pointer
        ch >>= sh                   ' offset for odd or even
        {endif}
        repeat ix from 0 to 15
          if ch&1
            gr.plot(ix+tx-64,32-iy+ty)
          ch >>= 2
        {end}
      {end}
      tx += 16
      if tx => 128-14
        tx := xmar
        ty -= 32
      {endif}
    pub ftext(bx,by,fontptr,textptr) | yp,xp,ch,bx2,ptr
      repeat
        ptr := ((byte[textptr++]-$30)*byte[fontptr+1])+fontptr+4
        repeat yp from 0 to byte[fontptr+1]-1
          ch := byte[ptr++] >< byte[fontptr]
          repeat xp from 0 to byte[fontptr]-1
            if ch&1
              gr.plot(bx+xp,by-yp)
            ch >>= 1
        bx += byte[fontptr]+1
      until not byte[textptr]
      
    PRI printDecimal(integer) | temp[3] ' Writes a decimal string.
    
    
      byte[@temp][10] := 0
      repeat result from 9 to 0 ' Convert number.
        byte[@temp][result] := ((||(integer // 10)) + "0")
        integer /= 10
    
      result := @temp ' Skip past leading zeros.
      repeat while((byte[result] == "0") and (byte[result + 1]))
        result += 1
    
      str16(result~) ' Print number.
    DAT
    
    ' 5x7 bitmap font
    font5x7         byte      5,7,0,0
    
                  byte      %01110  '0
                  byte      %10001
                  byte      %10011
                  byte      %10101
                  byte      %11001
                  byte      %10001
                  byte      %01110
                  byte      %00100  '1
                  byte      %01100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %01110
                  byte      %01110  '2
                  byte      %10001
                  byte      %00001
                  byte      %00010
                  byte      %00100
                  byte      %01000
                  byte      %11111
                  byte      %11111  '3
                  byte      %00010
                  byte      %00100
                  byte      %00010
                  byte      %00001
                  byte      %10001
                  byte      %01110
                  byte      %00100  '4
                  byte      %01100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %01110
    
    
    font8x10         byte      8,10,0,0
    
                  byte      %01110  '0
                  byte      %10001
                  byte      %10011
                  byte      %10101
                  byte      %11001
                  byte      %10001
                  byte      %01110
                  byte      %00100  '1
                  byte      %01100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %00100
                  byte      %01110
                  byte      %01110  '2
                  byte      %10001
                  byte      %00001
                  byte      %00010
                  byte      %00100
                  byte      %01000
                  byte      %11111
                  byte      %11111  '3
                  byte      %00010
                  byte      %00100
                  byte      %00010
                  byte      %00001
                  byte      %10001
                  byte      %01110
    '
    ' more to do
    '
    '
    
    vecdef                  word    $4000+$2000/3*0         'triangle
                            word    50
                            word    $8000+$2000/3*1+1
                            word    50
                            word    $8000+$2000/3*2-1
                            word    50
                            word    $8000+$2000/3*0
                            word    50
                            word    0
    
    vecdef2                 word    $4000+$2000/12*0        'star
                            word    50
                            word    $8000+$2000/12*1
                            word    20
                            word    $8000+$2000/12*2
                            word    50
                            word    $8000+$2000/12*3
                            word    20
                            word    $8000+$2000/12*4
                            word    50
                            word    $8000+$2000/12*5
                            word    20
                            word    $8000+$2000/12*6
                            word    50
                            word    $8000+$2000/12*7
                            word    20
                            word    $8000+$2000/12*8
                            word    50
                            word    $8000+$2000/12*9
                            word    20
                            word    $8000+$2000/12*10
                            word    50
                            word    $8000+$2000/12*11
                            word    20
                            word    $8000+$2000/12*0
                            word    50
                            word    0
    
    pixdef                  word                            'crosshair
                            byte    2,7,3,3
                            word    %%00333000,%%00000000
                            word    %%03030300,%%00000000
                            word    %%30030030,%%00000000
                            word    %%33333330,%%00000000
                            word    %%30030030,%%03000000
                            word    %%03030300,%%33300000
                            word    %%00333000,%%03000000
    
    pixdef2                 word                            'dog
                            byte    1,4,0,3
                            word    %%30000033
                            word    %%03333333
                            word    %%03333300
                            word    %%03000300
    
    pchip                   byte    "Propeller",0           'text
    
    
    
    
    
    
    
    
    PUB ms(Period)                                    '1 mS
      if period
        waitcnt(_1mS * Period + cnt)
    
    
    DAT
    '
    ' The LCD is placed into graphics mode and updated continuously from the buffer so that
    ' it behaves similar to any refreshed display such as a TV or VGA
    ' The buffer size is 1K mapped from start to end over to top left to right, top to bottom on the LCD
    ' The msb of a byte is left-most.
    
                            org
    
    ST7920                  andn    outa,_load
                            andn    outa,_sck
                            or      dira,_load
                            or      dira,_sck
                            or      dira,_sdo
                            mov     udly,cnt
                            add     udly,_udly
    
                            mov     r0,#$01
                            call    #txcmdl
                            mov     r0,#$06
                            call    #txcmd
                            mov     r0,#$0C
                            call    #txcmd
                            mov     r0,#$18
                            call    #txcmd
                            mov     r0,#$24
                            call    #txcmd
                            mov     r0,#$22
                            call    #txcmd
                            mov     r0,#$02
                            call    #txcmd
    
                            mov     r0,#$36
                            call    #txcmd
    
    '                        mov     atr,par
    '                        add     atr,lcdsz
    
    lcd_loop
                            mov     bufptr,par      ' set start address
                            mov     yptr,#0
    lcd_loopy               mov     r0,yptr           ' read line
                            and     r0,#$1F
                            or      r0,#$80         ' Y addr
                            call    #txcmd
                            mov     r0,#$80         ' X = 0 (start of line)
                            cmp     yptr,#32 wc     ' in bottom half of display?
            if_nc            or      r0,#$08          ' offset X to access bottom half with mirrored Y
                            call    #txcmd
                            mov     xcnt,#16          ' 16 bytes per line
    lcd_loopx               rdbyte  r0,bufptr
                            rev     r0,#24
                            call    #txdat
                            add     bufptr,#1
                            djnz    xcnt,#lcd_loopx
                            add     yptr,#1
                            cmp     yptr,#64 wz
            if_ne           jmp     #lcd_loopy   ' next line
    
                            rdbyte  r0,atrptr
                            or      r0,#2
                            wrbyte  r0,atrptr
    {
    wloop                   rdbyte  r0,atrptr
                            test    r0,#1    wz
            if_nz           jmp     #wloop
    }
                            jmp     #lcd_loop
    
    
    
    txdat                   mov     rssel,rsmask
                            rdbyte  r1,atrptr
                            test    r1,#$10 wz
           if_nz            xor     r0,#$ff
                            call    #transmit
                            mov     udly,cnt
                            add     udly,lcddly
                            waitcnt udly,#0
    txdat_ret               ret
    
    txcmd                   mov     rssel,#0
                            call    #transmit
                            mov     udly,cnt
                            add     udly,lcddly
                            waitcnt udly,#0
    txcmd_ret               ret
    
    txcmdl                  mov     rssel,#0
                            call    #transmit
                            mov     udly,cnt
                            add     udly,ms1
                            add     udly,ms1
                            waitcnt udly,#0
    txcmdl_ret              ret
    
    transmit                ' transmit r0 as 25 bits
                            mov     r1,r0
                            and     r1,umask        ' d7d6d5d4
                            rol     r1,#8
                            rol     r0,#4
                            and     r0,#$f0         ' d3..d0
                            or      r0,r1
                            or      r0,synch
                            or      r0,rssel
                            or      outa,_load
                            rol     r0,#8           ' prep data shift from bit23
                            mov     r2,#24
    :txloop                 rol     r0,#1  wc
                            muxc    outa,_sdo
                            nop
                            nop
                            or      outa,_sck
                            nop
                            nop
                            andn    outa,_sck
                            nop
                            nop
                            djnz    r2,#:txloop
                            andn    outa,_load
    transmit_ret            ret
    
    _load                   long 0  '|<scs
    _sdo                    long |<sdo
    _sck                    long |<sck
    msb                     long $80000000
    synch                   long %11111000_00000000_00000000
    _udly                   long 80000
    umask                   long %1011110000
    rsmask                  long %00000010_00000000_00000000
    ms1                     long 80000
    ms10                    long 800000
    lcddly                  long 80*(72-15)
    lcdsz                   long 1024
    atrptr                  long atr
    
    'atr                     res 1
    r0                      res  1
    r1                      res  1
    r2                      res  1
    r3                      res  1
    r4                      res  1
    r5                      res  1
    yptr                    res  1
    xcnt                    res  1
    bufptr                  res  1
    rssel                   res  1
    udly                    res  1
    
Sign In or Register to comment.