Wanted: Propeller Tachometer Code
I have a mini-mill and mini-lathe and I want to build Tachometer's for both. I have just embarked on a project to convert the Mill to CNC.
I have several Prop's around (and boards, and..) so I figured why not build rather than buy!! I would rather not spend the time starting from scratch - CNC is consuming LOTS of brainpower these days!!
Has anyone seen or have one built on the Propeller? If so, would you mind sharing code?
Thanks,
Paul
I have several Prop's around (and boards, and..) so I figured why not build rather than buy!! I would rather not spend the time starting from scratch - CNC is consuming LOTS of brainpower these days!!
Has anyone seen or have one built on the Propeller? If so, would you mind sharing code?
Thanks,
Paul

Comments
Lv
It is in PASM but heavily documented so you should be able to use it even if you don't know much PASM.
Copy it and run it. It is complete.
The attached code has three methods
The first displays what id going on on the PST
The second generates a signal you can seed (programmable) for a frequency to use as a source
if you don't have a signal to look at. Otherwise you can use your signal
The third counts how may waves go by in three (programmable) 1/5 (programmable) second time frames and averages them
You can construct a tachometer from that.
This is from my book on learning PASM for beginners
I invite comments on the code so I can make improvements.
The book is about done.
{{------------------------------------------------------------------------------- PASM_Tachometer.SPIN Function of program Tachometer reads the speed of an encoded motor every 5th of a second 3 readings are taken and averaged. A method is provided to allow a signal to be generated on pin 8 if you do not have any other signal to measure. Route this signal to pin 0 through a 220 ohm resistor to use it. Otherwise it leave disconnected. Program PASM_Tachometer.SPIN Book PASM for beginners, Propeller 102 Section 3 Inputs Programmer Harprit Sandhu Date Jan 10 2013 Revisions: Report errors to harprit.sandhu@gmail.com --------------------------------------------------------------------------------}} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 vars=16 OBJ fds : "FullDuplexSerial" 'for communications with PST VAR long stack2[25] 'space for pulser cog long clk_Div,value[vars],delay byte sub_scr PUB Main|x 'x is a local variable here fds.start(31,30,0,115200) 'start console at 115200 for debug output Cognew(@Read_Sig, @value) Cognew(Signal, @stack2) 'set lines to outputs fds.tx(16) 'home to 0,0 repeat fds.tx(1) fds.str(string("HUB memory display")) 'print to display fds.tx($d) 'new lines fds.tx($d) ' repeat sub_scr from 0 to vars-1 ' if sub_scr<10 'adds space for single digits fds.str(string(" ")) ' fds.dec(sub_scr) 'subscript printed fds.str(string(" ")) 'space over fds.dec(||value[sub_scr]) 'print value fds.str(string(" ")) 'print spaces to erase old data overflow fds.tx($d) 'new line waitcnt(clkfreq/60+cnt) 'flicker free wait x:=x+1 'increment counter. This routine clears up screen if x>10 'decision point by erasing extraneous lines of bottom fds.tx(16) 'clear screen of PST display every 10 loops x:=0 'reset counter '{{ 'If you do not have a signal to measure, you can use this 'routine as a source of a signal. Vary the delay as needed. 'You cannot use too small large a nummber. Do you know why? 'Comment it out if you don't need it. PRI Signal 'Signal generator dira[8]~~ 'pin 8 is output delay:=80_000 'count for 1 microsec repeat !outa[8] 'toggle signal waitcnt(clkfreq/delay+cnt) 'wait count '}} DAT Org 0 ' Read_Sig mov nmbr, #0 'initialize nmbr mov mem0, par 'read par into mem0 mov mem1, mem0 'make mem1=to mem0 add mem1, #4 'next mem location call #wait_Hi 'wait for signal to become high do_again call #wait_Lo 'wait for signal to become low call #wait_Hi 'wait for signal to become high mov temp, cnt 'read counter to temp wrlong temp, mem0 'store in first location add nmbr, #1 'increment number add mem0, #4 'increment mem mov varbl, nmbr 'make copy of nmbr sub varbl, #5 wz 'subtract. Has it reached 5 if_nz jmp #do_again 'if not do again 'at this point all five counter valued have been stored mov nmbr, #0 'reset counter mov mem0, par 'reset mem0 mov mem1, mem0 ' add mem1, #4 'reset mem1 mov stor, mem0 ' add stor, #24 'Stor is location 6 'pointers are ready to read the four differences in counts do_again2 rdlong temp, mem0 'read temp from a location rdlong temp1, mem1 'write it to next location sub temp1, temp 'subtract the two wrlong temp1, stor 'store the value add mem0, #4 'increment to next location add mem1, #4 'increment to next location add stor, #4 'increment to next location add nmbr, #1 'increment counter mov varbl, nmbr 'make copy of counter sub varbl, #4 wz 'subtract final number if_nz jmp #do_again2 'if not final yet do again 'the four differences are now in locations 6..9 in hub mov nmbr, #0 'reset couonter mov mem0, par 'reread mem0 add mem0, #24 'mem0 is now location 6 mov stor, mem0 ' add stor, #20 'stor is location 6+5 wrlong zero, temp3 'clear temp3 'pointers are ready to read the four additions of speeds do_again3 rdlong temp, mem0 'read location from memory rdlong temp2, temp3 'read stored current total add mem0, #4 'increment mem location add nmbr, #1 'increment counter add temp, temp2 'add to total stored wrlong temp, temp3 'write new total mov varbl, nmbr 'make copy of counter sub varbl, #4 wz 'subtract final number if_nz jmp #do_again3 'if not final do again wrlong temp, stor 'store final total shr temp, #2 'divide by 4 add stor, #8 'add two mem locations to stor=13 wrlong temp, stor 'store average at loc 13 jmp #Read_sig 'go back to beginning 'park jmp #park 'go into loop 'subroutines wait_Hi mov temp4, ina andn temp4, mask8 wz if_nz jmp #wait_Hi wait_Hi_ret ret Wait_lo mov temp4, ina andn temp4, mask8 wz if_z jmp #wait_Lo Wait_lo_ret ret 'constants and variables zero long 0 dira_set long %00000000_00000000_00000001_00000000 mask8 long %11111111_11111111_11111110_11111111 mem0 res 1 mem1 res 1 temp res 1 temp1 res 1 temp2 res 1 temp3 res 1 temp4 res 1 stor res 1 Nmbr res 1 varbl res 1Harprit.