Shop OBEX P1 Docs P2 Docs Learn Events
Need Help With ADC Program — Parallax Forums

Need Help With ADC Program

tom90tom90 Posts: 55
edited 2007-11-21 01:07 in Propeller 1
I have been working on this program for a 12-bit ADC (max 1270) for a while, but I just cant get it to work.
When I started this I was new to assembler, but I think it is pretty close to working (Hopefully).

When I run the program the propeller doesn't output anything. I wasn't exactly sure how to set up the pin masks
at the beginning so that could easily be the problem.

Also, is my shift in routine correct?

My assembler knowledge has definitely hit a wall! If somebody could take a look at my code and point out some
errors, I would be greatful.

Thanks,
Tom

Comments

  • pgbpsupgbpsu Posts: 460
    edited 2007-11-20 21:07
    Hi Tom-

    I'm not sure what you are doing with all the mask stuff at the beginning. It seems to me you are overwriting your dira register several times. Maybe I misunderstand what you are doing there, but if you suspect your trouble is in the mask stuff at the front, why not simplify it?

    As far as I can tell, by the time you get into BigLoop, you dira only has CsAdc. Yet in BigLoop it looks like you want to fiddle pins other than just pin 5.

    Why not define DIRA all at once using something like:
    DIRA_DEFN long %0000_0000_0000_0000_0000_0000_1010_1010

    which would set pins 1,3,5,&7 as outputs. (provided that's what you want)

    Then set dira in one command like this:
    mov dira, DIRA_DEFN ' set DIRA

    p
  • tom90tom90 Posts: 55
    edited 2007-11-20 21:19
    P

    If I define the dira register like this then how do I define which pin is which in the program?
    For example:

    If I want to send my clock pin high I would say

    mov outa, ClkAdc

    How do I define which pin corresponds to "ClkAdc"


    In the past i have simply used something like this to define "ClkAdc" as I/O pin 7:
    ClkAdc     long           |<7
    
    


    However, people have told me to setup a pin mask like I tried in my program, but Im not sure if I did it right.

    Thanks for the input
    Tom
  • pgbpsupgbpsu Posts: 460
    edited 2007-11-20 22:05
    Tom-

    I usually set my pins up like this:
    'PIN ASSIGNMENTS     %1098_7654_3210_9876_5432_1098_7654_3210
    DIRA_DEFN     long      %0000_0000_0000_0000_0000_1000_1111_1111 
    'set pins 11;7-0 as outputs.  All others are inputs
    SHADOW        long        |< 11 'OUTPUT; SHADOW of DATA just to show we are getting it correctly
    DATA             long         |< 10
    LRCLK            long         |<  9
    
    



    And access them like this:
    Here's a snippet from a assembly routine I'm using to read an ADC
    :L_channel    mov       current, #0      ' set current=0
                        mov       nbits, #25              ' nbits=25; number of times to loop
                        waitpeq   LRCLK, LRCLK       ' data are valid on rising edge; wait for LRCLK to go high
    
    :bitloop         and       DATA, ina nr, wc      ' Read DATA pin of INA.  set C=1 if odd number of ones in result
                       rcl        current, #1              ' shift C one bit at a time into current
                       muxc    outa, SHADOW         ' Set SHADOW to state of C so we can see what data we're collecting on scope
                       djnz      nbits, #:bitloop        ' Decrement nbits.  if Not Zero repeat; else move on
    
    



    Hope that helps.
    p
  • pgbpsupgbpsu Posts: 460
    edited 2007-11-20 22:21
    Tom-

    When you do this:

    mov outa, ClkAdc
    
    



    You are setting outa = ClkAdc which will set ONLY bit 7 of outa high AND CLEAR ALL OTHERS. If you only want to affect a single bit of outa, you'll need to use muxc.

    p
  • tom90tom90 Posts: 55
    edited 2007-11-20 22:44
    P

    Thanks a lot for the help!
    I didnt know I was clearing the entire outa register when I was doing this.

    I will give your advice a try tomorrow.

    Thanks again
    Tom
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-21 01:07
    MUX is nice but not always necessary... You generally work with
    OR
    and
    ANDN
    When you have the bits of the I/O pins in a 32-bit long X (a "mask) you do:
    OR OUTA, X to set it, and
    ANDN OUTA, X to clear it, and
    XOR OUTA, X to toggle it.

    When you use the first I/O ports n=0 ... 9 only you can use "immediate" addressing, but with hardly any advantage:
    OR OUTA, #|<n
    ANDN OUTA, #|<n
    XOR OUTA, #|<n

    You can of course also use "short masks" within the 9-bit range, i.e. when you want to use I/O 4 to 7.
    You also best use CONSTANTS to improve readeability as well as simplify maintainance.

    CON
    io4to7 = $f0
    DAT
    OR OUTA, #io4to7

    etc.
Sign In or Register to comment.