Shop OBEX P1 Docs P2 Docs Learn Events
Reading 8bit ADC in parallel — Parallax Forums

Reading 8bit ADC in parallel

hunparyhunpary Posts: 1
edited 2012-05-01 15:29 in Propeller 1
Hello,
I would like to have a question about ina register in propeller, Basically I am using a development board.
What I am trying to do in assembly is to read 8bit ADC value in parallel at a 7mhz rate. the code is attached.
In a new cog, it just is keeping reading ADC and storing each into designated address.
In the other side, spin code is getting the stored ADC values and sending them to PC in order to check through the serial port.
But I haven't gotten any right value from this program except for zeros.
In addition, I tried to read ADC at a fixed address but it was the same as the previous one.

I read through the manual, but it is talking about the OUTA rather than INA.
I hope to see if my code works or not and to know how to set up to read ADC in parallel with an example.

Thank you for your help.

adc_asm.spin

Comments

  • bee_manbee_man Posts: 109
    edited 2012-05-01 12:11
    Look at the ADC0820 driver in the OBEX for an example of reading an 8bit ADC.
  • Mark_TMark_T Posts: 1,981
    edited 2012-05-01 15:29
    A few immediate issues spring to my attention, see the ''' comments:
    DAT  
             org 0 
                                
             mov dira,pin_mask 'set pins from 0 to 7 as 8 bit inputs 
              
    start    mov t0, par       'receving the first address of storage that adc values are stored to 
             add t1, #100      't1 is counter for repeating this sequnce 100 times    ''' t1 is undefined here - the res directive does not zero its contents, use MOV not ADD
    :loop    mov t0, ina       'reading pins from ina register 
             add t0, #4        'Increment with 4 because a long space takes up 4 bytes.    ''' are you trying to use hub ram?  You need to use WRBYTE and then ADD by 1 since adc is byte array
             djnz t1,#:loop    'after subtracting 1 from t1, it jumps to :loop until t1 gets zero 
             mov t0, par       'setting t0 to the initial address of the storage 
             jmp #start        'going back to first sequence right after 100 repition. 
          
     
    t0      res   1            'temporary space for addressing as a pointer 
    t1      res   1            'temporary space for counts. 
    pin_mask long 111111_11111111_00000000_00000000
    

    Something more like this?
    :loop           mov   t, ina
                    wrbyte t, t0
                    add   t0, #1
                    djnz ...
    

    The PASM loop is going to run much much faster than SPIN can keep up, so expect the whole adc array to be updated many times for a few SPIN lines...
Sign In or Register to comment.