Thursday, 5 May 2011

Electronics - Voltage (Potential) Divider

Today we looked at how we can use two resistors in series to change a signal voltage.

We know from previous lessons that the voltage in a series circuit is shared between the components.  We can use a special type of series circuit to get a specific voltage.

For example if both resistors are of the same value then the voltage will be shared equally between them:

If one resistor is twice as big as the other, twice as much voltage will be dropped over it:



Remember that the whole supply voltage must be used in the circuit, there is none left over at the end!

We can work out the proportion of the voltage dropped over the bottom resistor using the equation:

              R2      
V2 = R1 + R2      x Vcc   (V2 might also be called Vo for Voltage Out of the voltage divider)
             20     
      = 10 + 20      x 12
         2
      = 3     x 12
      = 8v

In voltage dividers we are interested in the voltage dropped over the bottom resistor.  We can use this voltage as a signal to another part of the circuit.  However it is possible to use the equation to work out the voltage dropped over the top resistor by changing the equation so that instead of R2 on the top, it is R1

The application of voltage dividers is most useful when using input transducers like a thermistor, which changes resistance based on temperature, and a LDR, which changes resistance as the light level changes.  This change in resistance will result in a change of voltage.

Thermistors
First of all we will look at thermistors.  The resistance of a thermistor changes with temperature.  They are negative temperature coefficient (NTC) which means that the resistance will do the opposite of the temperature - i.e. as the temperature increases the resistance will decrease and as the temperature decreases the resistance will increase.

Consider these circuits:


The thermistor is the bottom resistor in a voltage divider.  As the temperature decreases, the resistance of the thermistor will increase.  Therefore the share of the supply voltage dropped over the thermistor will increase (remember the more resistance there is, the more voltage is required) and so the output voltage will increase.  This makes this circuit a cold sensor.

The thermistor is now at the top of the voltage divider.  The properties of the thermistor remain the same (temperature up > resistance down) but because it is now at the top of the voltage divider, the circuit will act as a heat sensor.  As the temperature increases the resistance of the thermistor decreases.  Therefore the share of the voltage dropped over the thermistor will decrease and so the share of the voltage dropped over the fixed resistor must increase and so the output voltage will increase as the temperature increases.

There are different types of thermistor with various temperature ranges.  They are all found on this graph:

This is a "log graph" as in reality the properties of the thermistor will form a curve and not a straight line which is very difficult to read.  So instead this type of graph is used and the axis need to be interpreted.  The temperature axis acts as you would expect and the only difference is the spacing.  The resistance axis, however, is more difficult and this is the bit people get stuck with.  Reading up from the bottom the units read > 10, 20, 30 etc then 100, 200, 300 etc, then 1000, 2000, 3000 etc. 

It is also important to note that the values nearer the top are closer together than those at the bottom.  So a half way point is not half way between the two values, but closer to 1/3 of the value.  i.e. between 1k and 2k, half way would be 1.3k.

To find a value, read along the axis of the value you know (you could be given either the temperature and asked to find the resistance, or the resistance and be asked to find the temperature)  This graph shows that at 25°c the resistance of a type 4 resistor is 50kΩ.
 LDR - Light Dependent Resistor
The light dependent resistor will change resistance as the light level changes.  As the light level increases, the resistance decreases and as the light level decreases, the resistance increases.  LDRs can be used in the same way as thermistors in a voltage divider circuit.

Consider these circuits:

This is a dark sensor - as the light level decreases the resistance of the LDR increases and therefore the voltage dropped over the LDR increases and the voltage out of the voltage divider increases.

This is a light sensor - as the light level increases the resistance of the LDR decreases and therefore the voltage dropped over the LDR decreases so the voltage over the fixed resistor increases and the voltage out of the voltage divider increases.

Just like thermistors there is a graph to show the change of resistance with the change in light level.  This is another log graph so you need to be aware of the axis.  We only need to look at one type of LDR, the ORP12.  You need to be aware that in this graph, the resistance is measured in KΩ.


This graph shows how to read the graph - at a light level of 200 lux the resistance is 600Ω.

It may be necessary to adjust the sensitivity of the circuit, i.e. change the "trigger" temperature or light level.  In this example a signal voltage of 5v is required.  First of all we can use the variable resistor to achieve this voltage at a temperature of 0°c.

