Shop OBEX P1 Docs P2 Docs Learn Events
Propeller randomly stops executing Spin Code — Parallax Forums

Propeller randomly stops executing Spin Code

DarkWarriorDarkWarrior Posts: 5
edited 2014-01-12 16:05 in Propeller 1
Hi,
I ran into an issue with the Propeller which I cant solve myself. It seems to me that the Propeller randomly stops executing SPIN code. Running PASM code in a seperat cog is working fine.
I wrote a simple program which blinks leds in 3 different ways.
1. Start a cog with PASM Code
2. Start an additional cog with SPIN Code
3. Run SPIN Code on the main cog

Both methods which execute SPIN code stop toggling the LED after a few seconds. Sometimes the LED dont even blink once.
Number 2 with PASM code is toggling the LED endlessly and is unaffected when the other Methods stops.

Methods 2 or 3 stops after a few seconds and the LEDs. But Method 3 is unaffected and toggles endlessly the Led´s.

I also have to say that i have problems programming with the Serial Port. I need several tries until the Propeller tool finds the Propeller on the Port, maybe this can be a reason for this odd behaviour.

So can it be that the Propeller is broken ?
CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000
   
PUB public_method_name

  'start a cog with PASM code
  cognew(@entry,0)

  'start an additional cog with SPIN code
  cognew(blink,0)

  'use current cog
  dira[16] := 1
  repeat
    waitcnt(cnt + 20_000_000)
    !outa[16]     

PUB blink
  dira[18] := 1
  repeat
    waitcnt(cnt + 20_000_000)
    !outa[18]     

DAT
                        org
entry                   mov     r0,#1
                        shl     r0,#17
                        mov     dira,r0

loop                    xor     outa,r0
                        mov     r1,cnt
                        add     r1,wait
                        waitcnt r1,#0
                        jmp     #loop                    
    

