Home Chapter 13 BS2 RCTIME & Hall Effect Sensors

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 RCTIME & Hall Effect Sensors

PROGRAMMING

In this program, you will be using a new command RCTIME. RCTIME can be used to measure the charge or discharge time of a resistor/capacitor circuit, which allows you to measure resistance or capacitance. This will allow you to use resistive or capacitive sensors such as thermistors, capacitive humidity sensors, or potentiometers as well to get some feedback from your stamp.

In a broader sense, RCTIME can also serve as a fast, precise stopwatch for events of very short duration.

Function

You have had some experience from chapter 10 with the RCTIME command which m easures the amount of time in which a pin you define stays in one logical state, either high or low. Here is a bit of review.

Syntax

RCTIME Pin, State, Variable

RCTIME measures the time a pin remains in a state or the charge or discharge time of R/C circuit.

  • Pin is a variable/constant/expression (0–15) that specifies which I/O pin to use. This pin will be placed into input mode.
  • State is a variable/constant/expression (0--1) that specifies the desired state to measure. Once Pin changes states, the measurement ends and stores the length of the measurement in Variable.
  • Variable is a variable (usually a word) in which the time measurement will be stored.

 

 Test the Hall Effect Sensor

Type in the code below

 
' {$STAMP BS2}
' {$PBASIC 2.5}

X VAR Word

Measure:

HIGH 7 'initialize pin 7 high to prepare for RC charging

PAUSE 50

RCTIME 7,1,x 'measure capacitor discharge time

DEBUG DEC x, "__" 'display charge time


GOTO measure

 

 

After entering the code take the magnet and move it in front of the hall effect sensor and see that you are getting some debug feedback in your editor window.

In this next program you will be attaching the magnet to the shaft of the DC motor and counting the number of rotations that the motor makes with the code below.

Test the Hall Effect Sensor Counting the Turning of a Motor

' {$STAMP BS2}
' {$PBASIC 2.5}

Time VAR Word

Distance VAR Word

INPUT 7

OUTPUT 0

OUTPUT 1

Sauce:

Time=0

Start:

HIGH 0

LOW 1

Distance = 0

HIGH 7

PAUSE 50

RCTIME 7,1,distance

PAUSE 200

IF distance>500 THEN add

GOTO start

Add:

Time=time+1

IF time=3 THEN switch

GOTO start

 

Switch:

HIGH 1

LOW 0

Distance = 0

HIGH 7

PAUSE 50

RCTIME 7,1,distance

PAUSE 200

IF distance>500 THEN add1

GOTO switch

Add1:

Time=time+1

IF time=6 THEN sauce

GOTO switch