Pic12F675 A2D problem

Discussion in 'Embedded Systems and Microcontrollers' started by Dodgydave, Jun 22, 2015.

  1. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,999
    745
    Got this little blighter working ok , a2d working but when i look at the adresh and adresl files which are the results of the a2d , they both are the same values and not the usual lower 2 bits in adresl and upper 8 bits in adresh, yet its set to left justified,

    tried the same routine on my usual 18f24k22, works perfect left or right justified the 8 and 2 bits are in different files,

    if i get the adresh file and put it to the gpio output ,the leds flicker on and off counting up as they should do as i rotate the preset on port An0,
    no probs there yet if i look at adresl its the same all leds flicker and counting , they should be the lower two bits as i am using left justified,

    why is the adresh and adresl showing the same values, is there something in the chip or programme that makes it not work like the 18f pic?

    Here is the AD setup in Asm


    AD ; a to d routine for pot on an0 pin 7,
    bsf STATUS,RP0 ; banks select 1
    movlw b'11001001' ; Specifiy GPIO port direction
    movwf TRISIO ; Set GPIO ports as xx0OIOO1 gp1-2 4-5 output, gp0,3 input
    movlw b'01110001' ; set AN0 to analogue input bit 0, int rc osc,
    movwf ANSEL
    bcf STATUS,RP0 ; bank 0
    movlw b'00000001' ; a/d on AN0 left justified bit 7=0, int ref vdd bit 6,set bit 1 to start conversion
    movwf ADCON0

    movlw b'0000111' ; turn off comparators pg 37
    movwf CMCON ; put to reg
    bsf ADCON0,1 ; start conversion
    hold
    btfsc ADCON0,1 ; is it done yet?
    goto hold ; no
    bsf STATUS,RP0 ; bank 1
    clrf ANSEL ; ports to digital I/O
    clrf TRISIO ; set ports to output
    bcf STATUS,RP0 ; bank 0

    return
     
    Last edited: Jun 22, 2015
  2. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    Are you waiting the appropriate time for acquisition after turning on the ADC?
     
  3. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,999
    745
    ad clock is set to 2-6uSec, internal 500khz speed, so thats the longest time.



    Must be the gpio port, it works ok in right justified.....
     
    Last edited: Jun 22, 2015
  4. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi Dave,
    Please post your complete program code, I will run it thru my IDE Sim.
    [post as an attachment]

    E
     
  5. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,999
    745
    eric sent you a pm with the asm file attached..

    note if i change the line movfw adresh to adresl, the leds move the same , they should only be the lower two bits
     
    Last edited: Jun 23, 2015
  6. RJohnson

    New Member

    May 29, 2011
    21
    3
    You realize this is an 8 pin device and GPIO does not include bits 6 & 7 when left justified. So when you write to A/D result to GPIO those
    2 bits do not get written as there are no outputs. Make sense?
     
  7. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,999
    745
    yes i know, what i get is both files adresh,adresl have the same values in them which ever i choose left or right justified, even if i use the xorwf with adresh, adresl, and test for zero, its as though they operate as one file...
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    If what RJohnson suggested isn't the issue, ADRESH and ADRESL are in different banks, which, it doesn't seem like you are switching between to access them - perhaps that is the issue.
     
    Dodgydave likes this.
  9. Dodgydave

    Thread Starter Distinguished Member

    Jun 22, 2012
    4,999
    745
    You are right they are in different banks, and thats the cause of the problem, thankyou...
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Which is why the BANKSEL macro was written.
     
  11. RJohnson

    New Member

    May 29, 2011
    21
    3
    And why I like the 16 bit processors written in C better. I didn't like keeping track of the banks in the 8 bit stuff. err!@$#%
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    You need not track banks in 8 bit devices either once you step up to any higher level compiler, C included.
     
Loading...