Newbe here
TOMBOLDUC
Posts: 16
Hi all,
I am new to this and to this forum.
Recenty I purchased a Basic stamp kit and a 2125 acc. chip. I have found from the parallax website a sample code that may be able to work if i can figure out how to modify it. I think I have figured out how to adjust for input delay and sensivity in the provided code.
What I am also trying to work out is how to go about changing automatically the sample time and trigger intensity based on a variable input ( say 50 pulses per second input) = one set of output paramertes then by switching to say 100 pulses per second input the program would automatically work with a different set of input values to trigger the output.
I hope I am explaning myself correctly. Any help would be appreciated
Below is the generic code that I am using
Thanks in advance
Tom
' =========================================================================
'
' File...... MEMSIC2125-Motion.BS2
' Purpose... Detects continuous motion for given period
' Author.... Parallax (based on code by A. Chaturvedi of Memsic)
' E-mail.... support@parallax.com
' Started...
' Updated... 15 JAN 2003
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
'
' Monitors X and Y inputs from Memsic 2125 and will trigger alarm if
' continuous motion is detected beyond the threshold period.
'
[ I/O Definitions ]
Xin PIN 8 ' X pulse input
Yin PIN 9 ' Y pulse input
ResetLED PIN 10 ' reset LED
AlarmLED PIN 11 ' alarm LED
'
[ Constants ]
HiPulse CON 1 ' measure high-going pulse
LoPulse CON 0
SampleDelay CON 500 ' 0.5 sec
AlarmLevel CON 5 ' 5 x SampleDelay
XLimit CON 5 ' x motion max
YLimit CON 5 ' y motion max
'
[ Variables ]
xCal VAR Word ' x calibration value
yCal VAR Word ' y calibration value
xMove VAR Word ' x sample
yMove VAR Word ' y sample
xDiff VAR Word ' x axis difference
yDiff VAR Word ' y axis difference
moTimer VAR Word ' motion timer
'
[ Initialization ]
Initialize:
LOW AlarmLED ' alarm off
moTimer = 0 ' clear motion timer
Read_Cal_Values:
PULSIN Xin, HiPulse, xCal ' read calibration values
PULSIN Yin, HiPulse, yCal
xCal = xCal / 10 ' filter for noise & temp
yCal = yCal / 10
HIGH ResetLED ' show reset complete
PAUSE 1000
LOW ResetLED
'
[ Program Code ]
Main:
DO
GOSUB Get_Data ' read inputs
xDiff = ABS (xMove - xCal) ' check for motion
yDiff = ABS (yMove - yCal)
IF (xDiff > XLimit) OR (yDiff > YLimit) THEN
moTimer = moTimer + 1 ' update motion timer
IF (moTimer > AlarmLevel) THEN Alarm_On
ELSE
moTimer = 0 ' clear motion timer
ENDIF
LOOP
END
'
[ Subroutines ]
' Sample and filter inputs
Get_Data:
PULSIN Xin, HiPulse, xMove ' take first reading
PULSIN Yin, HiPulse, yMove
xMove = xMove / 10 ' filter for noise & temp
yMove = yMove / 10
PAUSE SampleDelay
RETURN
' Blink Alarm LED
' -- will run until BASIC Stamp is reset
Alarm_On:
DO
TOGGLE AlarmLED ' blink alarm LED
PAUSE 250
LOOP ' loop until reset
I am new to this and to this forum.
Recenty I purchased a Basic stamp kit and a 2125 acc. chip. I have found from the parallax website a sample code that may be able to work if i can figure out how to modify it. I think I have figured out how to adjust for input delay and sensivity in the provided code.
What I am also trying to work out is how to go about changing automatically the sample time and trigger intensity based on a variable input ( say 50 pulses per second input) = one set of output paramertes then by switching to say 100 pulses per second input the program would automatically work with a different set of input values to trigger the output.
I hope I am explaning myself correctly. Any help would be appreciated
Below is the generic code that I am using
Thanks in advance
Tom
' =========================================================================
'
' File...... MEMSIC2125-Motion.BS2
' Purpose... Detects continuous motion for given period
' Author.... Parallax (based on code by A. Chaturvedi of Memsic)
' E-mail.... support@parallax.com
' Started...
' Updated... 15 JAN 2003
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
'
' Monitors X and Y inputs from Memsic 2125 and will trigger alarm if
' continuous motion is detected beyond the threshold period.
'
[ I/O Definitions ]
Xin PIN 8 ' X pulse input
Yin PIN 9 ' Y pulse input
ResetLED PIN 10 ' reset LED
AlarmLED PIN 11 ' alarm LED
'
[ Constants ]
HiPulse CON 1 ' measure high-going pulse
LoPulse CON 0
SampleDelay CON 500 ' 0.5 sec
AlarmLevel CON 5 ' 5 x SampleDelay
XLimit CON 5 ' x motion max
YLimit CON 5 ' y motion max
'
[ Variables ]
xCal VAR Word ' x calibration value
yCal VAR Word ' y calibration value
xMove VAR Word ' x sample
yMove VAR Word ' y sample
xDiff VAR Word ' x axis difference
yDiff VAR Word ' y axis difference
moTimer VAR Word ' motion timer
'
[ Initialization ]
Initialize:
LOW AlarmLED ' alarm off
moTimer = 0 ' clear motion timer
Read_Cal_Values:
PULSIN Xin, HiPulse, xCal ' read calibration values
PULSIN Yin, HiPulse, yCal
xCal = xCal / 10 ' filter for noise & temp
yCal = yCal / 10
HIGH ResetLED ' show reset complete
PAUSE 1000
LOW ResetLED
'
[ Program Code ]
Main:
DO
GOSUB Get_Data ' read inputs
xDiff = ABS (xMove - xCal) ' check for motion
yDiff = ABS (yMove - yCal)
IF (xDiff > XLimit) OR (yDiff > YLimit) THEN
moTimer = moTimer + 1 ' update motion timer
IF (moTimer > AlarmLevel) THEN Alarm_On
ELSE
moTimer = 0 ' clear motion timer
ENDIF
LOOP
END
'
[ Subroutines ]
' Sample and filter inputs
Get_Data:
PULSIN Xin, HiPulse, xMove ' take first reading
PULSIN Yin, HiPulse, yMove
xMove = xMove / 10 ' filter for noise & temp
yMove = yMove / 10
PAUSE SampleDelay
RETURN
' Blink Alarm LED
' -- will run until BASIC Stamp is reset
Alarm_On:
DO
TOGGLE AlarmLED ' blink alarm LED
PAUSE 250
LOOP ' loop until reset
Comments
If your input signal is a nice 5V square wave, you can sample it directly with the BS2. Tie it into any free pin (using a 220-330 ohm resistor) and COUNT the pulses over an appropriate interval. Using a 100 millisecond interval, you would COUNT five pulses for the 50 Hz signal and ten for the 100 Hz signal. Your program could then branch accordingly based on the value.
What you are describing I believe is exactly what I am trying to do with the code below ( I hope it formats correctly here this time). As I mentioned I am totally new to this, and I really have very little idea on how to write the coding to accomplish my task. In other words I can grasp the concept COUNT (input pulses) but how to branch the program based on different input frequency at the moment seems to be way over my head
Thanks in advance
Tom
[code]
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
'
' Monitors X and Y inputs from Memsic 2125 and will trigger alarm if
' continuous motion is detected beyond the threshold period.
'
[ I/O Definitions ]
Xin PIN 8 ' X pulse input
Yin PIN 9 ' Y pulse input
ResetLED PIN 10 ' reset LED
AlarmLED PIN 11 ' alarm LED
'
[ Constants ]
HiPulse CON 1 ' measure high-going pulse
LoPulse CON 0
SampleDelay CON 500 ' 0.5 sec
AlarmLevel CON 5 ' 5 x SampleDelay
XLimit CON 5 ' x motion max
YLimit CON 5 ' y motion max
'
[ Variables ]
xCal VAR Word ' x calibration value
yCal VAR Word ' y calibration value
xMove VAR Word ' x sample
yMove VAR Word ' y sample
xDiff VAR Word ' x axis difference
yDiff VAR Word ' y axis difference
moTimer VAR Word ' motion timer
'
[ Initialization ]
Initialize:
LOW AlarmLED ' alarm off
moTimer = 0 ' clear motion timer
Read_Cal_Values:
PULSIN Xin, HiPulse, xCal ' read calibration values
PULSIN Yin, HiPulse, yCal
xCal = xCal / 10 ' filter for noise & temp
yCal = yCal / 10
HIGH ResetLED ' show reset complete
PAUSE 1000
LOW ResetLED
'
[ Program Code ]
Main:
DO
GOSUB Get_Data ' read inputs
xDiff = ABS (xMove - xCal) ' check for motion
yDiff = ABS (yMove - yCal)
IF (xDiff > XLimit) OR (yDiff > YLimit) THEN
moTimer = moTimer + 1 ' update motion timer
IF (moTimer > AlarmLevel) THEN Alarm_On
ELSE
moTimer = 0 ' clear motion timer
ENDIF
LOOP
END
'
[ Subroutines ]
' Sample and filter inputs
Get_Data:
PULSIN Xin, HiPulse, xMove ' take first reading
PULSIN Yin, HiPulse, yMove
xMove = xMove / 10 ' filter for noise & temp
yMove = yMove / 10
PAUSE SampleDelay
RETURN
' Blink Alarm LED
' -- will run until BASIC Stamp is reset
Alarm_On:
DO
TOGGLE AlarmLED ' blink alarm LED
PAUSE 250
LOOP ' loop until reset
Here is some info on posting Code:
It will keep all the indentation correct.
Or you could attach the .BS2 code as an attachment, (you need to go the the "advanced" editor and use the Paper Clip icon.
I actually have been trying to do this (posting code correctly ) I am just not getting it. WYSISYG editor??? BASIC Editor ???
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[ Program Description ]
'
' Monitors X and Y inputs from Memsic 2125 and will trigger alarm if
' continuous motion is detected beyond the threshold period.
'
[ I/O Definitions ]
Xin PIN 8 ' X pulse input
Yin PIN 9 ' Y pulse input
ResetLED PIN 10 ' reset LED
AlarmLED PIN 11 ' alarm LED
'
[ Constants ]
HiPulse CON 1 ' measure high-going pulse
LoPulse CON 0
SampleDelay CON 500 ' 0.5 sec
AlarmLevel CON 5 ' 5 x SampleDelay
XLimit CON 5 ' x motion max
YLimit CON 5 ' y motion max
'
[ Variables ]
xCal VAR Word ' x calibration value
yCal VAR Word ' y calibration value
xMove VAR Word ' x sample
yMove VAR Word ' y sample
xDiff VAR Word ' x axis difference
yDiff VAR Word ' y axis difference
moTimer VAR Word ' motion timer
'
[ Initialization ]
Initialize:
LOW AlarmLED ' alarm off
moTimer = 0 ' clear motion timer
Read_Cal_Values:
PULSIN Xin, HiPulse, xCal ' read calibration values
PULSIN Yin, HiPulse, yCal
xCal = xCal / 10 ' filter for noise & temp
yCal = yCal / 10
HIGH ResetLED ' show reset complete
PAUSE 1000
LOW ResetLED
'
[ Program Code ]
Main:
DO
GOSUB Get_Data ' read inputs
xDiff = ABS (xMove - xCal) ' check for motion
yDiff = ABS (yMove - yCal)
IF (xDiff > XLimit) OR (yDiff > YLimit) THEN
moTimer = moTimer + 1 ' update motion timer
IF (moTimer > AlarmLevel) THEN Alarm_On
ELSE
moTimer = 0 ' clear motion timer
ENDIF
LOOP
END
'
[ Subroutines ]
' Sample and filter inputs
Get_Data:
PULSIN Xin, HiPulse, xMove ' take first reading
PULSIN Yin, HiPulse, yMove
xMove = xMove / 10 ' filter for noise & temp
yMove = yMove / 10
PAUSE SampleDelay
RETURN
' Blink Alarm LED
' -- will run until BASIC Stamp is reset
Alarm_On:
DO
TOGGLE AlarmLED ' blink alarm LED
PAUSE 250
LOOP ' loop until reset ]
Here is the instructon thread:
http://forums.parallax.com/showthread.php/129690-How-to-post-program-code-in-the-forum.
I really have been trying to post the code above in the correct format. I read the sticky note provided , it is just not computing in my brain. I have honesty spent several hours at trying to do this correctly, and the results keep coming back with what you see above
Yes I did see that and have been trying to understand it to no avail. The answer is probably very simple and I feel like an idiot. All I can say at this point is that I am trying. To be totally honest I am not really sure as to what the correct format should look like, however I am fairly sure it should look different than what I am displaying here now
thanks for the reply Chris
but no I want the program. to branch to several different output. options based on separate input pulse range inputs.
in other wordsa separate impulse range of let's say 50 -60 Hz.from an outside source will trigger the accelerometer to use 1 set of predefined input valuesbefore triggering an output then let's say 100 -150 h z. input pulses would now change the program to use another different input values 4 the accelerometer before triggering an output from it
left square bracket, then C then O then D then E then right square bracket, then your text, then left square bracket, then forward slash, then C then O then D then E then right square bracket.
Spaces added, but it looks like this
[ C O D E ] m y c o d e [ / C O D E ]
You are using the code from Experiment 3 of the Memsic 2125 AppKit and if you look there is a not that the SampleDelay constant should be 100 ms or greater. Remember that Frequency = 1 / Period or F = 1 / T = 1 / 100 ms = 0.01 x 1000 = 10 Hz. You can sample at whatever rate you want as long no less than 10x a second.
What exactly are you trying to measure where you have a changing frequency? 50-60 Hz sounds like AC power.
I will try it as a test once again
Thanks
Tom
Thank you once again for the help
As Erco mentioned the BS2 can count pulses using the COUNT command.
Does the speed change or will it stay the same?
There are several ways you code this in your program. You could use IF...THEN, SELECT...CASE, or LOOKUP. You could store your limits as Constants or place them in DATA statements that would be READ depending on which range is detected.
How is your system setup currently because the BS2 can also monitor pushbuttons, control LEDs, and control a motor using a motor controller. You could program test sequences into the BS2 that the user can select. What is this being used for?
Thanks again for your reply,
IN a nutshell runs through an automatic rpm cycle range, in each range the dynamics that I am trying to measure with the accelerometer changes. I need to come up with coding that will detect input rpm as pulses , then after determining which input rpm range it is in, select the appropriate x-y& time parameters before triggering the bs2 to output a command.
There will be 6-7 input rpm ranges I am thinking .... each range will have its own separate threshold limits required. I need this threshold to switch on the fly automatically based on the input.
So in escennse I need to create a code something like the example below ( these are just random number for this example BTW)
input rpm ( 1 - 2) Threshold before triggering an output from the BS2 ( X= 1 Y= 1 Time = 1 ) when x,y & time limit reached = output triggered
input rpm ( 3 - 4) Threshold before triggering an output from the BS2 ( X= 2 Y= 2 Time = 2 ) " = output triggered
input rpm ( 5 - 6) Threshold before triggering an output from the BS2 ( X= 3 Y= 3 Time = 3 ) " =output triggered
input rpm ( 7 - 8) Threshold before triggering an output from the BS2 ( X= 4 Y= 4 Time = 4 ) " =output triggered
ETC.
ETC
.
ETC,
I am wondering if the BS2 is capable of this level complexity or would I be better off starting off with the propellor platform?
BTW I an just getting started building the hardware to do my project I have limits in mind ( they may change as I progress) However I am a total novice whrn it comes to programming micro controllers and code writing. Mechanically I know what I am trying to do, electronically thats another ball game and I really do not know where to start other than stumbling across the code I posted above and testing it on the BS2 breadboard and shaking it by hand on a table. From what I observed by doing that and playing the the program settings it gave me the idea to employ it on my project as I feel it could be the solution for monitoring and detecting certain limits that I must follow that will be determined from experiments.
As I stated above I THINK that I have figured out how to change x-y-& sample time limits in the program as a one shot deal, however, coming up with coding for the level of complexity that I will require, I do not know if the BS2 is capable of that or where to even start if it is capable
Thanks again
Tom
:thumb:
Thank you for the tip Chris... I will keep that in mind in the future
Tom
Hi Genetix,
I do not at this point need to control the motor speed with the BS2 at this point, I can just use a rheostat manually, but I do need to have the BS2 coding be able to monitor the input speed and adjust the threshold values automatically as the speed changes.
At some point in the future that function may come in handy , however at this time I can live without that function.
Thanks
Tom
Forgive me if the schematic doesn't make sense.
Melexis 90217 - Numbers are for the sensor pins
P15
>|
(1) --- Vdd - 5.6K --- (3)
|_ 0.01 uF - Vss - (2)
Genetix Thank you for the Info. Looking at it I am really scratching my head trying to figure it out
I see 2 lines with arrows Is that what you are referring to?
I am really trying to understand the sequence of the BS2 language and the definitions. Starting to understand some of it but very little
I can't quite see or understand how that coding apply s to my requirements, but hopefully I may be able to piece it together
Thanks again
tom
I looked at that program and most of it doesn't apply.
This is what I am thinking you will do:
You can declare the RPM and Limits values as constants or just place them directly in the command statements.
This seems to make more sense to me at least a little bit.
However I'm still at odds as to how to interface this into the coding that I posted above. Are my X and Y values represented
by Value1 Low & High in your coding example above or are they rpm values?
The sensor that I was considering using is The Melexis 90217 sensor. I am still in the process of building the hardware for my project So my options are still wide open .
Tom