Shop OBEX P1 Docs P2 Docs Learn Events
Need waitpeq examples — Parallax Forums

Need waitpeq examples

frank freedmanfrank freedman Posts: 1,983
edited 2011-09-13 07:07 in Propeller 1
Looking for good example of waitpeq or waitpne instruction. Has anyone posted an object using these in OBEX?

The daSilva tutorial has example, but it is using immediate values, and does not help me on the higher pins. Need a bit better explanation than the Prop man provides.

Thanks,
Frank

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2011-09-12 09:53
    For the higher pins you need to use a variable to hold the pin mask (as you do for the state value). So for instance
            waitpeq state, #$F0   ; test pins 4/5/6/7 wait for only pin 7 high
            waitpeq state2, mask2 ; test pins 12/13/14/15 wait for only pin 15 high
    
    
    state   long   $80  
    mask2   long   $F000
    state2  long   $8000
    
    (Hope I've got that right).

    The instruction continuously reads the ina register (pin state) and ANDs it with the mask value, then compares to the state value. The cog halts until the result of the AND matches the state value.

    This means that only pins with a bit set in the mask value are inspected, and each must match the relevant bits in the state.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-12 09:56
    There's nothing different about the WAITPxx instructions vs. other instructions regarding immediate values vs. addresses. If the source value can fit into 9 bits, you can use an immediate value. If it doesn't fit, then you need the source value to be in a cog memory location and you put its address in the source field.

    It's not the purpose of the OBEX to have examples of instruction use. It's a repository of library objects, hopefully of general use for specific functions or I/O devices. Most of the I/O drivers that have assembly routines make use of WAITPxx instructions.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-09-12 21:52
    Mike Green wrote: »
    There's nothing different about the WAITPxx instructions vs. other instructions regarding immediate values vs. addresses. If the source value can fit into 9 bits, you can use an immediate value. If it doesn't fit, then you need the source value to be in a cog memory location and you put its address in the source field.

    It's not the purpose of the OBEX to have examples of instruction use. It's a repository of library objects, hopefully of general use for specific functions or I/O devices. Most of the I/O drivers that have assembly routines make use of WAITPxx instructions.

    @Mark_T
    Thanks for your reply, that is about what I was looking for. Looks like what I had but mine would just not work. The code posted may help me to determine just why what I wrote is not doing what I think it is.

    @ Mike.
    I perhaps may have misled you in what I was needing. What I meant to say was looking for an example using register content rather than immediate. I do understand the immediate vs.content of address. not in question actually. What I was looking for was how someone else wrote theirs so that I could compare with the way I did mine (and did not work).

    As to the OBEX, while it is not a repository of "examples", the very existence of the objects makes them examples. Few objects on the OBEX that I have looked at for use have met my needs as is. I have never expected them to. No reasonable person would. However, there are many very good, actually some "best practices" and ideas that one can look at learn from and emulate while folding them to the needed use. I reviewed many objects to create a three wire LCD driver in spin. Partly to see if I could teach myself to write one, and to use minimal I/O pins. I got to three, because I need be very miserly in one project coming up; 32 pins may be a bit to tight. Someone mentioned that they actually got to one line. The statement regarding the waitpxx instructions being fairly well represented in the I/O devices was part of what I was looking for.

    Frank
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-12 22:10
    What I was looking for was how someone else wrote theirs so that I could compare with the way I did mine (and did not work).
    Why don't you show us what you have (the not working bit) and explain what you want? Unless you want to figure it out on your own ...
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-09-12 23:18
    kuroneko wrote: »
    Why don't you show us what you have (the not working bit) and explain what you want? Unless you want to figure it out on your own ...

    Here is the solution, resolution prompted by Mark_T (and a host of others).
    Acquire
    
    Read_ADC ' should produce a csel low for a count of 15 pulses
    
            muxnz dira,pcsel     ' set csel pin to output
            muxz  outa,pcsel     ' set output to low
            nop
            or  dira,pckpin      ' enable clock pulses
            muxz  outa,pckpin    ' turn on clock pulses
            waitpeq null,pckpin  ' wait for first low clock
            mov clk_cnts,delaycnt   ' set to fifteen clock times
    acq_lp
            waitpeq clock_mask,clock_mask    'wait for the pin to go high
            waitpeq null,clock_mask         'wait for pin to go low
            djnz  clk_cnts,#acq_lp
    
            or    outa,pckpin       ' turn off clock
            xor   outa,pcsel        ' set the chip select high
            jmp     #Read_ADC       ' readout ADC sample 1 of n (test only, will be end of 256pt loop)
    
    

    and the resulting timing

    2011-09-12 22.49.09.jpg


    Thanks to all on this one.
    1024 x 768 - 86K
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-09-12 23:29
    I would have shown the non-working bit, however I tend to be a bit of a junkyard dog on problems and y'know, just one more try and shazam!!! Same thing with an AMX4 today at work. The D@MN thing would randomly reset itself when the rad tech was positioning the tube in certain ways. Not trip the breaker, just enough to shut down the switching supply. Turned the thing into gumby trying to reproduce the problem. Tore up half the collimator to check the wiring and finally found in a tiny corner the frayed insulation on a +24V line. Would short out only when in an extreme position, and only when the field lamp was activated from the collimator faceplate switch (to check positioning relative to film/cr plate and patient). Just was not ready to call it not found, So......... one more check and yep, shazam!!! Issue determined, parts for first overnight FedEx........ just the way I am.

    Frank
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-13 00:22
    Acquire
    
    Read_ADC ' should produce a csel low for a count of 15 pulses
    
            muxnz dira,pcsel     ' set csel pin to output
            muxz  outa,pcsel     ' set output to low
            nop
            ...
    
    Do you really want to rely on the Z flag being zero for this loop? You could easily use or/andn to achieve the same effect here.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-09-13 05:54
    kuroneko wrote: »
    Do you really want to rely on the Z flag being zero for this loop? You could easily use or/andn to achieve the same effect here.

    Thought about this. May revisit.

    Thanks,
    Frank
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-09-13 07:07
    > muxnz dira,pcsel ' set csel pin to output
    > muxz outa,pcsel ' set output to low

    As stated by Mr K,
    You only use muxz if your previous line(s) of code used a instruction that set z (conditionally 0 or a 1) and
    that you now want to set the destination registers bits to having the same value as z.

    Mask will take care of only setting the bits you want affected,
    as having a final result of only #0 or #-1 would be very limiting to its use.

    So muxz it just a shortcut to avoid two lines with if_z & if_nz.
    If you know the the value you want to set, use or & andn instead.
Sign In or Register to comment.