We can adjust the temperature which produces that 5v signal voltage to 20°c by changing the resistance of the variable resistor.

Wednesday, 4 May 2011

Electronics - Parallel Circuits

Parallel circuits have more than one path for the current to flow along, they are set up in "branches".  Each branch receives the supply voltage and the current is shared.  In a series circuit if one component fails then the circuit is broken and current can't flow.  In a parallel circuit if one component fails the others can still operate as they are in a different branch.


Resistors can only come in certain values and so it may be necessary to connect them in series or parallel to create a different total resistance.

Resistors in parallel use the equation:
                1
Rt = R1 + R2 + R3 . . .  (this is absolutely not the same as Rt = R1 + R2 + R3!)

This is known as the reciprocal.  You don't need to understand the maths, but it helps if you do.  The reciprocal is the inverse of a number.  You may find this website useful.


Consider this circuit:

We need to find the total or equivalent resistance of the pair of resistors.

Because there are only two resistors it is possible to use the special equation: 



WARNING!  If you plug these numbers straight into your calculator, it will follow BODMAS and so do everything else and then add R2 at the end.  Therefore you must either do the two sums separately and then divide, or use the brackets function on your calculator.


 Current in a parallel circuit is shared between the branches.  Kirchoff's current law states:

The current entering a node (join) equals the current exiting a node.  We use this to show that when the current splits at the node the total current = the sum of the currents in all the branches of a parallel circuit.



So we can find out both the total circuit current and the current in each of the branches:

      
IT = RT
         12
     = 825
     = 14.5mA

        V                                  V
I1 = R1                                      I2 = R2
         12                                 12
     = 1100                         = 3300
     = 10.9mA                    = 3.63mA


Check:  IT = I1 + I2
                  = 10.9 x 10-3 + 3.63 x 10-3
                       = 14.5mA                               So our calculations are correct!


Electronics - Ohm's Law

We looked at calculations for series circuits using both Kirchoff and Ohm's Laws.

Consider the circuit below.




First we can find the total circuit resistance. Because the resistors are end to end in a series circuit, to find the total resistance is the sum of all the resistances:

Rt = R1 + R2 + R3
    = 2300 + 7500 + 500
    = 10300 Ω
    = 10.3 KΩ

Now that we know both the total resistance of the circuit and the supply voltage we can work out the current flowing in the circuit using ohm's law.

      V
I = R
      24
   = 10300
   = 2.3mA

Because this is a series circuit the current will be the same through each resistor, so now we know the resistance and current of each resistor we can use ohm's law to calculate the voltage dropped over each resistor.

V1 = IR1
     = 2.3 x 10-3 x 2300
     = 5.29v

V2 = IR2
     = 2.3 x 10-3 x 7500
     = 17.25v

V3 = IR3
      = 2.3 x 10-3 x 500
      = 1.5v

We can then check our answer using Kirchoff's Voltage law (all voltages dropped in a circuit must equal the supply)

Vt = V1 + V2 + V3
    = 5.29 + 17.25 + 1.5
    = 24v                                  So our calculations are correct! :)

You can use a variants of this method to find out missing information from circuits.  You may find it useful to write down all the information that you do know at the side of your paper so that it is more obvious where the gaps are and therefore which calculations you need to do.

Wednesday, 20 April 2011

Revision - Mechanisms

Types of motion
  • Linear - movement in a straight line - i.e. a train
  • Rotational - movement in a circle - i.e. the wheels of the train
  • Reciprocating - back and forth movement in a straight line - i.e. a pneumatic drill
  • Oscillating - back and forth movement along an arc - i.e. a pendulum
Levers
Levers use distance to magnify force. The further away from the pivot the force is applied, the more it is magnified, therefore levers can be used to lift heavy loads with smaller forces.

So, in this example, the force we are trying to lift is 30N, it is magnified by 5 (5cm away from the pivot) the input force we need to put in is magnified by 15cm, therefore we have to apply an input force of 10N.

Pulleys

Pulleys are another mechanism used to magnify a force by a distance to make something easier to lift.  By increasing the distance of rope pulled through the mechanism less force can be used.  This only works with more than one pulley.

The mechanical advantage is a way of describing how much easier the load is to move with the pulley.  You can work out the mechanical advantage by using the equation:
                        load
             MA = Effort

