Shop OBEX P1 Docs P2 Docs Learn Events
ADC Parameter clarification Please! — Parallax Forums

ADC Parameter clarification Please!

TurboManTurboMan Posts: 19
edited 2010-10-05 13:02 in Propeller 1
In Beau's ADC driver code there are two parameters called sample. By the Prop Manual docs PUB (parameter) is "parameter is essentially a long variable and can be treated as such" and the COGNEW (ABC, parameter) "is passed into the COG's PAR register" and it is stated that they can both be local parameters.
I also see in Beau's documentation the wrlong par command says it writes the sample back to spin var "sample". For my own clarification does the "wrlong...., par" instruction send the data to the PUB (sample) and then the Cognew sample would be the data from the PUB (sample)? In other words the PUB.... (sample) is the actual variable? Correct? If true then what if I had multiple PUB (parm1,parm2,parm3). Would I then change the wrlong ,par to wrlong ,parm1 ?

PUB SigmaDelta (sample)
cognew(@asm_entry, sample) 'launch assembly program in a COG
...
DAT
....
wrlong asm_sample,par 'write sample back to Spin variable "sample"

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-25 07:48
    What you wrote will not do what you expect. PAR is used to hold the address of a long. It's only 14 bits wide (shifted left 2 bits) and the low order two bits are forced to zero, so it can hold a long word address from 0 to 65535. You probably mean to write COGNEW(...,@sample). In that case, the WRLONG will store the value in the variable sample. Since sample is a parameter, you have to be careful because the parameter is allocated on the stack and, when the SigmaDelta routine exits, that variable no longer exists even though the assembly routine still expects it to be there. Either the SigmaDelta routine has to continue to run indefinitely or the assembly routine has to be stopped before SigmaDelta exits or sample could be defined globally in a VAR section.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-09-25 09:16
    TurboMan,

    I assume that you are talking about the ADC.spin located in the Propeller Tool examples directory.

    The 'parameter' passed in both the PUB and from the cognew command are one in the same and represent the address of the variable you want to write the result to.

    The COG's PAR register holds the address of the variable we want to write to since we are not using an @ directly in 'sample'.

    If you had multiple PUB (parm1,parm2,parm3) , you could do that, but you would have to call the cognew using the @ symbol with parm1 like this...

    cognew(@asm_entry, @parm1)

    ... that way within PAsm you could write to parm1, parm2, and parm3 like this...

    mov     t1,             par     '<- get address pointer for parm1
    wrlong  asm_sample1,    t1      '<- write to address parm1
    
    add     t1,             #4      '<- advance address pointer to parm2
    wrlong  asm_sample2,    t1      '<- write to address parm2
    
    add     t1,             #4      '<- advance address pointer to parm3
    wrlong  asm_sample3,    t1      '<- write to address parm3
    

    likewise if you allocated your variables that you wanted to write to somewhere outside of the SigmaDelta PUB (The way it was intended), then your code might look something like this...
    VAR     
    long    parm1,parm2,parm3
    
    OBJ     ADC : "ADC.spin"
    
    PUB     ExampleCode
            ADC.SigmaDelta(@parm1)
    

    ...in this case parm1, parm2, and parm3 would still be accessed from PAsm in the same way mentioned above ... because we are defining the value of 'sample' within the ADC.spin object as the address of 'parm1'
  • TurboManTurboMan Posts: 19
    edited 2010-10-05 13:02
    Thanks to Mike and Beau for the explanation. I do understand it better now. With the help of many, I've been able to get the basics of my project up and running and now I just need to tweak it. There is so much information out there that it is hard to sift through it plus I get side tracked at other peoples projects. There are so many cool projects going on and I have so many new ideas in my head that it's hard to focus on one...
Sign In or Register to comment.