Activity Programming The Threephase Ac Alternator

As usual, we will be adding to our previous program, and commenting out the routines not currently needed. (Alternatively, you can download the source code from www.parallax.com)

V In the BASIC Stamp Editor, open Half-FullWaveRectifier.bs2

V Rename and save as AlternatorPhase1.bs2.

V Update the title section as follows:

' Experiments with Renewable Energy v1.0 - AlternatorPhase1.bs2 ' Generate 3-Phase power from wind-powered alternator, then plot ' only Phase 1. ' {$STAMP BS2} ' {$PBASIC 2.5}

Now add this to the Declarations section

' -----For Experiment 5: Three-Phase AC Alternator -----------------------

Plotting CON 1 ' Program is plotting

Sampling CON 0 ' Program is taking samples eepromAddr VAR dataPtr 'Word ' EEPROM address pointer eepromAddr = $0000 ' Initial eepromAddr value plotCount VAR codePtr 'Nib ' Number plotted so far mode VAR Bit ' Plot mode or sample mode mode = Sampling ' Initially will be sampling

In the Main Routine section, comment out the first 4 gosub commands, like this:

Main Routine

Main: DO

' GOSUB Exp_1 ' GOSUB Exp_2 ' GOSUB Exp_3 ' GOSUB Exp_4 GOSUB Exp_5 GOSUB Plot_It LOOP

' Programmable Battery Charger ' Dueling Solar Cells ' Solar Cell Sun Tracker ' Half&Full Wave Rectification Three-Phase AC Alternator Plot Data w/ StampPlot Pro

In the Experiment 5 section, add the explanatory comments and program code

Experiment 5: Three-Phase AC Alternator

Enter from power-on or reset with eepromAddr = $000, mode = Sampling, and plotCount = 0

This routine will be called once each time through Main, and right after this routine, Plot_It will be called.

If mode = Sampling, then take a set of 40 samples from all 4 A/D converter inputs. 10 samples per channel.

If mode = Plotting, then retrieve one set of 4 samples from EEPROM. Jump out of Exp_5... the one set will get plotted when Plot_It is called. This will happen 10 times to get all 10 sets of 4 samples plotted.

Sampling:

For each of the three phases and the rectified output, take samples as follows:

- Increment the eepromAddr to the next sub-block (except for phase 3)

- Set the A/D converter to sample phase 3

- Sync up to the positive peak of phase 3 (except for phase 3, itself)

- Switch the A/D to sample the next phase or the rectified output

(again, except for phase 3)

- Gather 10 samples of the converted values in sampleArray (RAM)

- Transfer the 10 samples from sampleArray to EEPROM

Plotting:

For each of the three phases and the rectified output, plot samples as follows:

- Increment plotCount for the next time around

- Read each sample from EEPROM into the appropriate variable (ch3, ch2, ch2, ch0)

- Exit the program and let the Plot_It routine graph the four samples

- When we've plotted all the samples, increment the eepromAddr to the next sub-block, change mode to Sample the next time through, and reset plotCount to zero

Note: If the eepromAddr is greater than address $0300, reset it to zero -we don't want to clobber the program memory

SELECT mode

CASE Plotting plotCount = plotCount + 1 GOSUB Exp_5_Retrieve_For_Plotting IF (plotCount = 9) THEN mode = Sampling plotCount = 0

GOSUB Exp_5_Inc_EepromAddr ENDIF CASE Sampling

GOSUB Exp_5_Sample_Phase_3 GOSUB Exp_5_Sample_Phase_2 GOSUB Exp_5_Sample_Phase_1 GOSUB Exp_5_Sample_Rectified_Output GOSUB Exp_5_Retrieve_For_Plotting mode = Plotting ENDSELECT

Exp_5_End: RETURN

Subroutines for Experiment 5

Exp_5_Sample_Phase_3:

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

Will plot 10 sets of data numbered 0..9

Get 1 set of data to plot

Done plotting, switch state

Reset plotCount

Inc. addr to next bank

Take 10 samples each of Phases 3, 2, 1, Rectified Out

Queue up 1st set of samples Change state back to plotting

GOSUB Exp_5_Wait_For_Zero GOSUB Exp_5_Wait_For_Next_Peak GOSUB Exp_5_Take_Samples GOSUB Exp_5_Write_Samples

Exp_5_Sample_Phase_3_End: RETURN

Loop until the wave is zero Wait for wave to begin to peak Take samples of phase 3 Write samples to EEPROM

Exp_5_Sample_Phase_2:

GOSUB Exp_5_Inc_EepromAddr a2dMuxId = A2dMuxId3

