130-28176 Parallax Inc, 130-28176 Datasheet
![KIT PARTS PROCESS CONTROL](/photos/8/99/89975/mfg_130-28176_sml.jpg)
130-28176
Specifications of 130-28176
Related parts for 130-28176
130-28176 Summary of contents
Page 1
Process Control Student Guide VERSION 1.0 ...
Page 2
... Parallax products, and the user may recover from the student only the cost of duplication. This text is available in printed format from Parallax Inc. Because we print the text in volume, the consumer price is often less than typical retail duplication charges. ...
Page 3
... Parallax products. Parallax Inc. is also not responsible for any personal damage, including that to life and health, resulting from use of any of our products. You take full responsibility for your BASIC Stamp application, no matter how life-threatening it may be ...
Page 4
...
Page 5
Preface........................................................................................................................iii Educator Resources.................................................................................................. iv The Stamps In Class Educational Series................................................................... v Foreign Translations ................................................................................................. vi Special Contributors.................................................................................................. vi Chapter 1: Process Control and Flowcharts ...........................................................1 What is Process Control?...........................................................................................1 Activity #1: Flowcharts for Representing Processes ..................................................3 Activity #2: Sequential Flow ...
Page 6
... Activity #7: Increasing Sensor Response .............................................................. 127 Conclusion ............................................................................................................. 130 Solutions to Chapter 4 Challenges ........................................................................ 130 Chapter 5: High Current Drive and PWM Control ............................................... 135 Activity #1: DC Fan On-Off Control ........................................................................ 135 Activity #2: Pulse Width Modulation ....................................................................... 141 Activity #3: PWM Filtering ...................................................................................... 152 Activity #4: Op-Amp Buffer and Active-Filters........................................................ 159 Activity #5: Op-Amp Non-Inverting Amplifier.......................................................... 162 Activity #6: Driving the Fan with the Op-Amp ...
Page 7
Preface Industrial process control (PC fascinating and challenging area of electronics technology and nothing has revolutionized this area like the microcontroller. The microcontroller has added a level of intelligence to the evaluation of data and a level of ...
Page 8
Actual applications require the microcontroller to read and control a wide variety of input and output (I/O) devices. The experiments include information on proper I/O signal conditioning. understanding of the electronics required to get proper input ...
Page 9
... Sensors”, Student Guide, Version 1.3, Parallax Inc., 2003 “Basic Analog and Digital”, Student Guide, Version 1.3, Parallax Inc., 2004 “Elements of Digital Logic”, Student Guide, Version 1.0, Parallax Inc., 2003 “Experiments with Renewable Energy”, Student Guide, Version 1.0, Parallax Inc., 2004 “ ...
Page 10
... Illinois University Carbondale for testing much of the text during its development. Also, thanks to Barry Shahian and Clark Radcliffe for their feedback and suggestions. Parallax Inc. would like to recognize their Education Team members: Project Manager Aristides Alvarez, Technical Illustrator Rich Allred, Graphic Designer Jen Jacobs, and Technical Editor Stephanie Lindsay ...
Page 11
Chapter 1: Process Control and Flowcharts BEFORE YOU START To perform the experiments in this text, you will need to have your Board of Education connected to your computer, the BASIC Stamp Editor software installed, and to have verified the ...
Page 12
A more sophisticated system would have a sensor to monitor temperature and provide feedback to the controller. The controller would automatically adjust the actuator to regulate the controlled parameter - temperature. The controller would drive the heating system to maintain ...
Page 13
This text explores these areas of process control through simple circuits using the BASIC Stamp microcontroller, and illustrates use with much larger systems. ACTIVITY #1: FLOWCHARTS FOR REPRESENTING PROCESSES When you hear the word ‘flowchart’, it may bring to mind ...
Page 14
While flowcharting has fallen out of fashion in many programming circles due to the advent of object-oriented programming (PBASIC used by the BASIC Stamp is procedural language still an excellent tool when planning program flow. Flowcharting is particularly ...
Page 15
Figure 1-2 Adjusting Shower Temperature Flowchart Start Turn On Cold Turn On Hot Wait A 3 Seconds Check Temperature Note how each of the symbols is used. • Typically, an input/output symbol is used when bringing data or information into ...
Page 16
As humans, we typically work with questions resulting in yes/no. In flowcharting better to use statements that result in true/false due to the logical nature of programming where conditions are checked to be true or false. Take the ...
Page 17
Construct the photoresistor, LED, piezospeaker, and pushbutton circuits shown √ in Figure 1-3. Figure 1-3 Test Circuit Schematics For an introduction to building basic circuits with these components, please see What’s a Microcontroller?, the recommended starting point for the Stamps ...
Page 18
Start Declarations and Initialization Read A Pushbutton Display Pushbutton Value Set LED to Pushbutton Value AVOID TYPOS! All of the BASIC Stamp (.bs2) programs listed in this text are available for free download from the Process Control product page at ...
Page 19
BuzzerDur CON 250 ' Constant for duration of tone for buzzer ' -----[ Initialization ]-------------------------------------------------- OUTPUT LED ' Set LED pin output OUTPUT Buzzer ' Set Buzzer pin output ' -----[ Main Routine ]---------------------------------------------------- ...
Page 20
Code Discussion As you read through the program, you can see that the coding that corresponds to the various elements of the flowchart are well highlighted using comments. The pushbutton switch is active-low, meaning that its value is 0 when ...
Page 21
Challenge 1-2: Coding from a Flowchart Figure 1 flowchart for a different sequence of operations, using the same circuit. Code a program to match this sequence of events. Hints for coding are provided in the flow symbols. Chapter ...
Page 22
ACTIVITY #3: FLOW AND CODING WITH CONDITIONAL BRANCHES In most processes, measurements are made and decisions are then based on those measurements (such as, in the shower example, whether to turn up or down the hot water based on the ...
Page 23
If you said the LED would blink on for ½ second when the button is pressed, and not at all when not pressed, you would be correct. Example Program: ConditionalLEDBlink.bs2 Enter, save and run ConditionalLEDBlink.bs2. √ ' -----[ Title ]----------------------------------------------------------- ...
Page 24
IF (PBVal = 0) THEN HIGH LED PAUSE 500 LOW LED ENDIF ' ******** 1/4 second pause PAUSE 250 When the button is not pressed, the conditional test of because the value Execution will branch to after ...
Page 25
Start Declarations and Initialization Read A Pushbutton Display Pushbutton Value False Button Pressed Blink LED 1/2 Second Delay (Pause) A Chapter 1: Process Control and Flowcharts · Page 15 Figure 1-8 Conditional LED Blink or Tone Flowchart True Sound Speaker ...
Page 26
ACTIVITY #4: PREDEFINED PROCESSES WITH SUBROUTINES Parts Required Same as Activity #2 As more operations are added to the flowchart, it can become quite large and complex. The same holds true for programs. performed within the main routine, and the ...
Page 27
Figure 1-9 Light Alarms using Predefined Processes Flowchart Read Check Photo Resistor Light High Read Light Light Level Too Bright False Display Light Level Return Return Chapter 1: Process Control and Flowcharts · Page 17 Start Declarations and Initialization Read ...
Page 28
Example Program: LightAlarmsWithSubroutines.bs2 Enter and run LightAlarmWithSubroutines.bs2. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - LightAlarmWithSubroutines.bs2 ' Sounds alarm based on photoresistor readings ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Declarations ]---------------------------------------------------- Photo PIN 0 ' Alias for ...
Page 29
FREQOUT Buzzer,200,1000 PAUSE 200 ENDIF RETURN Move your hand over the photoresistor, and watch the Debug Terminal. What √ occurs as the light level RC time is Less than 500? o Between 500 and 5000? o Greater than 5000? o ...
Page 30
Programming Tip: Every routine called with a GOSUB must exit with a RETURN. Internal pointers keep track of GOSUBs and RETURNs, and if not matched properly, will result in erroneous behavior of the processor. Challenge 1-4: Add an Operational Indicator ...
Page 31
Figure 1-11 Conditional Looping Flowchart Start Declarations and Initialization Wait For Button Get Frequency Get Count Sound Tone Chapter 1: Process Control and Flowcharts · Page 21 Wait For Frequency Button Request Display Message Frequency To Press Button (1-4000) Accept ...
Page 32
Example Program: ConditionalLooping.bs2 Enter, save and run ConditionalLooping.bs2. √ To begin, press the pushbutton as directed by the Debug Terminal. √ Enter a frequency to play and the number of times to play it by typing a value √ into ...
Page 33
GetCount: DO DEBUG CR,"Enter the number of times to play (1 to 10)",CR DEBUGIN DEC CountVal LOOP WHILE (CountVal > 10) RETURN SoundTone: FOR CountVal FREQOUT Buzzer,500,FreqVal DEBUG "Buzzing ", DEC X,CR NEXT RETURN Program Discussion ...
Page 34
Challenge 1-5 Save ConditionalLooping.bs2 under a new name, then add variables and code √ required to allow the user to enter the duration the tone should be played (entered in milliseconds). Limit the maximum allowable duration to 1000 milliseconds. CONCLUSION ...
Page 35
SOLUTIONS TO CHAPTER 1 CHALLENGES Challenge 1-1 Solution Figure 1-12 Shower Temperature Flowchart with True/False Start Turn On Cold Turn On Hot Wait A 3 Seconds Check Temperature Note that the yes-no questions became true-false statements. Challenge 1-2 Solution Your ...
Page 36
Main Routine ]---------------------------------------------------- DO HIGH LED PAUSE 500 FREQOUT Buzzer, 1000, 2000 LOW LED PAUSE 500 LOOP Challenge 1-3 Solution ' -----[ Title ]----------------------------------------------------------- ' Process Control - ConditionalLEDBlinkChallenge.bs2 ' Modify ConditionalLEDBlink for If-Else ' {$STAMP BS2} ' ...
Page 37
Challenge 1-4 Solution To the main flowchart’s loop, add another predefined 1. process: Make a flowchart for the predefined process (names 2. should match): To the programs Main Routine 3. subroutine call for your predefined process: GOSUB Indicator Under the ...
Page 38
Main Routine ]---------------------------------------------------- DO GOSUB WaitForButton GOSUB GetFreq GOSUB GetCount GOSUB GetDuration GOSUB SoundTone LOOP ' -----[ Subroutines ]----------------------------------------------------- WaitForButton: DEBUG CLS, "Press the pushbutton to begin",CR DO LOOP WHILE (PBVal=1) RETURN GetFreq: DO DEBUG CR,"Enter the frequency ...
Page 39
Chapter 2: PC Based Monitoring and Control In the program LightAlarmWithSubroutines.bs2 from Chapter 1 (page 18), it would be very difficult to determine rate of change, to look for trends spot abnormalities as numbers change on the screen. ...
Page 40
... Download and install the Process Control Macros from the same location as √ StampPlot. From your Start menu Programs → Parallax Inc → StampPlot → SIC √ Process Control → → sic_pc_light_level.spm. This will load StampPlot with the selected macro, a text file containing configuration and data manipulation instructions for StampPlot ...
Page 41
Let's test the software. Run LightAlarmsWithSubroutines.bs2 from page 18. √ Note the Com Port in use at the top-left of the BASIC Stamp Debug Terminal. √ Close the Debug Terminal. √ On StampPlot, select the Com Port noted in the ...
Page 42
Figure 2 sample plot for this activity. If the high and low-level setpoints are exceeded, a new window opens titled "Messages" as shown in Figure 2-4. This lists the high and low level alarm messages sent by the ...
Page 43
DO NOT change since that information is coming from the BASIC Stamp. By clicking the "Set Range to Scales" button, the range of the meter will adjust to match the current scale on ...
Page 44
Challenge 2-1 Perform the following: Disconnect on StampPlot (F6). √ Save LightAlarmsWithSubroutines.bs2 under a new name. √ At the end of the Initialization section of your BASIC Stamp program, add: √ DEBUG CR, "!SPAN 0,2000" the Main Routine ...
Page 45
ACTIVITY #2: STAMPPLOT INTERACTIVE CONTROL StampPlot also supports interactive control with the BASIC Stamp. The BASIC Stamp can request data from StampPlot and use the data for updating parameters. Parts Required Same as Chapter 1, Activity #2 (page 6). Open ...
Page 46
This txtMinA command: DEBUGIN DEC PhotoMin ...accepts data arriving on the data port and stores decimal value. Execution will cease ...
Page 47
ACTIVITY #3: STAMPPLOT TOOLBAR CONTROLS Parts Required Same as Chapter 1, Activity #2 (page 6). Open StampPlot to the macro sic_pc_light_level.spm. √ In the BASIC Stamp Editor, open LightAlarmsWithSubroutines.bs2 from page √ 18 and save it with a new name. ...
Page 48
Resets the plot to time 0 and erases the plot. • *Connect: Connects StampPlot to the selected Com Port. Note: StampPlot is configured to reset the Stamp when the connection is made. • *Plot: Enables plotting of incoming ...
Page 49
Time Stamp: Add date and time to data for messages and data file. • Configure: Configures StampPlot for various settings and configurations. • Values: Shows plot values under mouse pointer and minimum and maximum values plotted. • Messages: Opens ...
Page 50
Challenge 2-3: Configuring StampPlot 1. Use StampPlot controls for a configuration to plot 30 seconds of data for a light level range of 500 to 1000. The plot should reset and repeat every 30 seconds. 2. Use StampPlot controls for ...
Page 51
COM Port: Used to select the serial communications port that the BASIC Stamp is connected to. • File Name: An assortment of files and settings will use this specified name. The user may change the name for collecting data ...
Page 52
File Name textbox. The user may also take a snapshot at anytime by using the Snapshot button the toolbar. • Append Date/Time to image: snapshot file name, (File_Name)Date_Time.jpg, to create unique image files every time the ...
Page 53
Plot the light level and select to stop the plot at maximum. About halfway through, fully darken the light falling on the sensor. Once stopped, annotate the plot with text about what occurred at that point. CONCLUSION Computer based ...
Page 54
As in number 1, enter values for range and time in the top drop-down boxes and tab-off shift and plot the 'Stop' button should be off, and the 'shift button' should the toolbar. Challenge ...
Page 55
Chapter 3: Digital Input Conditioning Digital Input seems pretty cut and dried. An input voltage at Vdd is recognized as a digital HIGH (binary 1). An input voltage at Vss (ground) is recognized as a digital LOW (binary 0). However, ...
Page 56
Construct the circuit in Figure 3-1. √ Example Program: DataMonitoring.bs2 Enter and run the BASIC Stamp program DataMonitoring.bs2. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - DataMonitoring.bs2 ' Monitors and Plots Analog and Digital Data ' {$STAMP BS2} ' ...
Page 57
LED PIN 0 ' LED output pin DigIn PIN 8 ' Digital input pin monitored ADC_CS PIN 13 ' ADC Chip Select pin ADC_Clk PIN 14 ' ADC Clock pin ADC_Dout PIN 15 ' ADC Data output ' -----[ Initialize ...
Page 58
Manufacturer data sheets provide guaranteed threshold voltage for a device. Legal HIGH and LOW values are considered above and below these levels. • V – Voltage In-High: Voltage above which assured to be HIGH on the IH input. • V ...
Page 59
PROGRAM DISCUSSION LED in Figure 3-1 is used to indicate the state of P8: LED On = HIGH. 1 The potentiometer may simply be thought variable voltage divider, such as in Figure 3-3. Keep in mind that ...
Page 60
V = I(R )= (0.5 mA)(8 kΩ How much voltage is dropped across (IR = (0.5 mA)(2 kΩ The total voltage of the series circuit in ...
Page 61
Saving digital input is performed within the routine to read the ADC attempt to read both the ADC and digital input at the same time. The ADC value and the digital value may not track perfectly depending on ...
Page 62
Cast a shadow over the the photoresistor. What happens to voltage? When does √ your light energize? In the CdS (Cadmium Sulfide) photoresistor, light photons excite electrons and allow them to flow more freely. This in turn changes the resistance. ...
Page 63
Challenge 3-2: Photographic Darkroom Alarm Modify the circuit to exceed the threshold when excess light falls on the sensor. √ Draw your circuit modifications. Discuss settings and results. ACTIVITY #3: UNCOMMITED INPUTS AND CONDITIONING SWITCHES An uncommitted input is one ...
Page 64
Replace the photoresistor circuit Figure 3-4 with the pushbutton circuit as shown √ in Figure 3-6. Re-run the program DataMonitoring.bs2 √ Close the Debug Terminal. √ Run the StampPlot macro sic_pc_data_monitoring.spm. √ Connect and plot. √ Monitor the digital and ...
Page 65
Figure 3 sample plot of the results. When the pushbutton is pressed, current passes through the switch to register a solid HIGH value. The input is now committed and no longer floating. When the normally-open (N.O.) pushbutton is ...
Page 66
The pull-down resistor R is used to force the input to a low voltage when the pushbutton 5 is not pressed, keeping it LOW. When the button is pressed, current flows through R allowing a HIGH to be sensed on ...
Page 67
The pushbutton circuit is termed Active-High because when the button is active (pressed), the input state will be HIGH, a pull-down resistor is used to force the input LOW (when the pushbutton is not pressed). Always check data sheets for ...
Page 68
Integrated Circuit (IC) to perform sophisticated operations switch, the transistor may be driven to a condition where it drops virtually no voltage and allows full current flow in a load. In ...
Page 69
Beta (β) or, when dealing with strictly DC B values • Saturation Region: An increase in base current does not ...
Page 70
Table 3-1: 2N3904 Transistor Specifications Parameter Value h or ß 100 – 300 FE I 200 0 0.65 V – 0. ECO P 625 mW D Let's perform testing ...
Page 71
Connect ADC- Adjust the potentiometer and note the direction that √ P causes an increase in voltage (clockwise or counterclockwise). Disconnect ADC-IN from V √ potentiometer is adjusted? Does the increase in voltage follow V and connect ...
Page 72
Does the voltage at V potentiometer or only over a portion of movement? Analyzing what is occurring with reference to Figure 3-13: • increases in voltage, the current through the base (I P • ...
Page 73
Voltage and Current Characteristics Cutoff Region: With insufficient base current, the transistor will essentially be off (an open switch) and acts as a very high resistance from collector to emitter. I the output (V ) will be supply voltage, or ...
Page 74
Saturation Region: As shown, there must be some limit to how much current can be developed in the collector. The current limit is based on the supply voltage and the value of R called saturation current (I ). SAT I ...
Page 75
Any device that has current flowing through it and a voltage drop across it coverts electricity into power. This power ...
Page 76
Keep in mind that when using the transistor as a switch (in saturation or cutoff), the maximum power occurs only during the transition so that the power dissipated will be very low. The more frequently the transition occurs (frequency), the ...
Page 77
Figure 3-14 DC Load Line and Transistor Power Adjust the potentiometer slowly. Note the range over which the load line goes √ from cutoff to saturation. Replace R with a 10 kΩ resistor. √ StampPlot, change the value ...
Page 78
Reset the plot and re-acquaint yourself with the results of movement for the √ potentiometer. Replace R with the 10 kΩ resistor. √ B Reset the plot and adjust the potentiometer very slowly to obtain a new plot. √ Has ...
Page 79
Another effect is loading on the output. Take, for example, a voltmeter with an input impedance of 1 MΩ MΩ and the transistor is in cutoff, what voltage will be C read? It should be 5 ...
Page 80
Impedance is similar to resistance, but also takes into account AC characteristics, which will not be explored in this text. Ideally, the output impedance of a device should be zero, and the input impedance should be infinite to transfer the ...
Page 81
Note the similarities in operation: • The pushbutton is activated by pressing it. The transistor is active (in saturation) when sufficient voltage is applied to V • Both circuits have a HIGH output when the switch is not active through ...
Page 82
The common-collector is slightly more difficult to analyze, and we will only briefly discuss it. In the common-emitter the base current is calculated through −0.7)/ The collector current is determined from this value using ...
Page 83
ACTIVITY #7: TYPICAL INDUSTRIAL SWITCHES The pushbutton is just one of many switches available. Figure 3-19, Figure 3-20, and Table 3-2 show a variety of different switches commonly used in industrial applications. These switches may be either mechanical or electronic ...
Page 84
Table 3-2: Schematic Symbols for Various Industrial Switches Pushbutton Normally Open Normally Closed The proximity switches shown in Figure 3-20 are commonly used in industry to detect the presence of an object and operate on one of three principles: • ...
Page 85
A common final output stage of an electronic switch is shown in Figure 3-21. This configuration allows maximum flexibility for engineers in integrating it into their systems. The output may be configured as common-emitter or common-collector, and the resistors sized ...
Page 86
Other devices may simply output a digital HIGH and LOW. If the device does not use the same supply, ensure that output voltages are compatible with the BASIC Stamp. If the switch is powered from another supply, the grounds will ...
Page 87
Figure 3-23 (top): Higher-voltage digital signals can be interfaced using a 74HC4050 buffer or 74HC4049 inverter powered at +5 volts. These devices can safely handle inputs volts. Again, the grounds must be common. Figure 3-23 (bottom): An ...
Page 88
Challenge 3-7: Wiring a Relay The relay can use high voltage DC, to energize a solenoid that closes or opens electrically isolated mechanical contacts that can be used as input to the BASIC Stamp. Signal conditioning these contacts ...
Page 89
The DC Load Line is a graphical representation of output voltage and collector current over the linear range. The value common-emitter configuration determines the saturation ...
Page 90
Challenge 3-2 Solution Placing the photoresistor on the Vdd side of the potentiometer modifies the circuit for a darkroom sensor. When more light falls on it, the resistance decreases dropping more voltage across the bottom half causing voltage to increase. ...
Page 91
Challenge 3-4 Solution I = (40 V− 0.3 V)/500Ω = 79.4 mA SAT Maximum continuous is 200 mA ½ ½ MAX SAT dd Maximum is 625 mW so heat sinking is required. ...
Page 92
Challenge 3-6 Solution − 0.7)/( V− 0.7)/((100)(100 Ω kΩ) = 0.075 (0.075 mA)(100) = 7.5 mA ...
Page 93
Chapter 4: Sequential Processes and Optical Switches Sequential processes are those that follow a defined sequence of actions based on events. Events involved in a sequential process may be time based, where different actions occur with defined intervals of time. ...
Page 94
Some examples of optical sensors include: • Using a light beam to detect presence of an object or person at a moderate distance (several feet). • Using an emitter and detector pair for very close detection, such as motion of ...
Page 95
The IR LED emitter and phototransistor are combined in a single package. The pair are angled for maximum reflection from a surface at a distance of 0.15 inches (3.8 mm) or about 1 inch. This non-contact switch responds ...
Page 96
Construct the circuit shown by the schematic in Figure 4-2 and the wiring √ diagram in Figure 4-3. Note that Q QRB1114. Set aside the 100 kΩ and 1 MΩ resistors for now. Mount the QRB1114 as shown. Bend the ...
Page 97
Run the program DataMonitoring.bs2 from page 46. √ Close the Debug Terminal. √ Run StampPlot macro sic_pc_opto_plot.spm. √ Connect and plot. Nothing will show or update initially on the main plotting √ area. Move your hand just a few inches ...
Page 98
Use a folded piece of white paper or a white card for the reflective object. √ For maximum reflection, fold it so that the surface facing the detector is as vertical as possible. Start ...
Page 99
Repeat for at least 10 readings, moving a little closer to the switch each time. √ Each time you click Plot, a new point will appear on the graph. Be sure to include the lowest voltage achieved and at least ...
Page 100
Based on the value that provides the best response, which resistor would you use for a digital switch? Figure 4-6 shows the results of our test with the 100 kΩ value. Note as the distance is reduced (X-axis), the voltage ...
Page 101
Table 4-1: Surface/Distance Combinations for 1.5 Volts Surface Material White Paper Test Reflector ACTIVITY #2: BATCH OR SEQUENTIAL PROCESS CONTROL A batch, or sequential process, uses input signals and timing to perform a straightforward set of operations. A good example ...
Page 102
The following is an operational description of the batch process illustrated in Figure 4-7. A flowchart of the process is in Figure 4-8. Figure 4-7 Batch Mix System • When the Start button is pressed, the vat will begin to ...
Page 103
Figure 4-8 Batch Sequence Flowchart Parts Required (1) Resistor – 100 Ω (6) Resistors – 220 Ω (2) Resistors – 1 kΩ (1) Resistor – 10 kΩ (1) Opto-Reflective Switch – QRB1114 ...
Page 104
LED – Green (1) LED – Yellow (1) LED – Red (2) Pushbuttons Construct the circuit shown in Figure 4-9 and Figure 4-10. Leave the ADC √ circuit on your board for later use. Figure 4-9 Batch Sequence Circuit ...
Page 105
Example program: BatchMix.bs2 Enter and run program BatchMix.bs2. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - BatchMix.bs2 ' Control System for filling, mixing and draining a vat ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Declarations ]---------------------------------------------------- Stop_SW PIN ...
Page 106
PAUSE 500 DEBUG CR,"!RSET",CR, "!CLRC",CR, "!SPAN 0,500",CR DEBUG "@TEXT 1A,D0,1A,(Blue), Start Sw",CR, "@TEXT 1A,D1,1A,(Blue), Proximity Detector",CR, "@TEXT 1A,D2,1A,(Blue), Stop Sw",CR, "@TEXT 1A,D3,1A,(Blue), Fill",CR, "@TEXT 1A,D4,1A,(Blue), Mix",CR, "@TEXT 1A,D5,1A,(Blue), Drain",CR DEBUG "!O lblData = Mix Time:\n(Sec)",CR, "!O txtData = 15",CR, "!O ...
Page 107
NEXT LOW Mix HIGH Drain DEBUG "!O Stat1 = Draining",CR DO UNTIL (Stop_Sw = 0) GOSUB Display_Data LOOP LOW Drain DEBUG "!O Stat1 = Completed",CR Total_Mixed = Total_Mixed + Vat_Volume DEBUG "!O Stat2 = Total Gallons:", DEC Total_Mixed,CR LOOP ' ...
Page 108
Figure 4-11 General Purpose Interface Connect on StampPlot. Notice that the controls on the interface are updated √ accordingly with a default mix time of 15 seconds. Press the Start Button (PB1) to begin the fill operation. √ Observe that ...
Page 109
The three input switches are all Active-LOW, and the three outputs are all Active-HIGH. In Figure 4-12 the sequence of operations can clearly be seen in the traces for both inputs and outputs. Figure 4-12 Fill, Mix and Drain Batch ...
Page 110
DEBUG "!O txtR = Filling", CR This code will place Filling in the red indicators text box. control which is then named and assigned ...
Page 111
To label our 6 digital traces we used this line of code: DEBUG "@TEXT 1A,D0,1A, (Blue), Start Sw" this example absolute coordinate meaning as the plot shifts the text will 1A remain static. The same is ...
Page 112
Close the Debug Terminal. √ Run StampPlot macro sic_gen_process.spm. √ Click the "Delete Log" button on the interface and affirm the notice. √ Check the "Log Data" check box to begin storing incoming data to StampPlot. √ Run a batch. ...
Page 113
Challenge 4-3: Manual Data Logging StampPlot also allows manual logging of data using the DEBUG "!LOGD FILLING",CR Data from the BASIC Stamp can be incorporated: DEBUG "!LOGD Run Complete – Gallons Mixed: ", DEC Total_Mixed, CR Finally, data from StampPlot ...
Page 114
ACTIVITY #4: BOX CONVEYOR BELT – COUNTING AND EDGE DETECTION Parts Required Same circuit as Activity #2 This conveyor belt simulation activity uses the same BASIC Stamp circuit and StampPlot macro as the previous activities, but addresses different issues by ...
Page 115
Figure 4-15 (a)? Figure 4-15 Detection and Counting Algorithms a. c. "Sample Time" is how frequently a program reads a value. If the ...
Page 116
Consider the partial flowchart in Figure 4-15 (b). As long as a box is not detected, the decision will be false and no count will occur. When a sample detects a box, the flow will loop and wait until the ...
Page 117
The count would only occur when both conditions are true. no box present AND the flag needs to be set for a count. That "AND" is called Boolean Logic and the BASIC Stamp supports it directly by use of an ...
Page 118
Conveyor PIN 11 Box_Count VAR Word Box_Truck VAR Byte Edge_Flag VAR Bit Max_Truck VAR Byte ' -----[ Initialization ]-------------------------------------------------- LOW Conveyor LOW Diverter LOW Box_Det PAUSE 500 DEBUG CR,"!RSET",CR, "!CLRC",CR, "!SPAN 0,20",CR DEBUG "@TEXT 1A,D0,1A,(Blue),Conveyor",CR, ' Label digital data traces ...
Page 119
Count_Box: IF (Opto_SW = 0) THEN Edge_Flag = 1 HIGH Box_Det ENDIF IF (Opto_Sw = 1) AND (Edge_Flag = 1) THEN Box_Count = Box_Count + 1 Box_Truck = Box_Count // Max_Truck IF (Box_Truck = 0) THEN TOGGLE Diverter ENDIF LOW ...
Page 120
Stop the conveyor and change the value of the StampPlot input text box "Boxes √ Per" Start the conveyor and run boxes past. What changes? Why? √ Figure 4-16 shows a plot from a sample run that includes ...
Page 121
Challenge 4-4: Better Start/Stop Control What happens when both the START and STOP buttons are held down? The LED on the board blinks rapidly. If this were controlling a motor it would be cycling on and off emergency, ...
Page 122
Parts Required Same circuit as Activity #2 Excessive Signal Durations When dealing with the physical world and human-input, most things never go as planned, but a well-programmed process control system should be able to deal with these mishaps. As the ...
Page 123
Use the main status box above the plot for feedback showing the accumulated value when testing: DEBUG "!STAT Accum value=", DEC your_accum_variable let’s try it! Save BoxConveyor.bs2 under a new name: BoxConveyorSignal.bs2. √ To the Declarations section ...
Page 124
Challenge 4-5: Debounce with Programming Save BoxConveyor.bs2 under a new name. √ To the subroutine add code that would prevent input bounce from √ Count_Box affecting the count for normal conditions. Pseudocode is provided for one method. Show your code ...
Page 125
Testing the Encoder Wheels The encoder wheels work only when the black segments absorb the infrared light emitted by the QRB1114. A black surface produced by laser toner and inkjet copiers usually works well, but a home photo printer that ...
Page 126
Cycle/revolution 2 Cycles/revolution 4 Cycles/revolution 6 Cycles/revolution 8 Cycles/revolution Now that you have confirmed usable encoders, let’s modify our circuit to use the fan just a matter of removing the two pushbutton circuits and the LED circuits ...
Page 127
Parts Required (1) ADC0831 (1) Resistor – 100 Ω (2) Resistors – 220 Ω (1) Resistor – 10 kΩ (1) LED – Green (1) Opto-Reflective Switch – QRB1114 (1) Brushless DC Fan Build (or modify) your circuit as shown in ...
Page 128
Figure 4-19: Tachometer Wiring Diagram Enter, save and run Tachometer.bs2. √ Close the Debug Terminal. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - Tachometer.bs2 ' Measures RPM of Fan ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Declarations ]---------------------------------------------------- ...
Page 129
Label text boxes DEBUG "!O lblData = Sample Time\n "!O txtData = 1000", CR, "!O txtR = ", CR, "!O txtY = ", CR, "!O txtG = Sampled", CR, "!O Stat1 = Counts:", CR, "!O Stat2 = RPM:", CR, ...
Page 130
A typical reading is 8000 RPM, though this will vary with supply voltage. Lightly touch the front of the fan to vary speed, and monitor on StampPlot. √ Monitor the RPM. Skip these next two steps if you are ...
Page 131
Figure 4-20 Fan RPM with When Powered from Vin With this configuration and sample time what is the resolution of the tachometer? For each count change, there is a change of 60 RPM. Depending on the application, this may or ...
Page 132
Figure 4-21 Waveform of Phototransistor Output for 1 Cycle/Revolution Encoder Note the period of the waveform. The time represented between each horizontal major division, or dashed vertical line ms. A complete cycle takes approximately 3.6 divisions. 3.6 div ...
Page 133
This waveform was captured using the circuit in the next activity. Effects of loading lowered the metered voltage significantly due to the high impedance output of the circuit (RC = 1MΩ) and the impedance input of the oscilloscope used for ...
Page 134
Figure 4-22 Fan RPM Plot with Varying Sample Durations One way to increase the resolution without having to sample longer is to increase the number of counts per revolution. Using an encoder wheel with two light/dark pairs will double the ...
Page 135
Figure 4-23 Waveform of Phototransistor Output for 8 Cycle/Revolution Encoder Place the encoder wheel for 2 Cycles/Revolution on the fan, doubling the √ number of counts for the same unit of time. In the code, change the value of the ...
Page 136
Table 4-4: Tachometer Resolution with Different Encoders 2 Cycles/Revolution 4 Cycles/Revolution Time Count RPM Res. Count 1000 5000 100 50 Challenge4-6: Analyzing a Waveform Figure 4- waveform capture of an encoder with the time base set at √ ...
Page 137
ACTIVITY #7: INCREASING SENSOR RESPONSE While testing the various encoder wheels in Activity #6, you probably encountered a point where the RPM and count is abnormally low or zero. The response time of the sensor is insufficient to read the ...
Page 138
Additional Components Required: (1) 2N3904 Transistor (1) 220 Ω resistor (1) 1 kΩ resistor Leave the ADC circuit on the board not used in this activity but will be √ again later not shown in the ...
Page 139
Re-run Tachometer.bs2, and close the Debug Terminal. √ Run StampPlot macro pc_gen_process.spm. √ Complete Table 4-4 in Activity #6 using the higher cycles/count encoder wheels √ if not yet complete. You may have to re-adjust the distance between the QRB1114 ...
Page 140
CONCLUSION The opto-reflective switch combines an emitter (LED) and detector (phototransistor single package for the detection of near-range objects. The phototransistor acts similar to a BJT transistor, except that the base current is controlled with light instead of ...
Page 141
Challenge 4-2 Solution At end of code, add: √ Shutdown: IF (Stop_SW = 0) THEN LOW Fill LOW Mix LOW Drain DO GOSUB Display LOOP ENDIF RETURN Within each loop, add: √ GOSUB Shutdown Challenge 4-3 Solution Your partial code ...
Page 142
Challenge 4-4 Solution Your code may look like this: Run_Control: IF (Start_SW = 0) AND (Stop_SW = 1) THEN Challenge 4-5 Solution Assuming it requires 3 seconds for a box to pass, add this code block to the subroutine: IF ...
Page 143
Add the new subroutine √ RPMIndicator RPMIndicator : IF (RPM > 7500) then HIGH Green_LED LOW Red_LED ELSE LOW Green_LED HIGH Red_LED ENDIF RETURN : ...
Page 144
...
Page 145
Chapter 5: High Current Drive and PWM Control Earlier chapters discussed means to use transistors, standard or optical, to condition an input signal for the BASIC Stamp. Equally important in process control is the ability to drive large loads such ...
Page 146
But before testing this out, let's ensure the devices can meet the specifications with the fan acting as the load. • Q. Can the transistor collector handle the current requirements of the fan, which is 90 mA? • A. Yes, ...
Page 147
Figure 5-2 Switched Fan Drive Schematic Note: The ADC circuit is not shown, but leave it on the board for future use. ...
Page 148
Enter, save and run FanOnOffControl.bs2. √ Test the program. The fan should cycle on and off every 5 seconds. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - FanOnOffControl ' Controls 12Vdc fan with transistor driver ' {$STAMP BS2} ' ...
Page 149
Rs-on is typically less than 1 ohm. Applying a low ( the gate places the device in cutoff. In this state there is virtually no load current and the MOSFET acts as an open switch. The power MOSFET ...
Page 150
Replace the 2N3904 transistor that is connected to the fan with the BS170 √ MOSFET transistor to form the circuit shown in Figure 5-5. Be very careful to observe the proper pin placement. WARNING! The pinout for the BS170 is ...
Page 151
Challenge 5-1: Fast On-Off Cycling Save the program FanOnOffControl.bs2 under a new name. √ Change the and √ OnTime fast is the fan running compared to previously? Test other values where the on and off times add up to 10, ...
Page 152
If the period is 10 ms, and the output is high for 5 ms: Duty Cycle = On-Time/Period = 5 ...
Page 153
Ready to run PWM tests on your fan? Figure 5-6 Duty Cycles a.) 50% Duty Cycle b.) 25% Duty Cycle c.) 75% Duty Cycle ...
Page 154
Example Program PwmTest.bs2 Attach the 4-cycles/revolution encoder to the fan (cut-outs can be found in √ Appendix A. Enter, save and run PwmTest.bs2, then close the Debug Terminal. √ ' -----[ Title ]----------------------------------------------------------- ' Process Control - PwmTest.bs2 ' Uses ...
Page 155
IF duty < 100 THEN LOW Fan DEBUG IBIN OUT2,CR PAUSE 100-Duty NEXT RETURN Calibrate: HIGH Fan PAUSE 3000 DO COUNT Opto_SW,100,Opto_Count RPM = Opto_Count * (60000 / 100) / CyclesPerRev ' Calculate RPM DEBUG CR,"!REQD 0,30,Maximum RPM=", DEC RPM, ...
Page 156
Figure 5-7 PWM Test with Manual Drive As seen in Figure 5-8, a 100% drive, or duty cycle, is applied, and a sample of RPM is taken. The %Duty and %RPM are plotted (and updated in the gauges). Next, a ...
Page 157
The 20% drive is not truly 20%. Program Discussion In the subroutine, input from the user verifies that the fan is at ...
Page 158
The BASIC Stamp works in integer math. That is, values with decimal places will be truncated, or have the decimal portion dropped. Also, any intermediary math calculation cannot exceed 65,535. Using the PWM Instruction A much more efficient means to ...
Page 159
Figure 5-9 PWM Drive using the PWM Command Figure 5 sample plot of the drive versus the RPM. The linearity and control is much better than the prior result, though the lower voltage limit of the fan is ...
Page 160
A high-frequency duty cycle is not always desirable. Inductive loads, such as motors, limit how fast the current can change. With high-frequency duty cycles the current does not have time to build and will limit the response at lower duty ...
Page 161
Part A: Currently in PwmCommand.bs2’s repetitions for a PWM time of 100 ms. This allows 1.5 seconds for the fan to reach a new speed prior to taking a reading. Save PWMTest.bs2 under a new name. √ Modify the √ ...
Page 162
ACTIVITY #3: PWM FILTERING The inertia of the fan performed mechanical filtering, or damping, to run at various constant speeds with a quick cycling of high and low voltages. Your eye performed filtering of the LED blinking on and off ...
Page 163
Enter, save and run the program PWMFiltering.bs2. √ Open StampPlot macro sic_pc_pwm_filtering.spm √ Connect and plot. √ Figure 5-11 RC Filter of PWM Circuit Top: Schematic Bottom: Wiring Diagram ...
Page 164
Title ]----------------------------------------------------------- ' Process Control - PwmFiltering.bs2 ' Control of PWM filtering circuits through StampPlot ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Declarations ]---------------------------------------------------- ADC_DataIn VAR Byte ' Analog to Digital Converter data PWM_Val VAR Byte ' ...
Page 165
PlotData: DEBUG DEC ADC_DataIn ,",", "[",DEC ADC_DataIn,",*,0.0196]",CR PAUSE 50 RETURN This program reads slider controls from StampPlot. One sets value the of the variable, which will be used as the number of samples to measure (0-255) before re-applying the PWM ...
Page 166
The resolution of a system can also be defined in percentage, where: %Resolution = (Smallest Change/Total Range) x 100% %Resolution = .0196 V 100% = 0.392% So, for a range the smallest change is 0.392% ...
Page 167
Does the voltage eventually start to decrease? After the PWM has been applied, the BASIC Stamp output is high impedance, limiting the loss of electrons on the charged capacitor. The charge is also lost through the ADC sampling the voltage ...
Page 168
Figure 5-13 RC Network Discharge Set the PWM Value control to 255 (100% duty cycle) and adjust the samples to √ measure the full time it requires the charge to dissipate may be beneficial to log ...
Page 169
Challenge 5-3 : Modifying RC Values Part A: Based on the equation for the RC network time constants, what would be the result of changing R to 100 kΩ? L Calculate the discharge time. √ Test your results. √ Part ...
Page 170
Figure 5-14 shows the schematic symbol for an op-amp, though most times the supply voltage connections are not shown. Figure 5-14 also shows the pins of the LM358 dual op-amp. Figure 5- buffer configuration. With V must the ...
Page 171
Add the op-amp to the circuit as shown in Figure 5-16. √ Use the 100 kΩ resistor for R √ Run PwmFiltering.bs2. √ Run StampPlot macro sic_pc_pwm_filtering.spm. √ Monitor voltages and discharge rates for varying PWM values. √ ...
Page 172
Adjust the drive, which should produce stable voltages. √ You may note the voltage increasing slightly over time. Very small leakage through the non-inverting input is causing the capacitor to charge further. While not critical, if not refreshed regularly (occurs ...
Page 173
What would happen if the output was not connected directly to the inverting input, but used a voltage divider to cut the output voltage in half before being fed to the inverting input as shown in Figure 5-17? With the ...
Page 174
Additional Parts Required (2) 10 kΩ Resistors (1) 4.7 kΩ Resistor (2) 1 kΩ Resistors Reconfigure the op-amp as shown in Figure 5-19. Set the 4.7 kΩ resistor aside √ for the moment. Add R and R for the ADC ...
Page 175
Figure 5-18 Filtered with Non- Inverting Gain Schematic Figure 5-19 Filtered with Non- Inverting Gain Wiring Diagram ...
Page 176
Challenge 5-5: Changing the Gain Replace R with a 4.7 kΩ Resistor. √ f Calculate: √ a. The gain. b. The maximum output voltage predicted for a PWM of 255. c. The output voltage for a PWM value of 25. ...
Page 177
R With supply, and mA. The transistor is operating in the linear region to supply 40 mA, developing the 4 V required. decreases to 50 ...
Page 178
Figure 5-21 Filtered PWM Driving Fan Schematic (top) and Wiring Diagram (bottom) ...
Page 179
Challenge 5-6: Monitoring RPM Save ModPwmFiltering.bs2 under a new name. √ Modify the program to show the fan's RPM in the StampPlot 'User Status' box √ above the plot. Example code to update the text: DEBUG "!STAT RPM= ", DEC ...
Page 180
ADDITIONAL DEVICES OF INTEREST While we won't test these circuits and devices, they are worth discussing. Darlington-Pair Drivers Just as a Darlington-pair may be used to detect small signals, as explored with the opto- reflective switch, they may also be ...
Page 181
Figure 5-23. The BASIC Stamp controls the ULN2003, which energizes 100 mA relay coil. The relay coil is ...
Page 182
H-Bridges Using PWM control, it was seen that the speed motor might be controlled. How about direction? This can be performed using the H-Bridge as shown in Figure 5-25 applies PWM (unfiltered) to the bridge ...
Page 183
A Little More on Op-Amps In the op-amp configurations, the signal was applied to the non-inverting input. An input voltage produced the output with the configuration shown in Figure 5-26. The non-inverting input, and ...
Page 184
The gain formula for this configuration is − (−1)(V )( (−1)(2 V)(10 kΩ/10 kΩ − the input increases to 3 ...
Page 185
The gain equation is −V )( V−2 V)(100 kΩ/10 kΩ V)(10 special class of a differential amp ...
Page 186
The BASIC Stamp is simply energizing an LED in the SSR. The LED's light energizes a current switching device, a TRIAC, to control 240 VAC to the load. The SSR uses optical coupling and therefore complete electrical isolation between the ...
Page 187
CONCLUSION Controlling higher voltage or current output devices is often a necessity when interfacing real-world process control. The transistor (BJT or FET popular and inexpensive means of controlling DC devices. Using PWM, the power to a motor or ...
Page 188
Part B: 1. With the simulated delay of 2 seconds, the fan slows noticeably, or almost stops, before the RPM is measured. 2. The simulated delay should occur after measuring and plotting the speed, just prior to for best control ...
Page 189
Challenge 5-6 Solution To the declarations add: √ Opto_SW PIN Opto_Count VAR RPM VAR CyclesPerRev CON (Note: Adjust the value of used.) In the main add: √ DO...LOOP GOSUB ReadTach Add a subroutine: √ ReadTach: COUNT Opto_SW, 1000, Opto_Count RPM ...
Page 190
...
Page 191
Chapter 6: Open Loop Continuous Process Control Continuous process control involves maintaining desired process conditions. Heating or cooling objects to a certain temperature, rolling a thickness of aluminum foil, or setting a flow rate of material into a vat in ...
Page 192
Which is better? Arguably, some people prefer air conditioning to a fan, but others do not. If the objective is to maintain a comfortable sleeping temperature, they both have their advantages. In terms of industrial control, the lower cost and ...
Page 193
Parts Required (1) ADC0831 (1) LM34 Temperature Sensor (2) 220 Ω Resistors (1) LED Figure 6-1 The LM34 Temperature Sensor Figure 6-2 Monitoring the LM34 Temperature Sensor Schematic ...
Page 194
Construct the circuit in Figure 6-2. √ Run the BASIC Stamp program DataMonitoring.bs2 from Chapter 3, page 46. √ Open StampPlot macro sic_pc_data_monitoring.spm (also from Chapter 3). √ Adjust the analog (Y-axis) scale to 2.50. √ Increase the time (X-axis) ...
Page 195
Just as the RC network required 5 time constants (5 τ) to fully discharge, the LM34 requires 5 τ to fully cool. Based on the curve, ...
Page 196
ACTIVITY #2: SIGNAL CONDITIONING The analog to digital converter resolves an analog value to a digital value. ADC0831, as configured, coverts an input voltage volts to an 8-bit value (byte 255, respectively, as ...
Page 197
Where m is the slope of the line, and b is the y-intercept (where the line crosses the Y- axis), which this case. The slope the change in y for a given change in x. ...
Page 198
V/°F) for the change in input value 255. Temp = m(Bit Value ...
Page 199
GOSUB PlotPoint PAUSE 100 LOOP ' -----[ Subroutines ]----------------------------------------------------- ReadSP: DEBUG CR,"!READ [(txtADCoffset),*,10]",CR ' obtain offset volt. in tenths DEBUGIN DEC V_Offset PAUSE 50 DEBUG "!READ [(txtADCspan),*,10]",CR DEBUGIN DEC V_Span PAUSE 50 RETURN SetADC: PWM ADC_Vminus, V_Offset * 255/50,100 PWM ...
Page 200
Read down from the dot to determine the byte count read from the ADC. The √ display is not a “.vs time” plot the temperature doesn’t change much, you will only see a few dots. Pinch the LM34, ...