X hits on this document





3 / 4

DONE is 1 bit, SAMP is 1 bit, ASAM is 1 bit, the next bit has no name, CLRASAM is 1 bit, etc. The second struct is an alternative representation of the bits of the SFR; it has 5 unnamed bits, then 3 collectively named SSRC, 3 named FORM, 2 unnamed bits, 1 named ADSIDL, 1 unnamed, and 1 named ADON. Finally, the last struct has all 32 bits in a field named w.

Just below this type definition is defined the variable AD1CON1bits of type __AD1CON1bits_t. This allows us to refer to specific bits using more understandable variable names, rather than just talking about the 7th bit of AD1CON1. AD1CON1bits does not appear to be used much in the adc10.h library, however (only in BusyADC10()). (AD1CON1bits actually resolves to the same data memory location as AD1CON1. We now have two ways to refer to bits in this memory location: by AD1CON1, of type int, or by AD1CON1bits, of type __AD1CON1bits_t. To refer to the SAMP bit of AD1CON1bits, for example, we just type AD1CON1bits.SAMP. The name after the period accesses the appropriate bits.)

Let's keep searching for the text AD1CON1.

We can see it defined for assembly

language about 30% of the mostly ignore this assembly

way in the file (along with CLR, SET, and INV). We will code, which is defining memory locations (addresses) for the

variables, but notice that consecutive addresses differ (These are actually "virtual" memory addresses, which addresses. This is beyond our scope.)

by 4. Question: then get translated

Why is


to actual


Next, about 55% of the way into the file, we see a bunch of #define statements, the first of which is #define _AD1CON1_DONE_POSITION 0x00000000. There are definitions for POSITION, MASK, and LENGTH for DONE, SAMP, ASAM, CLRASAM, SSRC0, etc., up to ON, corresponding to the first struct in the type __AD1CON1_bits_t; for SSRC, FORM, ADSIDL, and ADON for the second struct; and w for the third struct.


Referring as necessary to the SFRs for the ADC in the Reference

Manual, what function do the bits SSRC1, SSRC2, FORM0, FORM1, purpose do the POSITION, MASK,

DONE, SAMP, ASAM, CLRASAM, SSRC0, FORM2, SIDL, FRZ, and ON serve? What and LENGTH definitions serve? Now answer

the same questions for the bits FORM. Are any LENGTH definitions used in adc10.h? Give an example) and explain what that line of code does.

of these example

POSITION, MASK, of each (if there is

or an

At the end of the file, we see the constant _ADC10_BASE_ADDRESS defined. This is the address in (virtual) data memory where the where the ADC10 SFRs begin. You can see that this address is identical to the one defined for AD1CON1 in the assembly language definitions.

  • 19.

    Refer to the definition of the AD1CON1 SFR and Section 17.3 of the Reference Manual. Let's say you want to set up the ADC to do the following: be on, continue operating in the debug exception mode, stop when the PIC is in IDLE mode, format the ADC output as a 32-bit integer, use an internal counter to end sampling and start conversion (auto conversion), continuously overwrite the buffer storing the conversion results, and begin the next sample immediately after the last conversion completes. (By reading Section

    • 17.3

      of the Reference Manual, you see that an ADC reading consists of two steps:

sampling, where the voltage on the input pin is carried through to the output of a sample and hold circuit; and conversion, when the voltage at the output of the sample and hold is

Document info
Document views23
Page views23
Page last viewedSun Oct 23 00:18:25 UTC 2016