Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Assembly for beginners - Page 16 — Parallax Forums

Propeller Assembly for beginners

1131416181929

Comments

  • HarpritHarprit Posts: 539
    edited 2011-09-17 11:33
    @Jon
    Thanks again for you careful and patient answer.
    I will have to re read the data sheets with much more care again this time and in future
    I had completely ignored the timing diagrams as being too advanced for the interests of beginners.
    Not so. Not so!
    H
  • HarpritHarprit Posts: 539
    edited 2011-09-17 12:05
    @Chris

    I reviewed and ran your program
    It runs OK right after loading it. Once
    Then will not run again properly if F10 is pressed.
    Dark boxes on first line. O'scope shown no activity on enable line.
    I tried to troubleshoot it to no real avail.
    Will you please take another look at your code to see what might be hanging things up.
    seems to be a problem with the jmp #$ command on the last line of the LCD_Init method
    If I replace it with jmp LCD_Init it works but it should not need that and the display is not really right.
    H
  • ChrisGaddChrisGadd Posts: 310
    edited 2011-09-17 13:58
    The code is meant to display the message once and then stop; jmp #$ is an in-line jump. Running the code a second time without resetting the display causes a glitch because the display is already configured in 4-bit mode. The following lines send one nibble to the display, while the display is expecting two nibbles.
                            mov       LCD_Temp,#%0010             ' 4-bit mode
                            call      #LCD_Send_Nibble
    
    You could comment those lines out when reloading, or power the display down between reloads.
    If you simply want to keep the display alive to see activity on the lines, execute a jump to the clear LCD line.

    @JonnyMac: The Data delay time T_ddr specifies 160ns as the maximum amount of time it might take for data to be valid after E goes high. I've written mine to check the busy flag after clocking Enable low following an on time of 250ns (actually closer to 350ns due to instruction overhead). The data sheet specifies PW_eh a minimum of 230ns, so I've got plenty of time there. I'm not following the Enable cycle T_cycE time of 500ns while checking the busy flag, my cycle time is slightly faster, but even so the display seems fine with it.

    Just had another look at it, and it seems to do fine even if I only mov Delay_cnt,#1, which produces a ~200ns on time. The attachments didn't come through as clearly as I'd hoped, but the first one shows a nine byte message to the LCD, with lots of busy flag checks. The second image is a closeup of one byte 0xC0, followed by busy flag checking.
  • HarpritHarprit Posts: 539
    edited 2011-09-18 13:43
    @Chris
    Thank you Chris. I appreciate the time you take to respond to this thread in some detail.

    Lets consider the 2 x 16 display done for now. Lets close the discussion of this device for now.
    Next let us go onto controlling a 7 segment display to see how that might be implemented in PASM
    I will consider one digit only at this time. One of the ones on the PD Board provided by Parallax.
    The resistors for each segment are in place, in series, already for these devices.
    A simple rapid serial illumination of 7 segments will be implemented.

    H
  • HarpritHarprit Posts: 539
    edited 2011-09-20 08:40
    [FONT=Arial, sans-serif]I am posting this first so that those who want to do some PASM on their own to control a 7 segment display can get going and we can all share the same wiring model.[/FONT]

    [FONT=Arial, sans-serif]The hardware used will be as provided on the PDB by Parallax. There are six 17segmented displays on this board. We will address the rightmost of these displays in our program. We will ignore the decimal point.[/FONT]

    [FONT=Arial, sans-serif]We will consider one digit with the equivalent of seven standard segments. The displays on the PDB have 17 segments each but we can treat them a 7 segment displays by combining the segments that form the top middle and low crossbars and ignoring the other 6 segments used for alphabetic character displays.[/FONT]


    [FONT=Arial, sans-serif]We have the following tasks ahead of us:[/FONT]

    [FONT=Arial, sans-serif]Wire up the display so that[/FONT]

    [FONT=Arial, sans-serif]Pin 12 controls segments B[/FONT]
    [FONT=Arial, sans-serif]Pin 13 controls segment C[/FONT]
    [FONT=Arial, sans-serif]Pin 14 controls segment E[/FONT]
    [FONT=Arial, sans-serif]Pin 15 controls segment F[/FONT]
    [FONT=Arial, sans-serif]Pin 16 controls segment A1, A2[/FONT]
    [FONT=Arial, sans-serif]Pin 17 controls segment G1. G2[/FONT]
    [FONT=Arial, sans-serif]Pin 18 controls segment D1, D2[/FONT]

    [FONT=Arial, sans-serif]The software sets up the segment control constants so that they are easy to change without having to rewire the experimental set up.[/FONT]

    [FONT=Arial, sans-serif]We will need the following methods[/FONT]
    [FONT=Arial, sans-serif] Identify number to be displayed. 0 to 9 in a loop[/FONT]
    [FONT=Arial, sans-serif] Assign consecutive addresses to the 10 number masks[/FONT]
    [FONT=Arial, sans-serif] Identify segment to be highlighted 01 to 7[/FONT]
    [FONT=Arial, sans-serif] Highlight the segment with programmable delay[/FONT]

    [FONT=Arial, sans-serif]Then the software[/FONT]

    [FONT=Arial, sans-serif]H[/FONT]
  • HarpritHarprit Posts: 539
    edited 2011-09-21 08:33
    [FONT=Arial, sans-serif]Here is the code to display form 0 to 9 on the rightmost display on the PDB.[/FONT]
    [FONT=Arial, sans-serif]This method displays to numbers by turning on the needed segments for a short[/FONT]
    [FONT=Arial, sans-serif]period of time, there is no display loop for each segment. The display for each number is static.[/FONT]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]{{ Program 021 PASM Seven Segment Display[/SIZE][/FONT][/COLOR]
      
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Cog in PASM controls the 7 Seg display[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Power will be directly from the Propeller[/SIZE][/FONT][/COLOR]
      
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]}}[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]CON[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]_clkmode = XTAL1 + PLL16x[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]_xinfreq = 5_000_000[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_1 = 12         'Display connections[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_2 = 13         'segments to pins[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_3 = 14[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_4 = 15[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_5 = 16[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_6 = 17[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]   [FONT=Lucida Console, monospace][SIZE=2]Pin_7 = 18[/SIZE][/FONT][/COLOR]
     
    
      
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]VAR[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]long shared[/SIZE][/FONT][/COLOR]
      
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]OBJ[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]fds: "FullDuplexSerial"[/SIZE][/FONT][/COLOR]
      
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]PUB FirstCog                          'displays par value on console,, if set  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]fds.start(31,30,0,115200)           'start console at 115200 for debug output[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]cognew(@PCog, @Shared)              'Cog in PASM for 7 Seg display    [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]waitcnt(clkfreq/4+cnt)              'wait 1/4 for everything to stabilize.  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]  [FONT=Lucida Console, monospace][SIZE=2]repeat                              'loop  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]    [FONT=Lucida Console, monospace][SIZE=2]fds.bin(shared[0],32)             'display whatever is in par[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]    [FONT=Lucida Console, monospace][SIZE=2]fds.tx(1)[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'--------------------------------------------------------------------------[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]DAT[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]org     0                           'start at 0 location in the cog [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]PCog[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]:loop     mov     select,   num0[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num1 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num2 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num3 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num4 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num5 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num6 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num7 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num8 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     select,   num9 [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #display  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]jmp     #:loop [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'-----------------------------------------------------------[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]display                     'start point identification[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     dira,     setdira[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]shl     select,   #12[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]mov     outa,     select[/SIZE][/FONT][/COLOR]
     [COLOR=#000000]          [FONT=Lucida Console, monospace][SIZE=2]call    #delay               [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]display_ret ret[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'----------------------------------------------------------- [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]delay     mov     del_time,  delay_long[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]:loop     djnz    del_time,  #:loop[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]delay_ret ret[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'----------------------------------------------------------- [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]delay_long  long    60_000_00[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]SetDira     long    %00000000_00001111_11111111_00000000[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'segment connections to pins[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_1  long  1<<Pin_4     '15[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_2  long  1<<Pin_2     '13[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_3  long  1<<Pin_1     '12[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_4  long  1<<Pin_3     '14[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_5  long  1<<Pin_6     '17[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_6  long  1<<Pin_7     '18[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]Seg_7  long  1<<Pin_5     '16[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'-----------------------------------------------------------[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'number design  [/SIZE][/FONT][/COLOR] 
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num0   long   %011_11_11[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num1   long   %000_01_01[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num2   long   %111_00_11[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num3   long   %111_01_01[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num4   long   %100_11_01[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num5   long   %111_11_00[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num6   long   %111_11_10[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num7   long   %010_01_01[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num8   long   %111_11_11[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]num9   long   %111_11_01[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]null   long   %000_00_00[/SIZE][/FONT][/COLOR]
     
    
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]del_time   res  1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]select     res  1[/SIZE][/FONT][/COLOR]
     [COLOR=#000000][FONT=Lucida Console, monospace][SIZE=2]'----------------------------------------------------------- [/SIZE][/FONT][/COLOR] 
    
  • HarpritHarprit Posts: 539
    edited 2011-09-22 08:15
    Basic techniques
    Beginners code examples:
    Here is the basic code for looping through any number of lines of code a fixed, given number of times
    {{ Program 022 PASM Repeat loop
    Cog in PASM to demonstrate loop repeat code
     
    }}CON
      _clkmode = XTAL1 + PLL16x
      _xinfreq = 5_000_000
         
    VAR
      long shared
      
    OBJ
      fds: "FullDuplexSerial"
      
    PUB FirstCog                          'displays par value on console,, if set  
      fds.start(31,30,0,115200)           'start console at 115200 for debug output
      cognew(@PCog, @Shared)              'Cog in PASM for 7 Seg display    
      waitcnt(clkfreq/4+cnt)              'wait 1/4 for everything to stabilize.  
      repeat                              'main loop
        fds.tx($1)                        'clear screen
        fds.dec(shared[0])                'display number of loops in PASM code
        fds.tx(" ")                       'print space
        repeat shared[0]                  'subordinate loop
          fds.tx("A")                     'print A for each count
          waitcnt(clkfreq/60+cnt)         'flicker free pause    
    '-----------------------------------------------               
    DAT                                             
              org     0                    'start at 0 location in the cog 
    PCog
    do_it                                  'main loop
              call    #demo_Repeat         'calls sbroutine repeatedly
              jmp     #do_it               'do again
    '-----------------------------------------------          
    demo_Repeat                            'demonstration loop
              mov     repeats,  number     'set up number of cycles
              mov     counter,  #0         'set counter to 0
    :loop
              add     counter,  #1         'add one to counter
              'the code for whatever you want to
              'do for any number of times
              'goes here
              sub     number,   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
              wrlong counter, par           'store in par for display in FirstCog
    demo_Repeat_ret ret
    '------------------------------------------------
    number     long  10
    repeats    res 1
    counter    res 1
    mem        res 1 
    

    Harprit
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-22 21:03
    Harprit wrote: »
    DAT                                             
              org     0                    'start at 0 location in the cog 
    PCog
    do_it                                  'main loop
              call    #demo_Repeat         'calls sbroutine repeatedly
              jmp     #do_it               'do again
    '-----------------------------------------------          
    demo_Repeat                            'demonstration loop
              mov     repeats,  number     'set up number of cycles
              mov     counter,  #0         'set counter to 0
    :loop
              add     counter,  #1         'add one to counter
              'the code for whatever you want to
              'do for any number of times
              'goes here
              sub     number,   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
              wrlong counter, par           'store in par for display in FirstCog
    demo_Repeat_ret ret
    '------------------------------------------------
    number     long  10
    repeats    res 1
    counter    res 1
    mem        res 1 
    
    The first call to demo_Repeat takes about 150 cycles. How long does the second call take?
  • JonnyMacJonnyMac Posts: 9,161
    edited 2011-09-22 22:53
    I'm confused, why would use use two instructions -- especially when one modifies the Z flag which you may want preserved -- when you can use one?
    sub     number,   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
    

    Why not used djnz?
  • HarpritHarprit Posts: 539
    edited 2011-09-23 07:03
    @kuroneko
    Your question is not specific enough for me at my level of expertise. It might have more interest for other readers.
    Do you mean to the beginning of the call or the end of the call and return
    And the same would be true for the second call
    But my guess is almost the same. Though, I do not know and did not run a test.

    @Jon
    That is why you are an expert programmer and I am a beginner.
    Of course you are right though I did not fully appreciate why the status of the Z flag would need preservation beyond its immediate use here. Or for that matter at another time beyond its immediate use though I can see where that may be useful in a complicated logical construct in at more advanced stage of programming proficiency.
    Right now I'm keeping it as simple as possible to follow.

    On another question, I am thinking of providing a short simple example of the use of each instruction in PASM (but not the operators) in the book. But me being a beginner these would be fairly quick, simple constructs. Would that be useful enough to do or it this just another not a very good idea. The PM lacks this feature and I felt I would have benefited from it if it has been there. Comments are invited from all readers of the forum.

    H.

    ps. I'm off to the north woods next week so will not be posting anything.
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-23 07:08
    Harprit wrote: »
    @kuroneko
    Your question not specific enough for me at my level of expertise. It might have more interest for other readers.
    Let me answer it myself, about 11min (@80MHz). Which means something is seriously wrong with that example.
  • HarpritHarprit Posts: 539
    edited 2011-09-23 07:41
    @kuroneko

    The program runs and there is no delay. I run all my programs before posting. There is no delay.
    I don't see a problem in that I am not using the CTR.
    However your observations are very important so I need to take another look.

    AH, I think I see it!!!!
    Apparently, the SPIN cog is repeating the results of the first pass through the PASM cog so I don't see the the hang up on the second pass of the PASM routine. However I don't see why the first pass works at all.
    I will have to check this out after I get back from vacation to see if I got it right.

    Very, very interesting THANK YOU.


    H
  • HarpritHarprit Posts: 539
    edited 2011-10-05 18:11
    OK. I give up
    I have racked my brain as to what is wrong with this and cannot figure it out
    There is certainly something wrong because the subroutine is called only once and then the hangup.
    Help
    H
  • kuronekokuroneko Posts: 3,623
    edited 2011-10-05 18:16
    DAT                                             
              org     0                    'start at 0 location in the cog 
    PCog
    do_it                                  'main loop
              call    #demo_Repeat         'calls sbroutine repeatedly
              jmp     #do_it               'do again
    '-----------------------------------------------          
    demo_Repeat                            'demonstration loop
              mov     [COLOR="blue"]repeats[/COLOR],  number     'set up number of cycles
              mov     counter,  #0         'set counter to 0
    :loop
              add     counter,  #1         'add one to counter
              'the code for whatever you want to
              'do for any number of times
              'goes here
              sub     [COLOR="red"]number[/COLOR],   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
              wrlong counter, par           'store in par for display in FirstCog
    demo_Repeat_ret ret
    '------------------------------------------------
    number     long  10
    repeats    res 1
    counter    res 1
    mem        res 1
    
    For the second call number is 0 which takes a long time to get down to 0 again. You really want to decrement repeats instead.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-10-05 20:09
    kuroneko wrote: »
    DAT                                             
              org     0                    'start at 0 location in the cog 
    PCog
    do_it                                  'main loop
              call    #demo_Repeat         'calls sbroutine repeatedly
              jmp     #do_it               'do again
    '-----------------------------------------------          
    demo_Repeat                            'demonstration loop
              mov     [COLOR="blue"]repeats[/COLOR],  number     'set up number of cycles
              mov     counter,  #0         'set counter to 0
    :loop
              add     counter,  #1         'add one to counter
              'the code for whatever you want to
              'do for any number of times
              'goes here
              sub     [COLOR="red"]number[/COLOR],   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
              wrlong counter, par           'store in par for display in FirstCog
    demo_Repeat_ret ret
    '------------------------------------------------
    number     long  10
    repeats    res 1
    counter    res 1
    mem        res 1
    
    For the second call number is 0 which takes a long time to get down do 0 again. You really want to decrement repeats instead.

    Good to show beginner the verbose way to loop, but follow up with using djnz. It is there, and saves writting an instruction, and as Jon points out, you may not want to mess with the state of the zero flag. The djnz,tjz and tjnz do not alter the Z flag unless you specify it.

    BTW, I may be wrong, but it looks like the code shown here will jump the track again after the first pass. I was hoping that Kuroneko was going to point out that you don't ever want to work directly on cells storing your constants unless you are deliberately altering them for some purpose. That goes for constants stored as part of the code or parameters passed in to the cog. Here, you are moving number into the repeats cell, but then you are actually operating on the constant again. When you head into the loop after the first pass, and you save number to repeat, the first thing you will do is wipe out the only copy of your constant you saved on the first pass. Then you move on and subtract 1 from zero which the core will happily do, and you will be stuck in the loop for 2^32 passes. A good example of what happens when your code wipes out parameters/constants.

    The solution is to create a working cell for the loop count. Start by pre-loading it with the constant prior to entering the loop. Once in the loop, do your thing and test on the working cell and djnz'ing until hitting 0. When you return to repeat, you should at some point hit the preload the working cell again and then call the loop.


    So it looks like
    DAT                                             
    
              org     0                    'start at 0 location in the cog 
    'main loop
    
    do_it   mov     [COLOR="blue"]repeats[/COLOR],  number     'set up number of cycles
              call    #demo_Repeat         'calls sbroutine repeatedly
              jmp     #do_it               'do again
    '-----------------------------------------------          
    demo_Repeat                            'demonstration loop
              mov     counter,  #0         'set counter to 0
    :loop
              add     counter,  #1         'add one to counter
              'the code for whatever you want to
              'do for any number of times
              'goes here
              sub     [COLOR="red"]repeats[/COLOR],   #1   wz     'subtract from number
    if_nz     jmp     #:loop                'do again
              wrlong counter, par           'store in par for display in FirstCog
    demo_Repeat_ret ret
    '------------------------------------------------
    number     long  10
    repeats    res 1
    counter    res 1
    mem        res 1
    


    Frank

    Note that while I said saves writting an instruction, it may not save you an instruction time. The propman states that if the jump is NOT taken then it is a four cycle instruction otherwise it is 8.
  • kuronekokuroneko Posts: 3,623
    edited 2011-10-05 20:55
    BTW, I may be wrong, but it looks like the code shown here will jump the track again after the first pass.
    The code was left as is with emphasis on the mismatch (if that's what you meant). I'd have thought the textual reference to "decrementing repeats" made that clear :)
  • HarpritHarprit Posts: 539
    edited 2011-10-07 07:43
    Thanks guys. It never dawned on me that I had used the wrong variable.
    I have to be gone again till the 18th so I will pick up on this thread again after that
    H
  • HarpritHarprit Posts: 539
    edited 2011-10-23 15:03
    On another thread, I asked if there was an object to read the Chinese DRO scales. No response so far .
    So.....
    Looks like the next exercise for beginners is going to have to be reading a Chinese DRO.
    I need that for my current Mill CNC project.
    Which is why I needed to learn PASM in the first place!
    Lets see if I can do it. (Of course with significant help of the experts here).

    I am getting the hardware set up right now.

    All information will be posted here.
    H
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2011-10-23 16:42
    ''****************************** ''* * ''* Caliper scales counter * ''* * ''* Richard Schultz * ''* * ''* 11 August 2008 * ''* * ''****************************** ''


    http://forums.parallax.com/showthread.php?117331-DRO-using-Chinese-%28caliper%29-scales
  • HarpritHarprit Posts: 539
    edited 2011-10-24 07:41
    Thanks Bob. I'll look the code over and see if I can understand it.
    Then try to create code beginners can understand.
    H
  • HarpritHarprit Posts: 539
    edited 2011-10-26 07:43
    Reading Chinese DRO Scales

    The first thing we need to know is what the interface looks like.

    It is a 4 wire interface. Power, clock, signal and ground.
    Since the battery power is at 1.5 volts, we cannot read the signal directly into the Propeller.
    We need at least 1.65 volts or better. Higher would be even better.
    I am going to use a Op Amp to see if I can read the signal into the Prop.
    I am using a Chinese scale with a standard Little Machine Shop cable.
    The cable plugs into the keyboard connector provided by Parallax to go directly into the Prof
    Dev Board.
    No soldering or other cable modifications are necessary.
    This is good because these cables are quite expensive.
    Those following along can set up accordingly and report how they got a readable signal.
    Next I'll report on the success of this scheme and what I found.


    H
  • HarpritHarprit Posts: 539
    edited 2011-10-26 12:06
    Bad news.
    You cannot use the keyboard connector. Parallax #28060 Rev A
    The data line does not carry through.
    Need to make up special cable connector

    H
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2011-10-28 10:38
    I thought this was interesting:
    [h=3](Data Output on a Scope and Logic Analyzer)[/h] [h=3]Chinese Scale Protocol[/h]
    http://www.shumatech.com/support/chinese_scales.htm#Chinese%20Scale%20Protocol
  • HarpritHarprit Posts: 539
    edited 2011-10-31 07:04
    Bob:

    I read that and everything else I could find on the internet
    Am trying to get a clean TTL signal from that signal at this time.
    Only then can I read it

    H
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2011-10-31 17:21
    re: Am trying to get a clean TTL signal from that signal at this time.
    Only then can I read it


    Are you using Viewport?

    http://hannoware.com/viewport/features.php
  • HarpritHarprit Posts: 539
    edited 2011-11-04 13:15
    Bob:
    Sorry for the delayed response.
    No I am not and I am not familiar with it.
    Right now I am waiting for parts for Jameco etc and getting all the fall preparations that are necessary in this part of the world done so I can settle into some serious experimentation for the winter shut in.
    I will look into your suggestion soon.
    H
  • HarpritHarprit Posts: 539
    edited 2011-11-15 09:59
    All:
    This business of reading scales is a lot harder than I thought. I need more experience.
    I am going to stop on them for now
    I am going back to the book I am writing. I have about 120 pages of notes that need attention
    I guess that's about 1/3 to about 1/2 of the book for beginners for now
    I'm going to organize that work and see what else needs to be done and what else I need to learn
    Then get back to the programming and post back to the group
    It will be a while
    H
  • HarpritHarprit Posts: 539
    edited 2011-11-16 06:51
    Here is my initial outline for the book.
    I am covering what I have in my other books
    How to run motors with Pic micros
    Making PIC Instruments and controllers
    Programming the Prop.
    Except covering the material with programming in PASM

    [FONT=Arial, sans-serif]Outline [/FONT]
    [FONT=Arial, sans-serif]PASM for beginners Propeller 102[/FONT]


    [FONT=Arial, sans-serif]Preface[/FONT]
    [FONT=Arial, sans-serif]Table of contents[/FONT]


    [FONT=Arial, sans-serif]Part one What we have to work with[/FONT]
    [FONT=Arial, sans-serif]Book resources[/FONT]
    [FONT=Arial, sans-serif]OBEX shared resources[/FONT]

    [FONT=Arial, sans-serif]Forum[/FONT]
    [FONT=Arial, sans-serif]Propeller Chip[/FONT]
    [FONT=Arial, sans-serif]This book[/FONT]
    [FONT=Arial, sans-serif]Program listings on the Net[/FONT]
    [FONT=Arial, sans-serif]Propeller manual and how to use it and what it does not tell[/FONT]
    [FONT=Arial, sans-serif]Binary math beginnings[/FONT]
    [FONT=Arial, sans-serif]Simple register manipulations[/FONT]


    [FONT=Arial, sans-serif]Part two Simple Output[/FONT]
    [FONT=Arial, sans-serif]LEDs[/FONT]
    [FONT=Arial, sans-serif]7404 buffers[/FONT]
    [FONT=Arial, sans-serif]The PST Duplex Full Serial interfacing to PST[/FONT]

    [FONT=Arial, sans-serif]Development board[/FONT]
    [FONT=Arial, sans-serif]7 segment displays[/FONT]
    [FONT=Arial, sans-serif]2 lines by 16 char display[/FONT]
    [FONT=Arial, sans-serif]Extended to 4 lines by 20 chars[/FONT]
    [FONT=Arial, sans-serif]Speaker[/FONT]
    [FONT=Arial, sans-serif]Servo motor[/FONT]
    [FONT=Arial, sans-serif]Frequency[/FONT]
    [FONT=Arial, sans-serif]PWM generation[/FONT]


    [FONT=Arial, sans-serif]Part three Simple Input[/FONT]
    [FONT=Arial, sans-serif]read one push button[/FONT]
    [FONT=Arial, sans-serif]read Switches[/FONT]
    [FONT=Arial, sans-serif]Read Keyboard[/FONT]
    [FONT=Arial, sans-serif]read Potentiometer[/FONT]
    [FONT=Arial, sans-serif]read Voltage[/FONT]
    [FONT=Arial, sans-serif]Count pulses.[/FONT]
    [FONT=Arial, sans-serif]read frequency[/FONT]
    [FONT=Arial, sans-serif]1302 interface[/FONT]
    [FONT=Arial, sans-serif]single wire clock/other interface.[/FONT]
    [FONT=Arial, sans-serif]LM34 interface[/FONT]


    [FONT=Arial, sans-serif]Part Four The projects[/FONT]
    [FONT=Arial, sans-serif]Solenoids and relays[/FONT]
    [FONT=Arial, sans-serif]Self leveling Table[/FONT]
    [FONT=Arial, sans-serif]440 cps tone[/FONT]
    [FONT=Arial, sans-serif]Metronome[/FONT]
    [FONT=Arial, sans-serif]Tachometer[/FONT]
    [FONT=Arial, sans-serif]Servo motor R/C[/FONT]
    [FONT=Arial, sans-serif]Temperature reading devices[/FONT]
    [FONT=Arial, sans-serif]Clock chip interfacing[/FONT]
    [FONT=Arial, sans-serif]DC motor[/FONT]
    [FONT=Arial, sans-serif]DC Motor with encoder[/FONT]
    [FONT=Arial, sans-serif]Stepper motors[/FONT]
    [FONT=Arial, sans-serif]Data collection from a solar collector.[/FONT]


    [FONT=Arial, sans-serif]Part five Appendices[/FONT]
    [FONT=Arial, sans-serif]Equipment needs[/FONT]
    [FONT=Arial, sans-serif]PASM words used in text with short meanings.[/FONT]
    [FONT=Arial, sans-serif]Epilogue[/FONT]

    Lets see what it ends up looking like by the time I get done
    Suggestions are welcome

    H
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2011-11-18 10:37
    Introduction) A basic explanation of why PASM isn't magic.

    1) Basic components of the Propeller

    2) Free tools used in the book

    3) Number and logic systems, addition, and subtraction

    4) Organization of a PASM program

    5) Introduction to PASM

    6) Flags

    7) Flow control

    8) Logic instructions, and counters

    9) Hub and cog ram

    10) Arrays and addressing modes

    11) Strings and Text display

    12) IC communication protocols

    13) Multiple cogs

    This my idea of how a book should be laid out, similar to a college text book.

    Respectfully, I think there is drawbacks to the number of projects, the cost involved.
    Also, I think, a book format that uses projects as titles reduces the books worth as a post
    reference material.

    On the other hand, I previously posted that I learn best when I use my hands--working on a project that is important to me.
    Constant rereading of a section, or chapter drives me crazy-- like some over-edited calculus or physics books.
    I am certain you can create readable a format that is both interesting, and covers the basics I outlined.
    Something that would become a good post reference material.

    A font selection like "Sabon" would help readability too.

    Bill M.




    It would be great if the book continued on to to at least cover:

    I/O functions

    Graphics

    Advanced Math
  • HarpritHarprit Posts: 539
    edited 2011-11-19 10:06
    Capt:

    Added your list to mine. Some additions are a must but I felt some might be too much for beginners. Will consider everything you said as I get along. Thanks

    H
Sign In or Register to comment.