BS2 tachometer/digital encoder project
dmaintenance
Posts: 6
Hi,
It’s been a while since I’ve done more than basic switching with the BS2 I have.
Hoping you can help and point me in the right direction with a project I need to accomplish.
I need a simple system to trigger an output being a buzzer and light indicator when a product is longer than the specified length when passing under a part of the machine. i.e. instead of 1 piece of paper has been fed past a fixed point on the conveyor belt, 2 pieces have fed incorrectly overlapping and being longer than expected.
I need to be able to measure the length of the product so I’ve ordered a digital encoder (tachometer) and photoelectric cell (photocell).
http://www.ebay.co.uk/itm/222122320381?_trksid=p2057872.m2749.l2649&ssPageName=STRK:MEBIDX:IT
http://www.ebay.co.uk/itm/331640970982?_trksid=p2057872.m2749.l2649&ssPageName=STRK:MEBIDX:IT
I need to be able to input the maximum length and change this length as and when required via keypad and LED or LCD display maybe or something simpler and not via reprogramming the code each time.
I have already built a system using 2 sensors and working on a physical trigger of both for the output error, but I need to go to system that measures the distance via the encoder and one sensor at a fixed point.
I’m thinking this is well within the capabilities of the Basic stamp and the BS2 I have already?
Being a while since using, it’s a bit like where do I start again……????
Can you advise on possible code for this? and any schematics if anyone has done a similar project?
Thanks for any help or assistance.
It’s been a while since I’ve done more than basic switching with the BS2 I have.
Hoping you can help and point me in the right direction with a project I need to accomplish.
I need a simple system to trigger an output being a buzzer and light indicator when a product is longer than the specified length when passing under a part of the machine. i.e. instead of 1 piece of paper has been fed past a fixed point on the conveyor belt, 2 pieces have fed incorrectly overlapping and being longer than expected.
I need to be able to measure the length of the product so I’ve ordered a digital encoder (tachometer) and photoelectric cell (photocell).
http://www.ebay.co.uk/itm/222122320381?_trksid=p2057872.m2749.l2649&ssPageName=STRK:MEBIDX:IT
http://www.ebay.co.uk/itm/331640970982?_trksid=p2057872.m2749.l2649&ssPageName=STRK:MEBIDX:IT
I need to be able to input the maximum length and change this length as and when required via keypad and LED or LCD display maybe or something simpler and not via reprogramming the code each time.
I have already built a system using 2 sensors and working on a physical trigger of both for the output error, but I need to go to system that measures the distance via the encoder and one sensor at a fixed point.
I’m thinking this is well within the capabilities of the Basic stamp and the BS2 I have already?
Being a while since using, it’s a bit like where do I start again……????
Can you advise on possible code for this? and any schematics if anyone has done a similar project?
Thanks for any help or assistance.
Comments
I could help if you were using the Prop and PropBASIC as I have been doing this for some time now.
There are quadrature decode objects for SPIN in the OBEX.
so ill order a 5-12vdc quad encoder. My systems are 24vdc with a power supply based so hence the choice.
excuse my ignorance but what do you mean by "There are quadrature decode objects for SPIN in the OBEX"?
http://obex.parallax.com/search/quadrature
Having re-read the OP, you might not need quad-decode, after all. It might be simply a case of counting the pulses of only one of the channels, if the paper is always moving in the same direction and 360 pulses/rev provides enough resolution. Quad-decode would provide an up/down count and 1,440 pulses/rev.
SPIN is the Propeller's interpreted language and PASM is Propeller assembly language. The quad-decode stuff is written in PASM and runs in a separate cog. The encoder count is stored in the hub memory so that other cogs may access it.
OBEX is here.
Spin is a language used in programming the Propellor chip. Not gonna help much for your BS-2 project.
Ive been hacking around the manuals and started a basic start on the code. Ive got stuck on the PULSIN command and it wanting a variable??
Ive read many web pages with no real solution to what im doing wrong. Basic stuff im sure but if you dont know and a steep learning curve then to be expected.
Plus the Parallax manuals and the student tutorial aren't giving me the answer.
Its a rough work in progress but any ideas why im getting errors on the PULSIN line?
Im presuming PULSIN is the command best suited?
code as follows:
Main:
DO
LOW 0
PULSIN 1, 1, value[/u][/b] "push button input" ' measure pulse input
DEBUG DEC value, CR
IF (value > 4000) THEN ' evaluate duration
DEBUG "Value was greater than 4000"
HIGH 0 'Buzzer & light output 1
PAUSE 1000
LOW 0
PAUSE 1000
DEBUG ? 0
HIGH 0 'Buzzer & light output 2
PAUSE 1000
LOW 0
PAUSE 1000
DEBUG ? 0
HIGH 0 'Buzzer & light output 3
PAUSE 1000
LOW 0
PAUSE 1000
DEBUG ? 0
ELSEIF (value = 4000) THEN
DEBUG "Value was equal to 4000"
ELSE
LOW 0
DEBUG "Value was less than 4000"
ENDIF
DEBUG CR, CR
PAUSE 1000
LOOP
' notes:
' use IF THEN ELSE FOR encoder signal to preset value to give an output to buzzer/light.
' greater or less than function
' Comparison Operator Symbol Definition
' = Equal
' <> NOT Equal
' > Greater Than
' < Less Than
' >= Greater Than OR Equal TO
' <= Less Than OR Equal TO
'Clock Speed: BS2 is 2mu's per unit of measure. 0.0002143 of a second.
'The units of time FOR PULSIN AND PULSOUT are 2 microseconds (µs).
'A microsecond is 10-6 seconds. FOR instance, IF we sent a PULSOUT with a value of 25,
'we would have the length of the pulse be: {25 x 2mu's = 25 x (2 x 10^{-6})= 50 x 10^{-6} = 50mu's =0.05ms}
'The reason why we make the conversion above from microseconds to
' milliseconds is that many devices display their requirements in terms of milliseconds
'It is always important FOR the programmer to be able to convert between different units.
' quadrature 5vdc encoder. pulsin? or count command?
'chapter 6 digital display
'chapter 5 measuring rotation
'pulsin? count?
I was referring to interfacing the encoder to the microcontroller....you're not intending to achieve this with an SSR, surely?
The encoders I used work with voltages from 5V to 24V. The signal lines needs to be pulled high to Vdd (Vdd is the voltage of the microcontroller being used).
Here's a link to a 394MB video of the Propeller gizmo I made to read the encoder (sorry, I haven't uploaded this to YouTube, if you open the link in a new tab a video player should open). I could spin the encoder at 2,400 rpm and the Propeller could keep up with the 100ppr encoders just fine.
The video linked above was made for a client of mine but I doubt he minds my sharing the video here (we've talked about this sort of thing in the past).
I also doubt he'd mind if I shared the quadrature code. The quadrature code is pretty darn simple but it's written in PASM so it's pretty fast. By "pretty fast" I mean it has about a 1.25us max loop time. This should allow it to capture up to 800 transitions per second. I'm not sure if the pull-up resistors will restore the open drain lines fast enough for an encoder to work at these sorts of speeds, but as you can see in the video, it keeps up with a 2,400 rpm drill just fine.
Any Propeller board would work as an interface board.
It's certainly possible to read a quadrature encoder with a Basic Stamp (erco has a nice video showing this) but Basic Stamp wouldn't be able to handle speeds nearly as high as a Propeller could handle.
I wondered about trying to find some the older quadrature encoder threads and look as some of the fast code but I was pretty sure I didn't need to worry much about speed. The max expected RPM was 1,800 with a 100ppr encoder so I figured a loop time less than 83us would be fine.
The code below writes to the hub twice with each transition. I wrote the direction value to hub as part of a debugging aid and I never removed it. I'm not positive I counted all the clock cycles correctly but I came up with 100 clock cycles for a worst case loop.
If you happen to recall the thread where you posted quadrature encoder code, I'd be interested to see it.
With 100ppr encoder at 2,400 rpm I figure I'm getting 62.5us between transitions (16K quad counts per second). I'm don't think I have an encoder I could use to test 1.6M quad counts a second.
As I've been thinking a bit about how to speed up the code I realized I'm doing things the slow way by checking for each possible encoder state.
The more I look at my code, the more I see ways it can be improved. I'm going to leave the code posted here but no fair holding it against me in the future.
I just mailed all my encoder reading hardware. I'll need to wire up another Propeller board so I can test any improved code I write (or test other's code).
I suppose I could use one cog to generate quadrature output and feed this output to encoder input pins.
http://forums.parallax.com/discussion/121179/reading-quadrature-encoders
http://forums.parallax.com/discussion/119343/make-your-own-encoders/p1
The first link includes a link to erco's YouTube video where he experiments with reading quadrature encoders with a BS2e. Here's a link to part 2 of his experiment.
With the Propeller, one cog can be counting encoder pulses while another cog can be calculating speed.
I took a very simplistic approach, knowing that; any change of state could be one of only two possibilities so I created separate loops for each possible state. What is not shown is the hub write which, in fact, happens each time the local variable is Inc'd or Dec'd.
http://forums.parallax.com/discussion/143397/propbasic-routine-for-quadrature-encoder-reading-fast-and-worked-first-time#latest
yeah one direction. the rpm wont be that high as with a 50mm approx disc on the encoder to run on a spring loaded pivoting mount running the wheel directly on the conveyor belt transporting the product.
direct shaft mounting isnt needed and normally a pain to install.
sorry i meant ssr for the outputs and inputs other than the encoder. The 5-12vdc encoders are little more than £10 on ebay and compact in size so not a problem to purchase a lower voltage one to suit the BS2.
If the conveyor is a constant speed (???) I wonder if the encoder is really necessary.
the conveyor may vary or be at a constant spped. The need for the Tachometer is to measure distance of a product via a lead edge trigger on the photocell.
So i can trigger an output if the length is longer than specified via input of a keypad maybe with an LCD or LED display.