Shop OBEX P1 Docs P2 Docs Learn Events
* Answered * The second bit of code does not run — Parallax Forums

* Answered * The second bit of code does not run

PliersPliers Posts: 280
edited 2011-02-06 05:26 in Propeller 1
I'm trying to get a second COG running a counter.
The first cog launches and the counter works, the second cog does not work.
I think the code is self explanatory.
If you are not familiar with View Port, some of the stuff might seem strange.

The problem is how I'm launching the second COG, I think.
Con     _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
 
VAR
  long parameter1
  long parameter2

  long frame[400]                    'stores measurements of INA port
 
OBJ                                  ' include 2 ViewPort objects:
 vp    : "Conduit"                   ' transfers data to/from PC
 qs    : "QuickSample"      'samples INA continuously in 1 cog- up to 20Msps
Pub go 
 vp.register(qs.sampleINA(@frame,1)) 'sample INA into <frame> array
 optional_configure_viewport         'optionally configure viewport's interface   
 vp.share(@parameter1,@parameter2)   'share the <freq> variable
 parameter2 :=80                    ' 80 percent duty cycle
 parameter1 :=50                     ' 50 percent duty cycle
 
cognew(@entry, @parameter1)    'Starting a new cog in assembly code.
      
cognew(@entry2, @parameter2)    'Starting a second cog in assembly code.
   repeat        

pub optional_configure_viewport  
vp.config(string("var:io(bits=[mine[0..5]]),Parameter,Parameter2"))
vp.config(string("start:lsa"))
vp.config(string("dso:timescale=10ms"))
vp.config(string("lsa:view=io,trigger=io[0]r,timescale=500ns"))
vp.config(string("edit:Parameter(mode=text),Parameter2(mode=text)"))
    

Dat
        org
entry   mov dira, diraval     'set APIN to output
        mov ctra, ctraval     'establish counter A mode a Apin
        mov frqa, #1          'set counter to increment by 1

        mov time, cnt            'record current time
        add time, period        'establish next period

:loop   rdlong value, par       'get an up to date pulse width
        waitcnt time, period    'wait until next period
        neg phsa, value         'back up phsa so that it trips "value" cycles from now
        jmp #:loop
  
        
entry2   mov dira, diraval2     'set APIN to output
        mov ctra, ctraval2     'establish counter A mode a Apin
        mov frqa, #1          'set counter to increment by 1
        mov time2, cnt            'record current time
        add time2, period2        'establish next period

:loop2   rdlong value2, par       'get an up to date pulse width
        waitcnt time2, period2    'wait until next period
        neg phsa, value2         'back up phsa so that it trips "value" cycles from now
        jmp #:loop2

diraval long |< 0                ' APIN = 0
ctraval long %00100 << 26 + 0    ' NCO/PWM APIN = 0
period  long 100                 ' 800 khz period (_clkfreq/period)        


diraval2 long |< 2                ' APIN = 2
ctraval2 long %00100 << 26 + 2    ' NCO/PWM APIN = 2
period2  long 100                 ' 800 khz period (_clkfreq/period)  

time2 res 1
value2 res 1

time res 1
value res 1

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-06 05:21
    Try this:
    Dat     org     0
    
    entry   mov dira, diraval     'set APIN to output
            mov ctra, ctraval     'establish counter A mode a Apin
            mov frqa, #1          'set counter to increment by 1
    
            mov time, cnt            'record current time
            add time, period        'establish next period
    
    :loop   rdlong value, par       'get an up to date pulse width
            waitcnt time, period    'wait until next period
            neg phsa, value         'back up phsa so that it trips "value" cycles from now
            jmp #:loop
      
    [COLOR="blue"]diraval long |< 0                ' APIN = 0
    ctraval long %00100 << 26 + 0    ' NCO/PWM APIN = 0
    period  long 100                 ' 800 khz period (_clkfreq/period)        
    
    time res 1
    value res 1[/COLOR]
    
    DAT     [COLOR="red"]org     0[/COLOR]
    
    entry2   mov dira, diraval2     'set APIN to output
            mov ctra, ctraval2     'establish counter A mode a Apin
            mov frqa, #1          'set counter to increment by 1
            mov time2, cnt            'record current time
            add time2, period2        'establish next period
    
    :loop2   rdlong value2, par       'get an up to date pulse width
            waitcnt time2, period2    'wait until next period
            neg phsa, value2         'back up phsa so that it trips "value" cycles from now
            jmp #:loop2
    
    [COLOR="blue"]diraval2 long |< 2                ' APIN = 2
    ctraval2 long %00100 << 26 + 2    ' NCO/PWM APIN = 2
    period2  long 100                 ' 800 khz period (_clkfreq/period)  
    
    time2 res 1
    value2 res 1[/COLOR]
    
    Main issue, your second code block was missing an org 0. As this affects long/res as well those should be kept in their respective org scope (using multiple DAT section helps).
  • PliersPliers Posts: 280
    edited 2011-02-06 05:26
    That worked.
    Thank you very very much.
Sign In or Register to comment.