18F1220 A/D Converter


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: 18F1220 A/D Converter

    Well, I'm intrigued. This has also raised some questions as to my ability to read a data sheet...

    Going back to Table 17-1 in the datasheet. MC refers to "TAD vs. DEVICE OPERATING FREQUENCY". In this case I assume "DEVICE" to be the IC. If this is the case then with ADCS2:ADCS0 set to "111" then the max you can clock the part at is 1 MHz. Am I missing something here?

    In ADCON2 you have ACQT2:ACQT0 set to "000" = 0TAD. Is this correct? I'd have a look at section "17.3 Selecting and Configuring Automatic Acquisition Time"

    There is are two notes regarding using Frc as the clock and putting the part to SLEEP before starting a conversion. There was the note about the accuracy may be off if not put to sleep but unclear to me what happens if you don't.

    When you say it's not working, what exactly do you mean? The result is wrong, or there is no conversion at all? You may already do these things, but when I'm testing a section of code I'll do things like blink an led after a conversion and such just to make sure that the routine is even running...

    What is the source impedance? Max is 2.5K...

    I agree with Al in the way that he handles the Go/Done bits and not use the defines...

    Lastly; what versions of PBP and MPLAB are you using? I recently was having a problem with a program and knew the program was correct but wouldn't run. For giggles I upgraded both PBP 2.60A and MPLAB to the latest and low and behold it started working. I wish I hadn't done them both at the same time so I knew which one it was (frankly I don't care) but it solved the problem.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 18F1220 A/D Converter

    I'm not sure what chip you were using here, but I dont think it was the 1220, I cant find any refference to CMCON in the data sheet.
    Just to complete the information, I was using a 18F2620.

    You should ignore the CMCON register since 18F1220 has no comparators.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: 18F1220 A/D Converter

    I can't tell you if your chip behaves the same as mine, but I use a lot of 18F2321's and I found that ADCIN didn't work.

    Try this.


    Code:
       ADCON0 = %00000001  ; Turn it on
       ADCON1 = %00010011  ; Chan 0 -11, Vref, GND (note that I use a precision reference on AN3)
       ADCON2 = %10001001  ; Rt jus, 2Tad, /8 clk
     
     
    Main:
       Chan = 4 ;Pick the channel you want to read
       NumSamples = 10 ; Do multiple reads for averaging or scaling
       Gosub DOADC
       ; resut is in ADCSTOR (WORD)
      GoTo Main
     
     
    .....
     
    DOADC:
     
     ADCSTOR = 0
             For X = 1 to NumSamples
                ADCON0 = ((Chan << 2) | %00000011)     
                While ADCON0.1:WEND                     
                ADCVAR.highbyte = ADRESH
                ADCVAR.lowbyte = ADRESL
                ADCSTOR = ADCSTOR + ADCVAR
                Pauseus 20
            Next X
     
         Return
    Charles Linquist

  4. #4
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: 18F1220 A/D Converter

    Well I have it working now, thanks for all of your help.

    I decided to take PBP out of the equation. I no am using:

    TRISA = 255
    ADCON0 = %00000001 'Vref = Vss Vdd, turn on A/D
    ADCON1 = %11111110 'Only Channel 0 analog
    ADCON2 = %10001010 'Right justified, 2 TAD, TOSC/32 (for 20MHz)

    For the A/D conversion:

    ADCON0.1 = 1 'Start A/D conversion
    while ADCON0.1 = 1 'Wait for it to finish
    wend
    adresult.highbyte = ADRESH
    adresult.lowbyte = ADRESL

    This works a treat. Now on to the next problem, trying to get the thiristors firing in the correct way.

    Regards
    Bob...

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts