Newbe here
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
' =========================================================================' ' 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
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.
mycode
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.
Thank you Dr-Acula The last part is what I was missing
.I will try it as a test once again
Thanks
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
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)
' ========================================================================= ' ' File...... Mill_Speedo.BS2 ' Purpose... Wabeco CC-1210 Milling RPM Measurement ' E-mail.... [EMAIL="support@parallax.com"]support@parallax.com[/EMAIL] ' Started... 04 JUN 2004 ' Updated... 07 JUN 2004 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- E PIN 0 ' LCD Enable RW PIN 2 ' Read/Write\ RS PIN 3 ' Reg Select (1 = char) LcdDirs VAR DIRB ' dirs for I/O redirection LcdBus VAR OUTB SpeedIn PIN 15 ' Melexis 90217 output ' -----[ Constants ]------------------------------------------------------- #DEFINE Lcd = 1 ' set to 0 for VFD #DEFINE BarGraph = 1 ' set to 0 for no graph LcdCls CON $01 ' clear the LCD LcdHome CON $02 ' move cursor home LcdCrsrL CON $10 ' move cursor left LcdCrsrR CON $14 ' move cursor right LcdDispL CON $18 ' shift chars left LcdDispR CON $1C ' shift chars right LcdDDRam CON $80 ' Display Data RAM control LcdCGRam CON $40 ' Character Generator RAM LcdLine1 CON $80 ' DDRAM address of line 1 LcdLine2 CON $C0 ' DDRAM address of line 2 ' -----[ Variables ]------------------------------------------------------- char VAR Byte ' for LCD addr VAR Word ' ee pointer (for DATA) pulses VAR Word ' input pulses from motor rpm VAR Word ' motor RPM percent VAR Byte ' % of max speed (7500) fldPos VAR Byte ' field position value VAR Word ' value to print width VAR Nib ' width of print field pad VAR Nib ' spaces for rj printing idx VAR Byte ' loop counter cols VAR Byte ' total graph colums blox VAR Byte ' whole blocks for graph ' -----[ EEPROM Data ]----------------------------------------------------- Banner1 DATA " KEN GRACEY ", 0 Banner2 DATA "MILL SPEEDOMETER", 0 DefaultL1 DATA " 0 RPM 0 %", 0 #IF Lcd #THEN CC0 DATA $10, $10, $10, $10, $10, $10, $10, $00 CC1 DATA $18, $18, $18, $18, $18, $18, $18, $00 CC2 DATA $1C, $1C, $1C, $1C, $1C, $1C, $1C, $00 CC3 DATA $1E, $1E, $1E, $1E, $1E, $1E, $1E, $00 CC4 DATA $1F, $1F, $1F, $1F, $1F, $1F, $1F, $00 #ENDIF ' -----[ Initialization ]-------------------------------------------------- Reset: DIRL = %11111101 ' setup pins for LCD LOW RW LCD_Init: PAUSE 500 ' let the LCD settle LcdBus = %0011 ' 8-bit mode PULSOUT E, 1 : PAUSE 5 PULSOUT E, 1 : PAUSE 0 PULSOUT E, 1 : PAUSE 0 LcdBus = %0010 ' 4-bit mode PULSOUT E, 1 char = %00101000 ' multi-line mode GOSUB LCD_Command char = %00001100 ' disp on, no crsr, no blink GOSUB LCD_Command char = %00000110 ' inc crsr, no disp shift GOSUB LCD_Command DL_Characters: #IF Lcd #THEN char = LcdCGRam ' point to CG RAM GOSUB LCD_Command ' prepare to write CG data FOR idx = CC0 TO (CC4 + 7) ' build 5 custom chars READ idx, char ' get byte from EEPROM GOSUB LCD_Write ' put into LCD CG RAM NEXT #ENDIF Banner: char = LcdCls GOSUB LCD_Command addr = Banner1 GOSUB LCD_Put_String char = LcdLine2 GOSUB LCD_Command addr = Banner2 GOSUB LCD_Put_String PAUSE 3000 char = LcdCls GOSUB LCD_Command ' -----[ Program Code ]---------------------------------------------------- Main: addr = DefaultL1 GOSUB LCD_Put_String COUNT SpeedIn, 1000, Pulses <----- RPM = Pulses * 60 <----- GOSUB Show_RPM percent = rpm / 75 GOSUB Show_Percent GOTO Main ' -----[ Subroutines ]----------------------------------------------------- Show_RPM: char = LcdLine1 GOSUB LCD_Command width = 4 value = rpm GOSUB LCD_Put_RJ_Value RETURN Show_Percent: char = LcdLine1 + 11 GOSUB LCD_Command width = 3 value = percent GOSUB LCD_Put_RJ_Value #IF BarGraph #THEN char = LcdLine2 ' position cursor GOSUB LCD_Command cols = percent */ 205 ' x 0.8 (100% = 80 pixels) blox = cols / 5 ' calculate whole blocks IF (blox > 0) THEN char = 4 FOR idx = 1 TO blox GOSUB LCD_Write NEXT ENDIF LOOKUP (cols // 5), [" ", 0, 1, 2, 3], char ' partial block GOSUB LCD_Write char = " " FOR idx = 0 TO (16 - blox) ' clear end of graph display GOSUB LCD_Write NEXT #ENDIF RETURN ' Writes stored (in DATA statement) zero-terminated string to LCD ' -- position LCD cursor ' -- point to 0-terminated string (first location in 'addr') LCD_Put_String: DO READ addr, char addr = addr + 1 IF (char = 0) THEN EXIT GOSUB LCD_Write LOOP RETURN ' Write right-justified value at cursor position ' -- move cursor to left-most position of field ' -- put field width if 'width' (1 to 5) ' -- put value in 'value' LCD_Put_RJ_Value: LOOKDOWN value, >=[10000, 1000, 100, 10, 0], pad pad = pad - (5 - width) IF (pad > 0) THEN char = " " FOR idx = 1 TO pad GOSUB LCD_Write NEXT ENDIF FOR idx = (width - pad - 1) TO 0 char = value DIG idx + "0" GOSUB LCD_Write NEXT RETURN ' Send command to LCD ' -- put command byte in 'char' LCD_Command: ' write command to LCD LOW RS ' Write character to current cursor position ' -- but byte to write in 'char' LCD_Write: LcdBus = char.HIGHNIB ' output high nibble PULSOUT E, 3 ' strobe the Enable line LcdBus = char.LOWNIB ' output low nibble PULSOUT E, 3 HIGH RS ' return to character mode RETURN
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:
SELECT RPM CASE 0 TO 2499 LowerLimit = Value1Low UpperLimit = Value1High CASE 2500 TO 4999 LowerLimit = Value2Low UpperLimit = Value2High CASE 5000 TO 7499 LowerLimit = Value3Low UpperLimit = Value3High CASE 7500 TO 10000 LowerLimit = Value4Low UpperLimit = Value4High ENDSELECT
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