The chip and the pendulum


The setup

This is a nice little demonstration of a swinging pendulum. The set-up is extremely simple. The pendulum is fastened to the shaft of a linear potentiometer, which in turn is mounted on a suitable board. The potentiometer I used is a slide wire 5k job out of the junk box. Any other linear potentiometer should do the job just as well. The easier the movement of the shaft, the better.




The connectionThe potentiometer is connected to the analogue to digital converter input 1 of the Velleman K8055 board. The supply is derived from the internal 5V supply of the ADC which can be tapped from the little link pins just behind the input connectors. The voltage is connected to one end of the pot, the other is connected to 0V and the centre connection, supply the varying voltage, is connected to input A1.

The positioning of the output trace on the screen depends on the setting of the ADC potentiometer, behind the link. This should be adjusted so that the input voltage is 1V when the pendulum is stationary.


The program

The program asks you to press 'P' to start the ball rolling. When prompted simply set the pendulum in motion. This will call the procedure

PROCfind_zero  at line 850

which records the swing of the pendulum for 2 seconds, finds the highest and lowest value and from this the average, with is the zero line. This should make allowances for different settings of the  Velleman board ADC potentiometer as well as for all other variables and hopefully put the first trace at the top of the screen.

The next procedure called is

PROCgoing_north   at line 1070.

This waits for one swing to go negative and then waits for the zero line to be crossed before plotting begins. This routine is called at the beginning of every new line, thus making sure that the traces all start at the same point. This makes sure that they all line up rather nicely.

PROCswing  will then look after the rest of the business. You can press 'H' at any time to return to the menu so that a new trace can be started from scratch.

Here is an archive with both the program code and a stand-alone exec file.

K8055_chip-and-pendulum.zip


and here is the YouTube video of this project


And here are the same two files for the K8061

K8061_chip-and-pendulumnew.bbc