The velocity ratio concerns the distances covered by both the load and the effort.  You can work out the velocity ratio by using the equation:
                       distance moved by load
            VR = distance moved by effort
You could also count the ropes (not including effort) to find the velocity ratio.

No mechanical system is 100% efficient due to friction in the moving parts, so you will need to put in more force in real life than in calculation to move the load.  The efficiency can be calculated using the equation:
                               Mechanical Advantage
          Efficiency =       Velocity Ratio

Rotary Mechanisms

All rotary mechanisms are used to increase or decrease speed, and/or change the rotation through different angels (most commonly 90)

You need to know about:
  • Spur Gears (Gear trains plus using an idler)
  • Chain and Sprocket
  • Belt and Pully
  • Worm and Wheel
  • Face Gears
  • Bevel Edge Gears

The velocity ratio of all rotary systems can be found using the generic equation:
                       the amount of input motion
            VR = the amount of output motion

However we can use simpler equations when we know the size/number of teeth on a gear.  This can apply to chain and sprocket, meashed gears, bevel edged gears and face gears.  If you want to find the Velocity Ratio of a belt and pulley, you can follow the same theory but you will have to use the diameter of the pulley as it will have no teeth.

A smaller gear will always turn faster, therefore is a small gear is driving a bigger gear you will get a speed reduction so you are looking for the Velocity Ratio to be a fraction.

So if gear A is the driver, and gear B is the driven, you can find the VR = A/B = 12/18 or simplified to 2/3.  So if gear A turned at 300 rev/min, gear B would turn at 2/3 of that speed = 200 rev/min.



If a larger gear is driving a smaller gear you will have an increase in speed and are therefore looking for a whole number as your velocity ratio.  So if gear B was the driver and gear A the driven the VR = B/A = 18/12 = 1.5.  So if gear B turned at 300 rev/min, gear A would turn at 1.5 x 300 = 450 rev/min.

When deciding between a chain and sprocket and a toothed belt you need to consider the function of the mechanism.  A chain and sprocket is very good for eliminating slip, but if something jams in the mechanism and a motor is being used as your input, the motor will be trying to turn but can't so will burn out, a belt would allow the motor to still turn as it would slip over the pulleys and so the motor is protected.  Something with manual input like a bike is very suited to a chain drive to ensure that every rotation of the pedals results in a turn of the wheel.

You can try to increase friction between the belt and the pulley by changing the type of belt to a V-belt or a toothed belt.

To make sure that the belt does not stretch so that it falls off the pulley, a tensioner or jockey wheel may have to be used.



Worm and Wheel
A worm and wheel is a special rotary system as it only allows rotation in one direction - i.e. the worm can only ever be the driver so acts as a brake.  The worm and wheel also produces a big reduction in speed as the worm only has one tooth.  So VR = 1/number of teeth on worm.




Bevel Edge Gears
Bevel edge gears often do not have a difference in size as their main purpose is to transmit the rotation through 90.



Face Gears
Face gears transmit rotation through 90 and can also have a velocity ratio by changing the size of the gears used.




Compound Gear Systems
Compound gear systems combine mechanisms to produce a greater velocity ratio.  This is done by adding two gears on the same axle.  As these must be turning at the same speed, there is no velocity ratio between them, but now the driver of the second "pair" is turning at the same speed as the driven of the first "pair."






The above picture and graph shows a motor turning at 120 rev/min.  There is a great reduction in speed with the worm and wheel - VR = 1/10 (the blue line shows the speed of the wheel) a further reduction with the first chain drive - VR = 10/20 (the green line) and a last reduction with the second chain drive - VR = 15/25 (the purple line).

So we can work out the total VR:

VR = 1/10 x 10/20 x 15/25
      = 0.03

The output speed will be the motor speed x VR so:

Output speed = 120 x 0.03
                      = 3.6 rev/min

If an idler mechanism was used, the effect of the speed reduction would be greatly reduced as the idler does not affect the velocity ratio, only the driven and the driver.

Rotary to Linear

The rack and pinion turns the rotary motion of the pinion into the linear motion of the rack.  You can do calculations based on the number of teeth per metre on the rack and the speed of the rack.



i.e. if the rack has 100 teeth per metre and the pinion has 10 teeth, it has to turn at 10 revolutions a second for the rack to move 1m/s.

Rotary to Reciprocating


