Example Program ADCtestbs

As before, in preparation for programming the A/D converter code you must first declare the variables this routine will use.

V Open and resave PlotIt.bs2 as ADCtest.bs2.

V Double-check the Piot_it subroutine to make sure the ch0 through ch3 values are set equal to zero; correct if necessary.

V Add the variables for the A/D Converter Routine to the Declarations section, which should read as shown below when you are finished. Note that the Piot_it subroutine variables remain in place.

Declarations

For Plot It Subroutine

ch0

VAR

Byte

'Voltage reading from A/D CH0

ch1

VAR

Byte

'Voltage reading from A/D CH1

ch2

VAR

Byte

'Voltage reading from A/D CH2

ch3

VAR

Byte

'Voltage reading from A/D CH3

checkSum

VAR

Byte

'Sum of all of above readings

For ADC08 34 4-Channel Multiplexed A/D Converter

A2dChipSel A2dDataIn A2dClk A2dDataOut

A2dMuxId0 A2dMuxId1 A2dMuxId2 A2dMuxId3

a2dMuxId a2dResult

PIN PIN PIN PIN

CON CON CON CON

VAR VAR

Nib Byte

A/D Converter Chip Select(PO) A/D Converter Data Input(Pl) A/D Converter Clock(P2) A/D Converter Data Output(P3)

Bit 1 odd / sign, Bit 0 select

A/D Channel MUX ID to shift out 8-bit result of A/D conversion

V In the Subroutines section, insert the following A/D Converter Routine code underneath its heading, like this:

A/D Converter Routine

Enter with a2dMuxId as the channel to convert

Return with 8-bit result in a2dResult (msb,6,5,4,3,2,1,lsb)

A2D:

HIGH A2dChipSel LOW A2dDataIn LOW A2dClk a2dResult = 0

A2D_Start_Conversion: LOW A2dChipSel

A2D Shift Out Channel ID:

Initialize signals Disable A/D Chip Select Initial state of data in Initial state of clock Clear the 8-bit result

Start the conversion process Enable A/D chip select

Shift out the Channel ID value

SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId\4]

' Shift in the result

A2D_Shift_In_Result: PULSOUT A2dClk,10

SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult\8]

HIGH A2dChipSel

A2D_End: RETURN

' Disable A/D chip select ' Return to calling routine

Was this article helpful?

0 0
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