r0      long  1
r1      long  1
wait    long  20_000_000
       

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2014-01-10 07:12
    You're missing the stack for the Spin cog for "blink" and the Spin interpreter is using memory starting at location 0. Unfortunately, the first few locations in memory contain crucial information and they're overwritten by the "blink" routine as it executes. Look at the section in the Propeller Manual on the COGNEW statement.
  • DarkWarriorDarkWarrior Posts: 5
    edited 2014-01-10 07:55
    So i try this and its the same problem , i have also problems running the graphic demo´s they dont work. So thats why i try to figure it out with this blink code. I think that the propeller hang up after short time total randomly sometimes the 2 leds with spin code work first then hang up or they dont work from beginning.
  • T ChapT Chap Posts: 4,223
    edited 2014-01-10 07:58
    Can you post the newest code?
  • DarkWarriorDarkWarrior Posts: 5
    edited 2014-01-10 08:06
    CON
    {Object_Title_and_Purpose}
    
    
    CON
            _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
            _xinfreq = 5_000_000
    
    VAR
      long  symbol
      long  stack[10]
       
    PUB public_method_name
      dira[16] := 1
      cognew(@entry,0)
      cognew(blink,@stack)
      repeat
        waitcnt(cnt + 20_000_000)
        !outa[16]  
    
    PUB blink
      dira[18] := 1
      repeat
        waitcnt(cnt + 20_000_000)
        !outa[18]     
    
    DAT
                  org
    entry                   mov     r0,#1
                            shl     r0,#17
                            mov     dira,r0
    
    loop                    xor     outa,r0
                            mov     r1,cnt
                            add     r1,wait
                            waitcnt r1,#0
                            jmp     #loop                    
                            
    
    
    r0      long  1
    r1      long  1
    wait    long  20_000_000
            
           
    

    and when i deleted the method like this its still the same
    CON
    {Object_Title_and_Purpose}
    
    
    CON
            _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
            _xinfreq = 5_000_000
    
    VAR
      long  symbol
       
    PUB public_method_name
      dira[16] := 1
      cognew(@entry,0)
      repeat
        waitcnt(cnt + 20_000_000)
        !outa[16]  
    
    DAT
                  org
    entry                   mov     r0,#1
                            shl     r0,#17
                            mov     dira,r0
    
    loop                    xor     outa,r0
                            mov     r1,cnt
                            add     r1,wait
                            waitcnt r1,#0
                            jmp     #loop                    
                            
    
    
    r0      long  1
    r1      long  1
    wait    long  20_000_000
            
    
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-10 08:19
    There is something else afoot -- did you build your own hardware.

    Here's an example of blinking three LEDs: one with PASM, one in a secondary Spin cog, one in the main Spin cog. This is running on a demo board so I know it works.
    con  
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000                                          ' use 5MHz crystal
    
    
    var
    
      long  spinstack[16]
    
    
    pub main | t
    
      pbmask := 1 << 16                                             ' mask for pin 16
      pbdelaytix := clkfreq / 1000 * 250
      cognew(@pasmblink, 0)                                         ' start pasm cog
    
      
      cognew(spin_blink(17, 250), @spinstack)                       ' start spin cog
    
    
      ' run in main cog
    
      dira[18] := 1                                                 ' make output
    
      t := cnt                                                      ' sync with system
      repeat
        outa[18] := 1                                               ' high
        waitcnt(t += (clkfreq / 1000 * 250))                         ' wait
        outa[18] := 0                                               ' low
        waitcnt(t += (clkfreq / 1000 * 250))                         ' wait
    
    
    
    
    pri spin_blink(pin, ms) | t                                     ' launch with cognew
    
      dira[pin] := 1                                                ' make output
    
      t := cnt                                                      ' sync with system
      repeat
        outa[pin] := 1                                              ' high
        waitcnt(t += (clkfreq / 1000 * ms))                         ' wait
        outa[pin] := 0                                              ' low
        waitcnt(t += (clkfreq / 1000 * ms))                         ' wait
    
    
    dat
    
                            org     0
                            
    pasmblink               mov     tix, pbdelaytix                 ' setup delay
                            add     tix, cnt                        ' sync with system
                            or      dira, pbmask                    ' make output
    
    :loop                   or      outa, pbmask                    ' high
                            waitcnt tix, pbdelaytix                 ' wait
                            andn    outa, pbmask                    ' low
                            waitcnt tix, pbdelaytix                 ' wait
    
                            jmp     #:loop
    
    ' ---------------------------------------------------------------------------------------
    
    pbmask                  long    0-0
    pbdelaytix              long    0-0
    
    tix                     res     1
    
                            fit     496
    
  • DarkWarriorDarkWarrior Posts: 5
    edited 2014-01-10 08:43
    Yeah its an DIL40 Propeller build up like its in the Datasheet with an external EEprom and an 5 Mhz Crystal and the 4 Resistors. I program it with an Usb to Serial adapter with the build up also from the Datasheet.

    Your Code seems to work.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-10 09:17
    It's a small thing and not likely to be causing trouble, but make sure you have a 0.1uF cap between the Vdd and Vss pins on either side of the chip.

    I ran your second program (above my last post) and it seems to work fine.
  • DarkWarriorDarkWarrior Posts: 5
    edited 2014-01-12 08:12
    So today i found more time to Test.

    I have now 0,1uF caps there, and it seem all the codes with the Led´s work fine.

    But the Problem with the Grafic Demos are still there , they are little bit better but not much.
    When i take the GraficsTest.spin that comes with the Propeller Tool, i get only a Black and White screen that starts moving for short time (0.5 - 1,5 sec sometimes 3-5 but not very often) and then hang up.
    I Try other Grafic demos too but non of them work fine, i checked the Crystal and the Resistors.

    So any ideas what´s the Problem ?
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-01-12 16:05
    Circuit fabrication? If adding the 0.1 caps fixed other problems that seems to indicate that you circuit construction is creating an issue. Why don't you post a photo of your setup so that others can give you meaningful guidance.
Sign In or Register to comment.