Beeb Body Building Course Part 64 The Experimenter's Board Part 5 A Shifty Character The Body Build Experimenter's Board was first described in the August 88 Micro User and enables you to learn about interfacing in a relatively painless way. It contains many components which can be interlinked to enable a wide variety of experiments to be performed. Last month we looked at how to handle inputs commands to the Body Build Experimenter's Board, well this month we will take a look at some of the hidden goodies in the VIA, namely the shift register. Normally the BBC's VIA is used simply as an input or output port but there are hidden extras as well. The shift register is perhaps the most neglected part, but it can be most useful. Basically a shift register is rather like a conveyor belt, the bits (zeros and ones) are loaded onto the belt at one end and fall off at the other, one at a time, in the same order. The conveyor belt is a register within the VIA (at address &FE0A) and the "end" is control line 2 on the VIAs' B side (CB2). The shift register can be made to work in the other direction as well. So that whatever logic level is near the end of the belt is sucked back onto the conveyor belt. It is called a shift register because each time a bit is moved in or out all the other bits "shift over". In deepest Lancashire this is known as an "utch up" register. To be technical for a moment, this movement of bit patterns when you are outputting bits one at a time, is known as a parallel to serial conversion . Conversly, when you are collecting or inputting data, it is known as serial to parallel conversion. The only snag is that the shift register can only be used for one type of conversion at any one time. Which means you can't perform a serial to parallel conversion while simultaneously performing a parallel to serial conversion. As well as deciding which way you want the data to flow you also have to decide what will control the time when the data will be moved. Here you are faced with a choice of three different controlling signals or clocks. You can shift the data when you feed a signal into control line 1 (CB1), this happens on the falling edge of the clock signal. In this way you can control the flow of your bit pattern or data from outside the computer. The two other sources of clock signals are derived from within the computer. You can use the systems clock of 1MHz, to get the fastest possible output or you can use a counter to move data after a pre-set number of 1MHz system clock pulses. Normally when you shift all the data out of the shift register it is empty and will stop shifting until you load in some more data by storing it in address &FE0A, but there is an other option. You can have all the data repeatedly appear on the output. That is, when 8 shifts have been performed, the whole operation is automatically repeated. This is known as a recirculating or free running mode. Those of you who are good at working out combinations will have spotted seven different ways the shift register can work. In fact there are 8 diffrent modes, the 8th being disabled or not working. If you look at Table 1 you will see all the different modes. In order to instruct the VIA which mode to use, the mode number is stored in the Auxiliary Control register at address &FE6B. To make matters a little more complicated the mode number has to be stored in bits 2, 3 and 4 which means you have to shift the mode number two places to the right (or multiply by 4) before storing it in the Auxiliary Control register. Also, other bits in this register control other aspects of the VIA so we should make sure we only change the bits we want to. This is done with logic operators in the same way as we did when we looked at outputs in the October 88 issue. Well enough of the theory let's do an experiment to reinforce the idea of shift registers. So that we can see what is happening let's use the shift register modes that work on an external input and to provide the input we will use the slotted opto switch. This has built in hysteresis circuitry so that we will not suffer with contact bounce producing multiple pulses which might be the case if we used a conventional switch or wire shorting loop. To set up our board we need to move Link 2 to position B. This connects the output of the opto switch to the PB6 screw connector. Now wire a link between PB6 and CB1 and finally move Link 3 to position A so the LED shows the output of the shift register. First let's look at outputting a bit pattern, to do this we need to set the shift register into mode 7. There is no need to run a program - to do this we can type in the commands directly from the keyboard. In basic :- ?&FE6B=7*4 In FORTH:- HEX FE6B 1C C! Note that in the basic version I have got the language to work out the bit pattern. This just makes things a little easier to follow, I could have simply used the bit pattern I wanted as I have in the FORTH version. Also there is nothing stopping you from working it out in FORTH. Now we need to put some bit pattern into the shift register, the number &CC is useful because in binary it is 11001100. This means that our LED will change state every two clock pulses. Load up the shift register by typing:- In basic:- ?&FE6A=&CC In FORTH:- FE6A CC C! Now, move out the bit pattern by lowering a piece of paper in and out of the opto slot. You should see the LED changing every two times and after 8 clock pulses the shift register will stop and the LED will remain off. Try putting different numbers in the shift register. Can you predict the sequence? Also see which direction the shift register travels, which is the first bit out. You might notice a click associated with each change in the LED, this is because the LED drive is also connected to the audio amplifier. We can monitor the contents of the shift register if we display its contents on the LED bar display. To do this we need a simple loop that continually reads the shift register and transfers it to the LEDs at address &FE61. In basic:- 10 REPEAT: ?&FE61=?&FE6A: UNTIL FALSE In FORTH:- : MON BEGIN FE6A C£ FE61 C! ; MON !! (Note to EDITOR in above replace £ with the "at" symbol) !! Note that in fact the value in the shift register recirculates and does not stop after eight shifts. Try loading the number 1 into the shift register and watch it run round. It recirculates because each time we read the shift register we reset the number of shifts needed to complete the transfer. Now, let's have a look at using the shift register to gather inputs. First we need to set the shift register into mode 3 by typing:- In basic :- ?&FE6B=3*4 In FORTH:- HEX FE6B C C! Then, so that we can see what is going into the register, we need the same program we just had to continuously monitor the contents of the shift register. Then take a wire and connect one end to CB2. This is the data input, touch it on the E connector for a logic zero or leave it unconnected and it will float high giving a logic one. Note the LED will indicate the logic state you are about to put into the shift register. Now trip the opto switch and watch the shift register fill up. Try to input a specific bit pattern such as alternating zeros and ones. While we have a program running it only gives us a window on the shift register, the accumalation or outputting of the bit pattern happens without any intervention from the computer. This is important because we need not take up computer time performing a serial to parallel conversion, it can be left free to do other tasks. There are many practical applications of shift registers such as serial communications between computers, data gathering and generating special pulse trains. Next month we will see how the shift register ties in with the other hidden part of the VIA, the timers. In the meantime if you have been paying attention to what we have been doing then I will give you a little test. Write a program to simulate the shift register in the input mode, use PB0 as the data input and PB1 as the clock, displaying the register on the bar display. Answers in FORTH and basic next month, see you then and have a merry Christmas. Mode Direction Clock 0 Disabled 1 Into register Timer T2 2 Into register 1MHz clock 3 Into register External on CB1 4 Out of register Timer T2 recirculating 5 Out of register Timer T2 6 Out of register 1MHz clock 7 Out of register External on CB1