BS2 counter divider
Inwo
Posts: 12
in BASIC Stamp
New to forum.
Using BS2, because I have them, from many years ago.
Need to refresh my skills to use pics.
Looking for ideas on using BS2 to divide by 4 and divide by "N" up to 500 simultaneously.
I input and two outputs.
Needs to work from 10 to 1,000hz input from hall tach sensor on motor.
I have a program working with about 15 lines of code.
2 "pulsout,1"
Works to 1khz with either divider output, but only to a few 100hz with both outputs.
Misses counts.
Is there a better (faster) way than pulsout?
Intention is to migrate to pic when it's debugged.
Will a faster pic take care of problem?
Using BS2, because I have them, from many years ago.
Need to refresh my skills to use pics.
Looking for ideas on using BS2 to divide by 4 and divide by "N" up to 500 simultaneously.
I input and two outputs.
Needs to work from 10 to 1,000hz input from hall tach sensor on motor.
I have a program working with about 15 lines of code.
2 "pulsout,1"
Works to 1khz with either divider output, but only to a few 100hz with both outputs.
Misses counts.
Is there a better (faster) way than pulsout?
Intention is to migrate to pic when it's debugged.
Will a faster pic take care of problem?
Comments
2. BS-2x or p or whatever would be faster by up to a factor of maybe four or so.
3. This sounds to me like a job for PROPELLORMAN. You could get an Activity board for $50 direct from the factory.
Are you using a vanilla BS2, or do you already have a BS2p? I agree with Tom, the Propeller can do this task easily. Also a Pic, if that is the way you want to go, as it is easily done in assembly language. The BASIC Stamp is relatively slow, because its PIC processor is executing an interpreter.
Yes, I'm using plain BS2 from many years ago.
Have other issues now getting my old epic pic equipment working.
Also can't get my old win98 computer to find BS2 activity board.
"no hrdw found"
Everything works on dos computer, but hard to see. Even in monochrome.
Serial port works with other dos programs.
Have the hardware coming (from parallax) to start using my win7 desktop. A belkin usb to serial didn't work.
All the same sw and hrdw from 15 years ago. Only my brain is different.
Changes are difficult in hrdw.
Hope to migrate to a pic only, with sw changes as needed.
Don't know asm.
Epic will compile from BS2 if I figure it out again.
Paste text???
Did not have it commented, so I'll add a couple.
Total var word
wfp: 'waiting for pulse
if in10 = 0 then plsout
if in10 = 1 then wfp
plsout:
total = total + 1
'debug dec total,cr 'slows program
if total // 10 = 0 then plsout9 'divide by 10
'if total // 4 = 0 then plsout8 'remark
wfnp: 'waiting for next pulse
if in10 = 1 then wfp
goto wfnp
plsout9:
pulsout 9,1
total = 0 ' zero total after divide by "N"
goto wfnp
plsout8:
pulsout 8,1
goto wfnp
I put together a non-modal snippet as follows. This uses XOR logic to detect the edges, also logic that doesn't use pulsout to generate the outputs. Avoids a mix of GOTOs. It may work at 200Hz too, but certainly not at 1kHz.
Are you using the most recent PBASIC 2.5 editor from Parallax?
My usb won't work.
That was just my first attempt. I have no idea about speed and such.
First I've attempted in 15 years.
Not coming back easily.
All my pic stuff is outdated. Can't get it to run on anything so far.
Found an XP with a parallel port.
Better I start over with something windows if I have to re-learn anyway.
All it does is send pulses to a tachometer and speedometer from electric vehicle.
Motor hall effect gives 4PPR hence the divide by 4.
Speedometer changes with gear ratio and tire size. Divide by "N".
There are a few other things I may want it to do.
This would leave room for lots of "few other things I may want to do". -_-
Couldn't get the xor to work BS2.
Nor do I understand it.
This divides by 4 and 10 when tested slow input.
n var word
x var word
y var bit
z var bit
dir8=1
dir9 =1
loop:
y = in10
x = y ^ z + x
z = y
out8 = x // 8 max 1
out9 = x // 20 max 1
goto loop
Thank you.
I'm looking for something that I can move to a pic.
I've done that from stamp.
How about if I get "into" propellor?
Or should I jump right into pic?
Either way, I'll have to learn a new language.
If your PIC stuff is so old it no longer works, but you want a small MCU, (ie smaller than a Prop), I'd suggest moving to a more capable family like the SiLabs EFM8 series.
Cheapest starting hardware there, is either TOOLSTICK850-B-SK (sub$10 for Debug+Device) or SLSTK2020A (sub $30, with LCD)
and because this is a good teaching example, I took your specs, and here is the EFM8 code....
Note the coded steps are very similar to the Spin above, but somewhat faster again as this is Assembler.
At default /8 clock Sim says this can cope with 58.892kHz Tacho in, and with /1 it can do 471.142kHz
(These parts have a 24.5MHz 2% on chip calibrated oscillator)
If you plan to end up with pic, any detour (say, into propellorLand) seems unneedful.
I used the propellor itself as a pulse generator; had been using a 555 but it (the 555) wouldn't run much above 100 kHz.
This exercise got me to understand just how cool waitpeq actually is. Without it, syncing up to an edge would take at least two instructions (three if you had to mask something off). With it, you just start executing instructions again at exactly the right time and with very little uncertainty.
Think I'll get some new equipment and give it a try.
Thanks for all the suggestions.
Learned a lot studying this.
I think I understand the XOR now. Detects both edges as I understand it?
Also googled -do, still haven't found it in my BS2 book???
I'll try again using a different bit "OUT1 = x.BIT1" for divide by 4.
Slowly coming back to me.
Got the new stamp hrdw, so I can run in windows now.
Look for DO...LOOP in the most recent manual:
https://www.parallax.com/downloads/basic-stamp-manual
Would have never thought of using logic and word bits, even though I've done a lot with ttl logic gates.