Crank and Slider: A crank is motion off centre of a circle.  This could be a single member, or a wheel.  The off centre motion pushes the slider back and forth, thus creating reciprocating motion.



Cam and Follower: The raised section of a Cam pushes a follower up and the dewll makes it fall again.  There are many shapes of Cam, the most common of these being a pear shaped cam.

Click here for more information about cam and follower

Safety Mechanisms
Sometimes it is necessary to ensure rotation in one direction only.  As mentioned before, a worm and wheel could be used for this purpose.  Alternatively a Ratchet and Pawl could be used.  This works by shaping the teeth on the ratchet so that in one direction the pawl slides over them and in the other direction gets stuck, stopping the mechnism.

Revision - Logic

You need to remember each type of logic gate - its symbol and truth table.

You then need to be able to go between English descriptions, to complex truth tables, to Boolean expressions and circuits.  You could be given any of the previous and be asked to produce a different form.

Wednesday, 6 April 2011

Your Exam

On the 10th May you will sit your S3 exam.

You need to know about:

Mechanisms:
  • Different types of mechanisms
  • Velocity Ratios
  • Speed
  • Uses, Advantages and disadvantages of different types of mechanism
Logic:
  • AND, OR, NOT, NOR, NAND, XOR
  • Truth tables
  • Boolean expressions
  • Logic circuits
  • You need to be able to go between any of the above i.e. get a circuit from a Boolean expression or get a Boolean expression from a truth table.
Pneumatics:
  • Name valves
  • How to wire up different valves to control cylinders or produce air signals
  • Cylinder calculations - F = PA and how to find area or diameter.
Programmable Control:
  • Parts of a microprocessor
  • Flowcharts
  • PBASIC
Electronics Basics:
  • Series Circuits
  • Ohm's Law
Keep checking the blog in the second week of the holidays, more information will arrive when I am back from holiday!

Electronics

This week we have started to look at electronics.

An electrical circuit is a closed loop network of different components and a power supply.

The main properties of an electrical circuit are:

Current: the flow of electrons around a circuit.  It flows from positive to negative, or from a high point to a low point - like water.  Current is measured in Amps (A)

Voltage: the "push" - voltage drives the current around the circuit.  Voltage is measured in volts (V)

Resistance: a material's reluctance to allow current to flow.  All materials can conduct electricity, but they all have different resistance - those who let current flow easily - conductors - and those which make current flow difficult - insulators.  The more resistance a material has, the more voltage is required to make current flow.  Resistance is measured in Ohms (Ω) (Though sometimes people are lazy and write R instead of Ω)

First we looked at resistors as components.  Resistors are important to gain some control over the voltage and current in a circuit as some components are sensitive and too much current could destroy them.  The following picture explains how to read resistor colour code. 



This website can also be used to check, but in real life you may not have this luxury!

Remember your prefixes. You already use Kilo (k) and Milli (m) on a daily basis i.e. kg and mm.  So kilo is a thousand - 1000 or x103 and milli is a thousandth - 0.001 or x10-3.  To help you organise your numbers you may be able to find the engineering mode on your calculator which will put your number in the correct scientific notation to quickly convert to the correct prefix.  This table should help you make conversions.



The first type of circuit we looked at were series circuits - where component are connected end to end.  Be built a circuit with a resistor and an LED in series and measured the voltage over the resistor for different resistor values. 

To measure voltage we had to place one probe on one leg of the resistor and the other probe on the other leg.

We found that as the resistance increased, the voltage dropped over it increased.

We also found, through circuit simulation and using Kirchoff's law, that all the voltages dropped in the circuit must equal the supply voltage i.e. VR + VLED = VS

In this circuit the switch has no resistance as it is a very good conductor when closed.  You can see that the voltage over the resistor (4.1v) and the voltage over the LED (1.9V) equal the supply (6v)



We then used simulation software to measure the current in a series circuit.  The flow of current is the same throughout the loop and therefore current is the same at all points.  Also the larger the resistor, the less current can flow in the circuit.



The relationship between voltage, current and resistance is known as Ohm's law and can be described using the equation V = IR where V = voltage, I = Current and R = Resistance.

Other things that you should be aware of:


Types of Switch
Ohm's Law

Thursday, 31 March 2011

Class Projects

The deadline for handing in your 4 class projects is 05/05/11

