Shop OBEX P1 Docs P2 Docs Learn Events
Newbe here — Parallax Forums

Newbe here

TOMBOLDUCTOMBOLDUC Posts: 16
edited 2014-08-02 09:02 in BASIC Stamp
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

Comments

  • ercoerco Posts: 20,256
    edited 2014-07-23 21:12
    Welcome to the forums, TOMBOLDUC.

    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.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 10:05
    Thank you for your reply Erco,

    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
  • PublisonPublison Posts: 12,366
    edited 2014-07-24 10:09
    Tom, welcome to the forum!

    Here is some info on posting Code:

    attachment.php?attachmentid=78421&d=1297987572

    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.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 10:20
    Publison wrote: »
    Tom, welcome to the forum!

    Here is some info on posting Code:

    attachment.php?attachmentid=78421&d=1297987572

    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 ???
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 11:10
    [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 ]
  • PublisonPublison Posts: 12,366
    edited 2014-07-24 11:20
    Tom, Did you click on the "Click Here" ?

    Here is the instructon thread:

    http://forums.parallax.com/showthread.php/129690-How-to-post-program-code-in-the-forum.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 11:22
    Sorry guys

    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
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 11:24
    Publison wrote: »
    Tom, Did you click on the "Click Here" ?

    Here is the instructon thread:

    http://forums.parallax.com/showthread.php/129690-How-to-post-program-code-in-the-forum.



    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
  • PublisonPublison Posts: 12,366
    edited 2014-07-24 11:28
    No worries Tom. For everyone following along, here is the code Tom presented:
    ' ========================================================================='
    '   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
    
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 11:42
    THANK YOU!!!!!!! Publison That's what I have been trying to do for the last 2+ hours. Now if I could just figure out how to do it on my own, I would be a happy camper
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-07-24 13:48
    If you're using the Memsic 2125 I don't think you want to use COUNT. I think you want to continue using PULSIN (as the demo code does) and just branch based on the value returned. So if I am guessing correctly you need the code to branch to one or more points based on the tile/acceleration from the accelerometer?
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-24 16:11
    If you're using the Memsic 2125 I don't think you want to use COUNT. I think you want to continue using PULSIN (as the demo code does) and just branch based on the value returned. So if I am guessing correctly you need the code to branch to one or more points based on the tile/acceleration from the accelerometer?


    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
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2014-07-24 22:28
    THANK YOU!!!!!!! Publison That's what I have been trying to do for the last 2+ hours. Now if I could just figure out how to do it on my own, I would be a happy camper

    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 ]
  • GenetixGenetix Posts: 1,749
    edited 2014-07-24 23:09
    The output frequency of the Memsic 2125 is fixed at 100 Hz (period of 10 ms). The duty cycle, or what percentage of the time there is a high pulse, varies with how much it's moved. At rest the duty cycle is about 50% of half of the time there is a high pulse. So sitting flat and still you should see calibration values of about 250.
    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.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-25 08:56
    Dr_Acula wrote: »
    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
    

    Thank you Dr-Acula the last part is what I what was missing [/code]. I will try it as a test once again
    
    Spaces added, but it looks like this
    
    [ C O D E ] m y c o d e [ / C O D E ]
    
    
    
    
    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
    
    
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-25 09:03
    Well...... looks way better now !!!!!

    Thank you once again for the help
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-25 11:37
    I'm using specific ranges of a variable speed RPM motor driving a vibrating table with an accelerometer mounted on the table. Based on varying RPM speeds through a Hall Effect sensor it will be sending a varying pulse frequency to the input terminal of the accelerometer chip. Typical ranges are 0 -300 RPM, 300-1000 RPM, 1000-2000 RPM, and 2000-3000 RPM, for example AND they include a G force at the threshold of each range. At the upper limit of each range the input threshold of the program that I am using above will have to change before triggering it to output, but remains constant through the range. Can you suggest code(s) to provide the change at the thresholds based on the various input ranges?
  • GenetixGenetix Posts: 1,749
    edited 2014-07-26 19:37
    Oh ok I see now.
    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?
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-27 22:56
    Genetix wrote: »
    Oh ok I see now.
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-07-28 11:10
    Tom, in the interest of helping with future posts, one reason you may not have gotten very many responses is that the subject of your message doesn't tell anyone what your post is about or even that you need help. It could look like a simple introduction. You should always post a descriptive subject line that lets people browsing the forums know what your message is about. You can tell them how new you are in the beginning of the post. =) Also, always try to include all the details up front so there is not a lot of back and forth to get the details. I hope this helps in future posts on these forums.

    :thumb:
  • GenetixGenetix Posts: 1,749
    edited 2014-07-28 17:11
    Tom, do you have a motor controller? You mentioned the motor speed will be controlled automatically. I ask because the BS2 can only do 1 thing at a time.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-29 08:43
    Tom, in the interest of helping with future posts, one reason you may not have gotten very many responses is that the subject of your message doesn't tell anyone what your post is about or even that you need help. It could look like a simple introduction. You should always post a descriptive subject line that lets people browsing the forums know what your message is about. You can tell them how new you are in the beginning of the post. =) Also, always try to include all the details up front so there is not a lot of back and forth to get the details. I hope this helps in future posts on these forums.

    :thumb:

    Thank you for the tip Chris... I will keep that in mind in the future

    Tom
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-29 08:56
    Genetix wrote: »
    Tom, do you have a motor controller? You mentioned the motor speed will be controlled automatically. I ask because the BS2 can only do 1 thing at a time.


    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
  • GenetixGenetix Posts: 1,749
    edited 2014-07-29 19:17
    Here is some old code for a Mill Tachometer. Most of the code is for outputting to an LCD but I pointed to the main lines you need.

    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
    
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-07-30 21:16
    Genetix wrote: »
    Here is some old code for a Mill Tachometer. Most of the code is for outputting to an LCD but I pointed to the main lines you need.

    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
  • GenetixGenetix Posts: 1,749
    edited 2014-08-01 04:31
    Tom, do you know what Hall-effect sensor you motor uses?
    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.
  • TOMBOLDUCTOMBOLDUC Posts: 16
    edited 2014-08-02 09:02
    Thank you once again for your reply Genetix,


    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


    Genetix wrote: »
    Tom, do you know what Hall-effect sensor you motor uses?
    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.
Sign In or Register to comment.