Activity Programming The Half Wave Rectifier

Once again, we will be building upon our previous program. These additions let us read and compare the voltages generated by the two solar arrays. Remember, if you don't want to modify and update your program as shown here, you may download all of the source code for this text from

V In the BASIC Stamp Editor, open DuelingSolarCells.bs2.

V Rename and save the program as Half-FullWaveRectifier.bs2.

V Update the title to read as follows:

Experiments with Renewable Energy v1.0 - Half-FullWaveRectifier.bs2 Takes AC voltage from wind-powered alternator and rectifies it to DC.

V Add the following code to the bottom of the Declarations section.

----- For Experiment 4: Half and Full Wave Rectification ----------------

sampleCount VAR waitCount 'Nib ' Number of A/D samples per period sampleArray VAR Byte(10) ' 10-element array for A/D samples

V Next, in the Main routine, add an apostrophe in front of the first three GOSUB commands as shown below, "commenting out" the previous experiments which would conflict with the Half and Full Wave Rectification experiment.

Main Routine

Main: DO

' GOSUB Exp_1 ' Programmable Battery Charger

' GOSUB Exp_2 ' Dueling Solar Cells

' GOSUB Exp_3 ' Solar Cell Sun Tracker

GOSUB Exp_4 ' Half&Full Wave Rectification

GOSUB Exp_5 ' Three-Phase AC Alternator

GOSUB Plot_It ' Plot Data w/ StampPlot Pro


V Then document the Exp_4 subroutine as shown:

Experiment 4: Half and Full Wave Rectification

Set the A/D conterter to convert only on ch3

If sampleCount is not equal to 10 Then plot existing samples Else prepare to plot new samples

To plot new samples first wait for the rectified wave to equal zero Once zero, wait for the beginning of the first peak Then take ten (10) samples as rapidly as possible Zero sampleCount to begin plotting next

Plot each sample in the order taken using Plot_It Increment sampleCount and


V Then fill in the code between the Exp_4 and Exp_4_End labels as shown:

a2dMuxId = A2dMuxId3 ' Set the A/D to convert Channel 3


Exp_4_Wait_For_Zero: GOSUB A2D

GOTO Exp_4_Wait_For_First_Peak ENDIF

sampleCount = sampleCount + 1 IF (sampleCount = 10) THEN

GOTO Exp_4_Take_Samples ENDIF

GOTO Exp_4_Wait_For_Zero

Loop until the rectified wave is zero

If the rectified wave stays above zero for 10 counts, assume that a smoothing capacitor is attached

Exp_4_Wait_For_First_Peak: ' Loop until the first peak is detected


IF (a2dResult > 5) THEN Exp_4_Take_Samples GOTO Exp_4_Wait_For_First_Peak


FOR sampleCount = 0 TO 9 ' As rapidly as possible take 10

GOSUB A2D ' A/D samples and save them in the sampleArray(sampleCount) = a2dResult ' sampleArray NEXT

sampleCount = 0 ' Re-initialize sampleCount

' for plotting


ch3 = sampleArray(sampleCount) sampleCount = sampleCount + 1

Get the next A/D sample into CH3 and increment sampleCount

Exp_4_End: RETURN

V Save your work!

Solar Power

Solar Power

Start Saving On Your Electricity Bills Using The Power of the Sun And Other Natural Resources!

Get My Free Ebook

Post a comment