This date is after the Easter holidays so I suggest that you do as much as possible before the holidays so that you can come back and ask me questions.  We will use the work you do here next year as one of your practical NABS.  The more work and effort you put into this now, the easier you will pass this unit.  It is also very imporant that you can problem solve following these steps so that you are properly prepared for any question in the exam.

I feel that some people are a little confused by what you need to include so hopefully this more thorough guide will help.  I am going to use question 14 from the homework as my example.

Project Brief:
This is the question that you are trying to answer.  You should copy it out so that I know which project you are doing and so that you can start thinking about it properly.

The layout of a new restaurant is quite spread out, with the kitchen quite far away from the restaurant.  Design a system which could transport food quickly along a track between the two rooms.

System Diagram:
This is to help you work out the inputs and outputs that you are going to need to solve your project brief.  Remember that if you use a motor, you may need to know where the output is i.e. a barrier lifting, or curtains closing, so you will need to add some sensors in.  As these feed information into the microprocessor, they are also inputs.

In my example the buggy needs to stop when it gets to each location so I need two sensors.  I also need another two buttons to "call" the buggy between rooms.



Flow Chart:
The flowchart is the planning stage to the program.  This is where you work out the sequence you want to test inputs and switch on/off outputs.  It should be completely in English, so use the terminology you have used in the system diagram, or words that explain what you are controlling easily.



Input/Output Table - Pin Diagram:
This is to decide which inputs and outputs you would like to connect to which pins.  Remember that if you would like to use input switches you have to use 0,1,2 or 3 as these are the connections on the STAMP board.  If you are using a motor which has to go both forwards and backwards, you need to use either pins 4&5 or 6&7.



PBASIC Program:
Now you have decided which pins you are going to use for which purpose, and you have decided on the sequence that you need to test inputs and switch on/off outputs in (flowchart).  You need to convert each box of your flowchart into the PBASIC command required.  You may find it useful to note in pencil next to each box of your flowchart the PBASIC command before writing the program completely.

init: let dirs = %11110000     'sets pins 7-4 as outputs

main: if pin1 = 0 then main   'waits for the restaurant call button to be pressed
rest:   high 6                           'switch on motor forwards
          if pin3 = 0 then rest     'wait until buggy reaches the restaurant
          low 6                            'switch off motor
kit:     if pin0 = 0 then kit       'waits for the kitchen call button to be pressed
to_kit: high 7                          'switch on motor backwards
          if pin2 = 0 then to_kit  'wait until buggy reaches the kitchen
          low 7                            'switch off motor
          goto main                     'loop back to start

