Packing 10bit ADC results into PIC (not a question)

Thread Starter

Markd77

Joined Sep 7, 2009
2,806
I was just about to start naively storing all the bits sequentially, but thought of a better method (I'm probably not the first to think of this).
Instead there is a pattern of 5 bytes, the first 4 contain exactly what was in the least significant bits of the first 4 analog to digital conversions. The 5th byte is packed with four sets of the extra 2 bits from each conversion.
I'm pretty sure this is much faster than doing it the other way, both packing and unpacking.
I haven't included the code for setting the FSR to the start point of the store, the loop or the readAD subroutine because they are more application specific.
Code:
Rich (BB code):
    call readAD                ;First byte
    movf ADRESLtemp, W
    movwf INDF
    movlw 0x04
    addwf FSR, F            ;FSR + 4
    clrf INDF
    btfsc ADRESHtemp, 1
    bsf INDF, 7
    btfsc ADRESHtemp, 0
    bsf INDF, 6
    movlw 0x03            ;FSR - 3
    subwf FSR, F    

    call readAD                ;Second byte
    movf ADRESLtemp, W
    movwf INDF
    movlw 0x03
    addwf FSR, F            ;FSR + 3
    btfsc ADRESHtemp, 1
    bsf INDF, 5
    btfsc ADRESHtemp, 0
    bsf INDF, 4
    movlw 0x02            ;FSR - 2
    subwf FSR, F    

    call readAD                ;Third byte
    movf ADRESLtemp, W
    movwf INDF
    movlw 0x02
    addwf FSR, F            ;FSR + 2
    btfsc ADRESHtemp, 1
    bsf INDF, 3
    btfsc ADRESHtemp, 0
    bsf INDF, 2
    movlw 0x01            ;FSR - 1
    subwf FSR, F    

    call readAD                ;Fourth byte
    movf ADRESLtemp, W
    movwf INDF
    movlw 0x01
    addwf FSR, F            ;FSR + 1
    btfsc ADRESHtemp, 1
    bsf INDF, 1
    btfsc ADRESHtemp, 0
    bsf INDF, 0
    movlw 0x1            ;FSR + 1
    addwf FSR, F
 
Last edited:

Thread Starter

Markd77

Joined Sep 7, 2009
2,806
Actually, l'll be storing a few hundred for later processing. Four 10bit samples fit into five bytes.
 

MMcLaren

Joined Feb 14, 2010
861
Actually, l'll be storing a few hundred for later processing. Four 10bit samples fit into five bytes.
If you're measuring a signal that changes relatively slowly over time, you might be able to store the first 10-bit reading and then store a signed 8-bit delta value for subsequent readings.

Good luck on your project...

Regards, Mike
 
Top