K8061_chip-and-pendulum.exe



   10 REM K8055_chip-and-pendulum
   20
   30 REM Demonstrate the mysteries of a pendulum
   40 REM Needs a functioning Velleman K8061 extended USB Experiment Interface board
   50 REM and a large tower if pendulum is longer than a few metres.
   60 REM Jochen Lueg
   70 REM http://roevalley.com
   80 REM Limavady, February 2012
   90 REM Issue 3.2
  100
  110
  120 ON ERROR PRINT REPORT$;"  ";ERL:END
  130 MODE 28
  140 COLOUR 128
  150 CLS
  160 COLOUR15
  170
  180 PROCK8055_init
  190 PROCinit
  200 SYS K8055_CloseDevice%
  210 SYS K8055_OpenDevice%,1
  220 PROCprint_menu
  230
  240 REPEAT
  250   Key$=INKEY$(0)
  260   IF Key$= "p" OR Key$= "P" PROCswing
  270 UNTIL Key$="q" OR Key$="Q"
  280
  290 SYS K8055_CloseDevice%
  300 SYS "FreeLibrary",K8055_Board%
  310 *QUIT
  320 END
  330
  340
  350 DEFPROCprint_menu
  360 VDU 4
  370 CLS
  380 PRINT
  390 PRINT " Please select one of the following"
  400 PRINT
  410 PRINT " Plot the movement of the pendulum  . . . . . . . .  P"
  420 PRINT
  430 PRINT " Quit this program  . . . . . . . . . . . . . . . .  Q"
  440 PRINT
  450 ENDPROC
  460
  470
  480 DEFPROCswing
  490 LOCAL A%,Key$
  500 PRINT " Please set pendulum swinging."
  510 PRINT " Press H to return to the main menu at any time"
  520 PRINT " It will take 3 seconds for the plotting to start."
  530 REPEAT
  540   SYS K8055_ReadAnalogChannel%,1 TO V1%
  550   TIME=0:REPEAT UNTIL TIME >20
  560   SYS K8055_ReadAnalogChannel%,1 TO V2%
  570 UNTIL V2%>V1%+4 OR V2%<V1%-4
  580 PROCfind_zero
  590 PROCgoing_north(10)
  600 VDU 5
  610 CLG
  620 MOVE 0,1900
  630 FORI%=5 TO 6
  640   GCOL I%
  650   FOR Y%= 1900 TO 600 STEP -250
  660     PROCgoing_north(2)
  670     REM Start plotting
  680     FOR X%= 0 TO 2879
  690       SYS K8055_ReadAnalogChannel%,1 TO V%
  700       PLOT 5,X%,Y%+(V%-ZeroPoint%)*6
  710       Key$=INKEY$(0):IF Key$= "h" OR Key$= "H" PROCprint_menu:ENDPROC
  720     NEXT
  730     MOVE 0,Y%-200
  740   NEXT
  750 NEXT
  760 GCOL 15
  770 MOVE 20,2200
  780 PRINT " Press any key to return to the main menu"
  790 A%=GET
  800 REPEAT UNTIL INKEY(0)=-1
  810 PROCprint_menu
  820 ENDPROC
  830
  840
 


  850 DEFPROCfind_zero
  860 LOCAL High%,Low%
  870 High%=0
  880 Low%=10000
  890 REPEAT
  900   SYS K8055_ReadAnalogChannel%,1 TO V1%
  910   TIME=0: REPEAT UNTIL TIME>10
  920   SYS K8055_ReadAnalogChannel%,1 TO V2%
  930 UNTIL V2% > V1%
  940 TIME=0
  950 REPEAT
  960   SYS K8055_ReadAnalogChannel%,1 TO V%
  970   IF V%>High% THEN High%=V%
  980 UNTIL TIME>100
  990 REPEAT
 1000   SYS K8055_ReadAnalogChannel%,1 TO V%
 1010   IF V%<Low% THEN Low%=V%
 1020 UNTIL TIME>200
 1030 ZeroPoint%=(Low%+High%)/2
 1040 ENDPROC
 1050
 1060
 1070 DEFPROCgoing_north(l%)
 1080 REPEAT
 1090   Key$=INKEY$(0)
 1100   SYS K8055_ReadAnalogChannel%,1 TO V%
 1110 UNTIL V%<ZeroPoint%-l% OR Key$="h" OR Key$="H"
 1120 REPEAT
 1130   Key$=INKEY$(0)
 1140   SYS K8055_ReadAnalogChannel%,1 TO V%
 1150 UNTIL V%>=ZeroPoint%+l%  OR Key$="h" OR Key$="H"
 1160 ENDPROC
 1170
 1180
 1190 DEFPROCinit
 1200 Mode%=MODE
 1210 Offset%=0
 1220 ZeroPoint%=100
 1230 ENDPROC
 1240
 1250
 1260
 1270 DEFPROCK8055_init
 1280 REM  Typing errors in routine name do not generate an error message - they just hang up the program.
 1290 REM These are all the system calls in the order found in the manual
 1300 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
 1310 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
 1320 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
 1330 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
 1340 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
 1350 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
 1360 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
 1370 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
 1380 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
 1390 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
 1400 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog"  TO K8055_SetAllAnalog%
 1410 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
 1420 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
 1430 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
 1440 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
 1450 SYS"GetProcAddress",K8055_Board%,"SetAllDigital"  TO K8055_SetAllDigital%
 1460 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
 1470 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital"  TO K8055_ReadAllDigital%
 1480 SYS"GetProcAddress",K8055_Board%,"ResetCounter"  TO K8055_ResetCounter%
 1490 SYS"GetProcAddress",K8055_Board%,"ReadCounter"  TO K8055_ReadCounter%
 1500 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime"  TO K8055_SetCounterDebounceTime%
 1510 ENDPROC



Return to the interfacing index

Back to the Limavady home page

Tudor with sign