You need to use white space comments (the text following the ' ) to explain what each line of the program means in English. In doing this you can also check back to your flowchart to make sure that your program follows the correct sequence.     

Monday, 28 March 2011

Blog Homework Answers

 Use these answers to check through your homework and make sure you understand.

You must show that you can take information either from the blog or your class notes to answer questions in your own words or by problem solving.




Thursday, 24 March 2011

Class Projects

Some tips in how to complete the class projects.  Remember that you must complete at least 4.

First of all work out the inputs and outputs you will need.  It may help you to draw a little picture (as I did in homework question 14)  From this you can draw the system diagram, remember:

Real life input > input > microprocessor > T.D. > output > real life output

Now you can clearly see which inputs you need to test, and the outputs you need to control and you can write the flowchart to plan your sequence.

Remember the boxes required for a flowchart.

From your flowchart you should be able to find the correct PBASIC command for each part of the flowchart, in sequence.

ASK ANY QUESTIONS IF YOU ARE STUCK AT ANY POINT!

Thursday, 17 March 2011

NEW feature! Reactions!

I have added some "reactions" to the blog.  This allows you to quickly comment on how much you understand something.  Please use this so that I can gauge how much people understand, and which areas I need to go over more. 

You don't have to comment, and it's anonymous so please give me this feedback so that I can tailor my teaching to help you.  If you would like me to go over something individually then leave a comment and I'll catch up with you :)

Homework Due 22/3/11

You must write the answers to the following questions on a sheet of paper and hand it in on Tuesday 22nd March.  (I know that you were all in class to hear this!)

  1. Which part of the microprocessor stores the program?
  2. What carries data from here to the ALU?
  3. What does EEPROM stand for and what is the advantage of using this type of ROM? 
  4. Convert these numbers into binary:
    1. 24
    2. 208
    3. 7
  5. Convert these numbers into decimal:
    1. %10101111
    2. %11100110
    3. %11001
  6. Draw the flowchart box you need to use to "call" a sub-procedure from the main flowchart.
  7. Write a couple of lines of program which would test a start switch. Nothing should happen until the start switch is pressed.
  8. Write the whitespace comment for this line of programming: let dirs = %11101100
  9. Write a program which will turn a stepper motor 360 clockwise then 360 anticlockwise.
  10. What is the output voltage from the microprocessor?  What is the voltage needed for a stepper motor?  What do you need to use to ensure that the stepper motor will work properly?
  11. Write a program to slow down the speed of a DC motor to half its speed.
  12. Draw a system diagram for a warning light which comes on when it is too cold.
  13. What type of output driver do you use to control the direction of a motor?  (not just "output driver" the type of output driver required)
  14. A restaurant's kitchen is far away from the restaurant so it uses a buggy system to transport food.  The buggy is on a track.  It starts in the kitchen and if the restaurant call button is pressed the buggy travels along the track until it hits the limit switch telling it that it is at the end of the track and it will stop.  The buggy stays there until the kitchen call button is pressed, it travels back along the track until it hits the limit switch again telling it that it has reached the end of the track and the buggy will stop.  Below is a sketch of this situation and the pin connections required.
    1. Draw a flowchart which will fulfill this brief
    2. Use your flowchart to write a program in PBASIC

Turning a Flowchart into a PBASIC Program

A flowchart is the planning stage for a program.  It is important to use the correct shaped box so that it is clear when you are controlling an output, or asking a question etc.  The flowchart is to help you understand the sequence so it is written in English.

The first flowchart is to practice asking about the condition of an input:


First you must choose which pins you are going to use as outputs and which as inputs.  Looking at the board you know that pin 7 is a red LED and 5 is a green LED. I'm going to use pin 0 as my switch.

So I need to tell the microprocessor this:

init: let dirs = %10100000     'Sets pin 7 and 5 as outputs
       symbol green = 5
       symbol red = 7

Now I can write my main program.  If I want to use English words, I must first of all tell the microprocessor this as well by setting the English words as symbols.  If you prefer not to do this, use the black commands, if you would like to do this, follow the purple programming language.

To ask a question I need to use an IF . . . THEN . . .  statement in relation to my input pin.  Then I need to tell the microprocessor which bit of program to go to when my input is on, and when it is not.  If the statement is not true, it will not go to the label which follows THEN but to the next line instead.

main: if pin0 = 1 then green_on       'Check the input pin, if it is on, go to the
                                                                    'green_on sub-procedure.
          goto red_on                            'If the input pin is off, go to the
                                                                    'red_on sub-procedure

red_on: high 7           high red          'Switch on the red LED
             low 5            low green        'Switch off the green LED
             goto main                             'Loop back to the start to test the input

green_on: high 5        high green      'Switch the green LED on
                 low 7         low red          'Switch the red LED off
                 goto main                        'Loop back to the start to test the input




The second flowchart incorporates testing an input and using a counter loop.  To repeat something a certain number of times, you must use a temporary memory file in the RAM to store the number of times the loop has been repeated.  Often we will use b0 for this purpose.  Again, if you want to call b0 something in English you must use the symbol command.

The PBASIC language required to repeat a sequence is a FOR . . . NEXT loop.  For must go at the top of the sequence and next at the bottom.  Anything you write in between FOR and NEXT will be repeated.

Motors, as described earlier in the blog, must be connected using the push-pull driver on the output driver.  7&6 control one motor, and 4&5 control another motor if you require it.  It is important to use the correct pairing to ensure that your motor will turn.

The program for this flowchart would therefore be:

init: let dirs = %11000000             'sets 7 and 6 as outputs
       symbol counter = b0

main: if pin0 = 0 then main     OR    main: if pin0 = 1 then motor   'both of these statements check
                                                                    goto main                       the input.
motor: for counter = 1 to 5           'Starts the loop to repeat 5 times
              high 7                              'motor clockwise on
              pause 10000                    'wait 10 seconds
              low 7                               'motor clockwise off
              high 6                              'motor anticlockwise on
              pause 10000                    'wait 10 seconds
              low 6                               'motor anticlockwise off
          next counter                        'If it has not been repeated 5 times, loop back to motor
          end



The third flowchart is in two parts.  This shows that the sequence uses a sub-procedure.  Where "alarm" is in the main flowchart, it means that the whole of the alarm flowchart fits into that box.  So from the main flowchart, the sequence goes to the start of alarm, and at the end of alarm it returns to the main program and follows the arrow back round to the start.

Here is the program:

init: let dirs = %10000000          'sets pin 7 as the output (buzzer)

main: if pin0 = 0 then alarm        'if the door is opened go to the sub-procedure alarm
          if pin1 = 0 then alarm        'if the window is opened go to the sub-procedure alarm
          if pin2 = 0 then alarm        'if the door mat is stepped on go to the sub-procedure alarm
          goto main                           'go back to the start and test the inputs again.

alarm: high 7                               'buzzer on
           pause 500                         'wait half a second
           low 7                                'buzzer off
           pause 500                         'wait half a second
           if pin3 = 0 then alarm      'test the reset switch, if it is not pressed then continue sounding the alarm
           return   /   goto main        'return to the main program.

Sunday, 13 March 2011

Stepper Motors

Stepper motors are motors which turn due electromagnetic coils pulling the axle round in a circle.  There is an amination of this on this website:

Stepper Motor

This is useful for two reasons: you can make the stepper motor turn to a particular position and it has a "holding torque" meaning that as long as two of the magnets are energised it can hold something in position.

To make the stepper motor turn you must use a particular pattern to make sure that the coils energise in a circle.  To make the stepper motor turn clockwise you type the pattern in as seen, to make it turn anticlockwise you simply use the same pattern but in reverse:

i.e. 

symbol delay = b0
let delay = 100

clock: let pins = %10100000
           pause delay
           let pins = %10010000
           pause delay
           let pins = %01010000
           pause delay
           let pins = %01100000
           pause delay
           goto clock

anti:    let pins = %01100000
           pause delay
           let pins = %01010000
           pause delay
           let pins = %10010000
           pause delay
           let pins = %10100000
           pause delay
           goto anti

Repeating like this will simply make the stepper motor turn continuously.   By using b0 as the delay, we can quickly change the speed of the stepper motor by changing the value of "delay"  The smaller the number the faster the motor will turn, but if you try to turn too quickly the magnets will not have time to pull the axle round so it may not turn at all.

To make the motor turn to a specific position, we must use a FOR . . . NEXT . . . loop.  This will allow us to repeat the pattern a set number of times.  Each line of the program is 7.5 degrees, so each 4 line pattern is 30 degrees.  Therefore to turn one complete revolution we must repeat the pattern 12 times.

i.e.

symbol counter = b0
symbol delay = b1
let delay = 100

clock: for counter = 1 to 12
                  let pins = %10100000
                  pause delay
                  let pins = %10010000
                  pause delay
                  let pins = %01010000
                  pause delay
                  let pins = %01100000
                  pause delay
            next counter


The stepper motor requires a 12v supply and the microprocessor can only supply a 5v signal.  Therefore we must use an external power supply (a black box) to connect to our output driver.

Friday, 11 March 2011

Using Inputs

The next thing we need to learn about is how to use inputs in microprocessor control.

In real life there are a variety of different inputs we could test - switches, temperature sensors, light sensors, strain gauges (to measure how much something has been bent) etc.  In class we are going to start by using simple switches:






Using the connections given we can only use pins 0-3 without adding any extra wiring.

Now that we are dealing with both inputs and outputs we have to make sure we set up the DDR (Data Direction Register) correctly:

init: let dirs = %11110000     'Sets pins 7, 6, 5, 4 as outputs, and 3, 2, 1, 0 as inputs

To "test" an input, we must ask about its state, i.e. whether it is on or off.  In a flowchart we must do this using a rhombus box.  Each question must be YES/NO.

Here is a flowchart using inputs, for a toy train which should travel along the track until it reaches the end.  This system uses a start switch (pin 0) and an "end switch" (pin 1) as its inputs and a motor (pin 7) to drive the train.


This can be turned into a PBASIC program using "IF . . . THEN . . . "

init: let dirs = %11000000     'Sets pins 7 and 6 as outputs, and 5, 4, 3, 2, 1, 0 as inputs

main: if pin0 = 1 then train    'tests the start switch
          goto main                     'if the start switch is not pressed, go back to main

train: high 7                            'switches on the motor
         if pin1 = 0 then train     'tests to check if the motor has reached the end of the track
         low 7                             'switches off the motor.
      
         end

If the IF . . . THEN . . . statement is true, it will go to the label stated.  (following the then MUST be a label - another part of the program to go to).  If the statement is not true, it will skip to the next line of the program.  You can ask if the pin is '1' or '0' depending on what your flowchart says.

Tuesday, 8 March 2011

Today's Mini Test

Here are today's mini test answers:


1. What shape of box would you use to control an output in a flowchart?
 
 
2. What does the % sign mean? That the following number is in binary
3.a) Label the most significant bit: 10101010 (MSB is in red)
  b) Which pin number is this? 7
