Shop OBEX P1 Docs P2 Docs Learn Events
Measuring Pulse / spin and assembly communication — Parallax Forums

Measuring Pulse / spin and assembly communication

krazyideaskrazyideas Posts: 119
edited 2008-11-10 22:14 in Propeller 1
Hello

I am having a couple of problems. I'm not understanding how to use the command "wrword or wrlong"
What I think they are soppose to do is write the value to a varuble that can be accessed in a spin program. I want to store Reader into the spin var ReaderToRPM, along with a couple others. How do I do that??

Also I was wondering about how I was doing the division command (mov deg, measure2 / 10) I want to divide measure2 by 10 and then store it in deg which I will inturn write to a spin varuble and then use.

My program fallows, I need it to be as fast as I can get it, which is why I did it in Assembly and not the much easyer spin. I think that I got it right besides the questions that I have.
What I am doing is measureing the duration of a high pluse from a motor and from that pulse I find how many clock ticks are in one degree of rotation, I know the window is 10 degrees hence the divideing by 10 to give me how many clock ticks in one degree.
Any help would be great. Thanks


var
long read
long ReaderToRPM
long begin
long degree
pub start
cognew(AssemblyReader, @read)

Dat
AssemblyReader·· cogid Reader···························· {Cog to stop when "l" is pressed and start RPM gage}
······················· wrword Reader, ReaderToRPM······ {Send COGID to ReaderToRPM}
··
······················· movs CTRA, %0························· {Monitor pin 0}
······················· movi CTRA, %011010000············· {Set CTRa mode to logic A and PLLa to times 16}
·······················
······················· mov beg, 0······························· {Set beg to 0}
:CountA············ mov PHSA, 0····························· {Resets PHSA to 0}
·······················
······················· waitpeq 1, |< 0························· {Wait till pin 0 is High}
······················· mov measure1, PHSA·················· {Store PHSA in measure1}
······················· waitpne 1, |< 0························· {Wait till pin 0 in not High}
······················· mov measure2, PHSA·················· {Store PHSA in measure2}
·······················
······················· sub measure2, measure1············· {Subtract measure1 from measure2 to get clock's passed between}
······················· mov deg, measure2 / 10·············· {Divide clock's passed by 10 to get clock's pass in one degree}
·······················
······················· add beg, 1································ {add 1 to begin each loop}
·······················
······················· wrlong beg, begin······················· {Send beg counter to begin to sync other cogs start up}
······················· wrlong deg, degree····················· {Send deg to degree to control other cogs}
·······················
······················· JMP #:CountA···························· {loop endlessly}

Reader········ word
measure1····· long
measure2····· long
deg············· long
beg············· long

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-11-10 22:14
    The way hub variables are accessed in assembly is different than spin. You have to use the par register (parameter). You have loaded par with the address of read, but you don't use it in your assembly. First off, you want to use the address of AssemblyReader in cognew, so the cognew should be cognew(@AssemblyReader,@read).

    Accessing multiple spin variables are done using base+offset, since you don't use the variable read in your assembly code, I'm going to remove that and assume that cognew(@AssemblyReader,@ReaderToRPM) is used instead. There are several ways to construct the pointers, this is one way:

    AssemblyReader add pReaderToRPM, par
                   add pbegin, par
                   add pdegree, par
                   cogid Reader                              
                   wrword Reader, pReaderToRPM
                   ...
                   wrlong beg, pbegin
                   wrlong deg, pdegree
                   ...
    
    ...
    pReaderToRPM long 0 
    pbegin long 4 
    pdegree long 8
    

    This creates pointers to each variable you need to access within your assembly program, thier inital values are the offset from the pointer passed via par. ReaderToRPM is what par is pointing at (hence 0 offset), begin is 1 long later (4 byte offset), and degree is one long after that (total of 8 bytes later). The first 3 lines of code construct each pointer by adding the base (par) to the offset, it is these pointers which are used in the wrlongs and wrword.

    Code for assembly multiply and divide is described in the Propeller Guts document: http://forums.parallax.com/showthread.php?p=572669

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.