GOSUB Exp_5_Wait_For_Zero GOSUB Exp_5_Wait_For_Next_Peak a2dMuxId = A2dMuxId2

' Increment pointer to EEPROM ' Set the A/D to convert Channel 3 ' sync up to phase 3 ' Loop until the wave is zero ' Wait for wave to begin to peak

Switch the A/D to convert Channel 2

GOSUB Exp_5_Take_Samples GOSUB Exp_5_Write_Samples

Exp_5_Sample_Phase_2_End: RETURN

Take samples of phase 2 Write samples to EEPROM

Exp_5_Sample_Phase_1:

GOSUB Exp_5_Inc_EepromAddr a2dMuxId = A2dMuxId3

GOSUB Exp_5_Wait_For_Zero GOSUB Exp_5_Wait_For_Next_Peak a2dMuxId = A2dMuxId1

' Increment pointer to EEPROM ' Set the A/D to convert Channel 3 ' sync up to phase 3 ' Loop until the wave is zero ' Wait for wave to begin to peak

Switch the A/D to convert Channel 1

GOSUB Exp_5_Take_Samples GOSUB Exp_5_Write_Samples

Exp_5_Sample_Phase_1_End: RETURN

Take samples of phase 1 Write samples to EEPROM

Exp_5_Sample_Rectified_Output: GOSUB Exp_5_Inc_EepromAddr a2dMuxId = A2dMuxId3

GOSUB Exp_5_Wait_For_Zero GOSUB Exp_5_Wait_For_Next_Peak

' Increment pointer to EEPROM ' Set the A/D to convert Channel 3 ' sync up to phase 3 ' Loop until the wave is zero Wait for wave to begin to peak a2dMuxId = A2dMuxId0

Switch the A/D to convert Channel 0

GOSUB Exp_5_Take_Samples GOSUB Exp_5_Write_Samples

Take samples of the rectified wave Write samples to EEPROM

Exp_5_Sample_Rectified_OutputEnd: RETURN

' Retrieve 4 samples, one for each channel. This will be called 10 times, ' to get the total "bank", which is 4 sets of 10 samples per channel. Exp_5_Retrieve_For_Plotting:

' READ (eepromAddr - $30 + plotCount), ch3 ' Read phase 3 into ch3 ' READ (eepromAddr - $2 0 + plotCount), ch2 ' Read phase 2 into ch2

READ (eepromAddr - $10 + plotCount), ch1 ' Read phase 1 into ch1 ' READ (eepromAddr - $00 + plotCount), ch0 ' Read rectified val into ch0

Exp_5_Retrieve_For_Plotting_End: RETURN

Exp_5_Wait_For_Zero: ' Loop until the rectified wave

DO ' is below 0.10 volts

GOSUB A2D LOOP UNTIL (a2dResult <= 5)

Exp_5_Wait_For_Zero_End: RETURN

Exp_5_Wait_For_Next_Peak: DO

GOSUB A2D LOOP UNTIL (a2dResult => 5)

Loop until the rectified wave is non-zero

Exp_5_Wait_For_Next_Peak_End: RETURN

Exp_5_Take_Samples:

FOR sampleCount = 0 TO 9 GOSUB A2D

sampleArray(sampleCount) = a2dResult NEXT

Enter with A2D channel set Acquire 10 samples of the wave as quickly as possible

Exp_5_Take_Samples_End: RETURN

Exp_5_Write_Samples: ' Enter with eepromAddr set

FOR sampleCount = 0 TO 9 ' Store the wave samples to

EEPROM

WRITE (eepromAddr + sampleCount), sampleArray(sampleCount) NEXT

Exp_5_Write_Samples_End: RETURN

Exp_5_EepromAddr_To_Zero: eepromAddr = $0000

Exp_5_eepromAddr_To_Zero_End: RETURN

Initialize the eepromAddr to the bottom of EEPROM

Exp_5_Inc_EepromAddr:

eepromAddr = eepromAddr + 16 IF (eepromAddr >= $0300) THEN

GOSUB Exp_5_eepromAddr_To_Zero ENDIF

Exp_5_Inc_EepromAddr_End: RETURN

Add 16 to move to next bank Make sure not to overwrite our PBASIC program which starts around $0300

End Exp_5 Subroutines

V If you have hand-entered all these changes, save your work!

DIY Battery Repair

DIY Battery Repair

You can now recondition your old batteries at home and bring them back to 100 percent of their working condition. This guide will enable you to revive All NiCd batteries regardless of brand and battery volt. It will give you the required information on how to re-energize and revive your NiCd batteries through the RVD process, charging method and charging guidelines.

Get My Free Ebook


Post a comment