4. a) What method of speed control do you have to use with a microprocessor? PWM - Pulse Width Modulation
    b) Draw a graph to show a fast speed labeling the mark and space See the green graph below.
    c) How would you alter this to make the motor turn slowly? Increase the space so that the mark to space ratio changes.  The bigger the space the slower the motor will turn.
5. What is the value, in volts, of a "high" signal? 5V
6. What is b0? A memory file in the RAM where information can be stored whilst the program runs i.e. how many times a sequence has been repeated.
7. What is the name for the wires connecting the ROM to the ALU? The Program Bus
8. What connects the microcontroller to the "real world"? The I/O Port Input Output port
9. What unit of time does the microprocessor count in? Milliseconds (ms)
10. Draw a system diagram for a street lamp which will come on automatically at night.




(I would accept "dark" as the real life input and "dark sensor" for the input transducer.)

You must show all the parts of the system in separate boxes with a system boundary around them, then real life inputs/outputs are not in boxes and outwith the system boundary.

Please leave a comment stating what part of today's test you found most difficult so that I can target my feedback to suit.

Thursday, 3 March 2011

Pneumatics Test

We recently sat the class test in Pneumatics. The answers are now deleted, I hope you found them useful.




Wednesday, 2 March 2011

Speed Control - Pulse Width Modulation

