Shop OBEX P1 Docs P2 Docs Learn Events
My prochip never works? — Parallax Forums

My prochip never works?

olivertogolivertog Posts: 3
edited 2008-12-06 21:20 in Propeller 1
why this will not work? I cant get any thing to follow th repeat command either?

con
_clkmode = Xtal1
_clkfreq = 5_000_000

var
long stack[noparse][[/noparse]9]

pub main
cognew(inverter, @stack)


PUB Inverter
dira ~
dira[noparse][[/noparse]6..7]~~
waitpeq(%10, %10, 0)
outa[noparse][[/noparse]6]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]6]~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~~
waitcnt(4_000_000 + cnt)
outa[noparse][[/noparse]7]~
waitpeq(%00, %10, 0)
inverter

Comments

  • P!-RoP!-Ro Posts: 1,189
    edited 2008-12-06 00:48
    If I counted right, you need more stack space than you are allowing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PG
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-06 00:50
    1) The system clock is running at 5MHz, not 80MHz which is what is normally used. You need "_clkmode = xtal1 + pll16x" to make it 80MHz. At 5MHz, the WAITCNTs will be slower by a factor of 16.

    2) At the end of Inverter, you have a recursive call to Inverter. This will very quickly use up the limited stack space and eventually start to fill up memory with stack frames from these calls without returns. A good initial stack space for simple routines without calls to other routines is 20 levels.

    3) You didn't explain what happened or what you expected to happen.
  • olivertogolivertog Posts: 3
    edited 2008-12-06 01:23
    dira~
    dira[noparse][[/noparse]6..7]~~
    waitpeq(%10, %10, 0)

    this is what my original code looks like, I want it to wait for me to make pin 1 high, then continue
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-06 01:49
    That's what it should do, set pins 6 and 7 as outputs, wait for pin 1 to become high, then continue.

    Notice that the main cog will quit after the COGNEW, but leave the 2nd cog running. This is because the implicit return from the PUB main goes to a cogstop.
  • olivertogolivertog Posts: 3
    edited 2008-12-06 16:53
    My problem is the waitpeq dosnt wait, Will it wait for ever? IF I have pin 1 high and run the program it works fine, if I have pin 1 low run program it hould be waiting for pin 1 to go high, correct? if I then make pin 1 high i get nothing like the program terminated. What could be my simple problem? If I also try and make repeat loops that are very simple they only reapeat 4 times then quit??
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-06 19:19
    REPEAT loops normally work. The WAITPEQ/PNE should work. There must be something else going on, perhaps unrelated to your program. Post a schematic of your setup and a copy of the program that you're testing (after you fix the stack size and _clkmode statement)
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-12-06 21:20
    Hello Oliver,

    in your thread-headline you suspected the propeller-CHIP not to work
    this could be easily checked by loading one of the example-codes

    one more or less obvoius thing:

    the numbers of the IO-Pin start at ZERO so Pin 1 is the SECOND Pin .


    There are two errors inside the code that you posted

    first error: stacksize

    you defined

    var
      long stack[noparse][[/noparse]9]
    
    
    



    a stacksize of 9 is not enough in most cases
    if the stack is too small your program can crash immediatly

    take a size of 20 longs and sometimes it will be nescessary to take 200 longs

    var
      long stack[noparse][[/noparse]20]
    
    
    




    second:

    if you call the method Inverter INSIDE itself this is RECURSIVE
    This will eat up ALL THE 32kB of RAM after some time and then your program crashes down

    if the code inside the method Inverter should be repeated you MUST use a repeat-loop

    this code works properly

    con
    _clkmode = Xtal1
    _clkfreq = 5_000_000
    
    var
      long stack[noparse][[/noparse]20]
      
    pub main
      cognew(inverter, @stack)
    
    PUB Inverter
      repeat
        
        dira[noparse][[/noparse]6..7]~~
        waitpeq(%10, %10, 0)
        outa[noparse][[/noparse]6]~~
        waitcnt(4_000_000 + cnt)
    
        outa[noparse][[/noparse]6]~
        waitcnt(4_000_000 + cnt)
    
        outa[noparse][[/noparse]7]~~
        waitcnt(4_000_000 + cnt)
    
        outa[noparse][[/noparse]7]~
        waitpeq(%00, %10, 0)
        
    
    




    some more hints:

    use a clock of 80 MHz

    CON    
      _clkmode = xtal1 + pll16x    'instead of  " _clkmode = xtal1"
      _xinfreq = 5_000_000
    
    



    use ClkFreq instead of harcoded numbers in waitcnt

    "ClkFreq + cnt" means a delay of 1 second

    "ClkFreq / 10 + cnt" means a delay of 0,1 second

    "ClkFreq * 5 + cnt" means a delay of 5 seconds

        waitcnt(ClkFreq / 4 + cnt) ' wait for 0.25 seconds
    
    
    



    best regards

    Stefan
Sign In or Register to comment.