Because the microprocessor gives a digital signal out - either 5v or 0v and nothing in between, we must use Pulse Width Modulation (PWM) to control the speed of a D.C. motor.

This uses the Mark to Space ratio to vary the speed - that is the time a motor is on for (Mark) and the time the motor is off for (Space).  This is in order of milliseconds so that it happens so quickly you can't see the pulse, only a constant speed.



Examples of the programs required for these graphs:

green: high 7                                             blue: high 7
           pause 20                                                  pause 10
           low 7                                                        high 7
           pause 10                                                  pause 20
           goto green                                               goto blue

Because the motor is on longer than it is off in the green graph, this is the program which will make the motor turn faster.  You can increase the mark to space ratio to get a bigger difference in speed.

Using the Microprocessor

First we looked at the architecture of a microprocessor:

ALU: Arithmetic Logic Unit: The "brain" of the microprocessor, reads the program and carries out the mathematical calculations necessary.
ROM: Read Only Memory - where the program is stored.  The type of ROM we are using is Electronically Erasable Programmable Read Only Memory, which means that to reprogram the microprocessor, all we have to do is connect is back to the computer and write over the old program with a new one.  Other chips may be once use only, meaning that if you make a mistake, or need to change a part of your program, you need to get a brand new chip.
RAM: Random Access Memory.  This is memory the microprocessor uses whilst the program is running.  The parts of the RAM are called b0 - b13.  You can ask it to remember any number, add and subtract, or count how many times a part of the program has been repeated.
Clock / Program Counter / Timers: Controls the speed of the mathematical calculations
I/O Ports: Connect the microprocessor to the real world so that we can control outputs and test inputs
Buses: Groups of wires which transport information from one part of the microcontroller to another.

Then we looked at the "Stamp Controller" we will be using for our programming.



To be able to use outputs with the Stamp Controller, we needed to add an output driver to boost the current from the microprocessor enough to drive output transducers like buzzers, motors and lamps.






There are two types of output driver.  The Darlington Pair at the top, which is used to drive anything which requires on/off control - lamps, buzzers; and the Push Pull driver at the bottom which is used to drive motors so that they can turn in both directions.  This means that a buzzer needs to be connected to one output pin, and a motor to two output pins - one to make it go forwards and one to make it go backwards.