Shop OBEX P1 Docs P2 Docs Learn Events
cognew command freezes propeller chip — Parallax Forums

cognew command freezes propeller chip

tony_89tony_89 Posts: 14
edited 2009-09-08 19:19 in Propeller 1
I've tried many different approaches to solving this problem. The cognew command on line 39 should send the lcdbl pub into a new cog. The lcdbl pub is designed to turn on the blacklight when any of the input buttons are pressed. The program should launch this into a new cog and continue on to the main pub. If anyone can solve this problem please help. I've been trying to fix it for about 6 hours now... I'm a newbie to propeller. The attachment manager is not working so i had to copy paste. sorry for the inconvenience!!

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000


LCD_PIN = 14
LCD_BAUD = 19_200
LCD_LINES = 2
var
byte set_temp, set_freq, set_amps, temp,temp_max ,temp_min, value
long stack[noparse][[/noparse]1000]

OBJ
lcd: "debug_lcd"

pub ini


if lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES) ' start lcd
lcd.cursor(0) ' cursor off
lcd.backLight(true) ' backlight on (if available)
lcd.cls ' clear the lcd
lcd.str(string("Hydrogen", 13 ,"thermostat"))

waitcnt(clkfreq *1 + cnt)
lcd.cls
lcd.str(string(129,"designed by:", 13," Anthony Ford"))
waitcnt(clkfreq *1 + cnt)
lcd.cls

lcd.str(string(" Initialization", 13))
repeat 16
waitcnt(clkfreq/10 +cnt)
lcd.str(string("-"))

lcd.str(string(152, "complete"))
waitcnt(clkfreq * 1 +cnt)
lcd.cls

cognew ((lcdbl), @ stack)
main

dira [noparse][[/noparse]0..3]~
dira [noparse][[/noparse]4..6]~~



pub main
temp:= 75
if set_temp == 0
set_temp := 50
lcd.cls
lcd.str(string(137,"set:",156,"temp:"))
repeat

if ina[noparse][[/noparse]0]==0
waitcnt(clkfreq/2 + cnt)
set_temp ++
set_temp <#= temp_max

if ina==0
waitcnt(clkfreq/2 + cnt)
set_temp --
set_temp #>= temp_min

if ina ==0
menu
lcd.str(string(142))
lcd.dec(set_temp)
lcd.str(string(162))
lcd.dec(temp)


pub menu
lcd.cls
lcd.str(string(134,"menu"))
waitcnt(clkfreq*1 + cnt)
lcd.str(string(132,"set amps"))
waitcnt(clkfreq/2 + cnt)

repeat until ina ==0
if ina ==0
lcd.cls
lcd.str(string("set amps:"))
waitcnt(clkfreq*1 +cnt)
menu_set(set_amps,1,50)
set_amps := value
main

lcd.cls
lcd.str(string(134,"freq"))
waitcnt(clkfreq*1 + cnt)
repeat until ina ==0
if ina ==0
lcd.cls
lcd.str(string("set freq:"))
waitcnt(clkfreq*1 +cnt)
menu_set(set_freq,1,125)
set_freq := value
main

lcd.cls
lcd.str(string(129,"temp max"))
waitcnt(clkfreq*1 + cnt)
repeat until ina ==0
if ina ==0
lcd.cls
lcd.str(string("set maxtemp:"))
waitcnt(clkfreq*1 +cnt)
menu_set(temp_max,1,200)
temp_max := value
main

lcd.cls
lcd.str(string(129,"temp min"))
waitcnt(clkfreq*1 + cnt)
repeat until ina ==0
if ina ==0
lcd.cls
lcd.str(string("set min:"))
waitcnt(clkfreq*1 +cnt)
menu_set(temp_min,1,200)
temp_min := value
main
waitcnt(clkfreq*1 +cnt)
main

pub menu_set(set_value,min_value,max_value)
repeat
if ina[noparse][[/noparse]0]==0
set_value ++
set_value <#= max_value
waitcnt(clkfreq/2 + cnt)
if ina==0
set_value --
set_value #>= min_value
waitcnt(clkfreq/2 + cnt)
if ina ==0
lcd.cls
lcd.str(string("changes saved",13))
waitcnt(clkfreq*1 +cnt)
value := set_value
return
if ina ==0
lcd.cls
lcd.str(string("changes aborted",13))
waitcnt(clkfreq*1 +cnt)
main
lcd.str(string(140))
lcd.dec(set_value)



pub lcdbl
repeat
if ina[noparse][[/noparse]0] ==0
outa~~
waitcnt(clkfreq * 2 + cnt)
outa~
if ina ==0
outa~~
waitcnt(clkfreq * 2 + cnt)
outa~

if ina ==0
outa~~
waitcnt(clkfreq * 2 + cnt)
outa~

if ina ==0
outa~~
waitcnt(clkfreq * 2 + cnt)
outa~
waitcnt(clkfreq *1 + cnt)

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-08 16:03
    tony,

    Please copy and paste your code here: www.phipi.com/format, click Format, and repost the result. This will preserve your indents and subscripting so the program is readable. As it stands, it is not.

    Thanks,
    -Phil
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 16:06
    I was using google chrome when I used this post earlier. I couldn't use the attachment manager in chrome. After I posted, however, I tried using internet explorer and it worked great. Here is the code with which I am having trouble.
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-09-08 16:10
    Use the code command to post code in the forum.

    
    this is what code will look like in a code command
    
    
    



    Are you sure it makes it to the cognew command? Is it possible its locking up before that?
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 16:15
    If I take out the cognew command, then the program runs great other than the lcdbl pub. If I leave the cognew command in, the program will progress to the·stage where·the lcd screen·says "complete." Then the·screen clears and everything freezes.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-08 16:17
    tony_89,

    The website I linked to will do all your formatting for you, including adding the [noparse][[/noparse]code] tags and protecting your subscripts (which the [noparse][[/noparse]code] tags alone will not do). It will work with any browser. That's why I suggested it.

    -Phil
  • SamMishalSamMishal Posts: 468
    edited 2009-09-08 16:18
    Tony, and any one reading this.....
    There is an attachment manager in the posting editor...see button at the
    bottom of the editor screen.

    INSTEAD of posting a LONG LONG unformatted code that is a load of
    USELESS text
    WHY NOT ATTACH your .Spin file......only post code fragments that you need
    to talk about· in the posting. BUT.... use the #·button
    from the Speed Buttons
    at the top of posting editor.
    Check out your postings editor....it has tools you can use to make your posting more readable.
    Also at the bottom of the edit area there is a button labeled "Attachment Manager"
    USE this to attach your Spin files.....we can read them a lot better using our
    Propeller Tool than the unformatted LENGTHY LENGTHY waste of space
    .
    Also this helps people read your code and test it and that way can help you better
    with your problem.

    The posting Editor is not very different from most editors you have used. TAKE A MINUTE
    to LOOK at
    it and figure out how to use it.
    ALSO ....if you need to practice use the Test Forum·on this site.
    ·
    Regards
    Samuel
    ·
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 16:19
      [b]_clkmode[/b] = [b]xtal1[/b] + [b]pll16x[/b]                       
      [b]_xinfreq[/b] = 5_000_000
    
    
      LCD_PIN   = 14                        
      LCD_BAUD  = 19_200
      LCD_LINES = 2
    [b]var[/b]
    [b]byte[/b] set_temp, set_freq, set_amps, temp,temp_max ,temp_min, value
    [b]long[/b] stack[noparse][[/noparse]&#173;1000&#093;
    
    [b]OBJ[/b]
    lcd: "debug_lcd"
    
    [b]pub[/b] ini
    
    
    [b]if[/b] lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES)             ' start lcd
        lcd.cursor(0)                                       ' cursor off
        lcd.backLight([b]true[/b])                                 ' backlight on (if available)
        lcd.cls                                             ' clear the lcd
        lcd.[b]str[/b]([b]string[/b]("Hydrogen", 13 ,"thermostat"))
    
      [b]waitcnt[/b](clkfreq *1 + [b]cnt[/b])
      lcd.cls         
      lcd.[b]str[/b]([b]string[/b](129,"designed by:", 13,"  Anthony Ford"))
      [b]waitcnt[/b](clkfreq *1 + [b]cnt[/b])
      lcd.cls
    
     lcd.[b]str[/b]([b]string[/b](" Initialization", 13))
      [b]repeat[/b] 16
        [b]waitcnt[/b](clkfreq/10 +[b]cnt[/b])
          lcd.[b]str[/b]([b]string[/b]("-"))
    
      lcd.[b]str[/b]([b]string[/b](152, "complete"))
       [b]waitcnt[/b](clkfreq * 1 +[b]cnt[/b])
        lcd.cls
    
      [b]cognew[/b] ((lcdbl), @ stack)
     main
     
        [b]dira[/b] [noparse][[/noparse]&#173;0..3&#093;~
        [b]dira[/b] [noparse][[/noparse]&#173;4..6&#093;~~
    
    
    
    [b]pub[/b] main
    temp:= 75
      [b]if[/b] set_temp == 0
       set_temp := 50
    lcd.cls
    lcd.[b]str[/b]([b]string[/b](137,"set:",156,"temp:"))
    [b]repeat[/b]
    
         [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;0&#093;==0
          [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
            set_temp ++
             set_temp <#= temp_max
          
        [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;1&#093;==0
          [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
           set_temp --
            set_temp #>= temp_min
            
        [b]if[/b] [b]ina[/b] [noparse][[/noparse]&#173;2&#093; ==0
          menu
        lcd.[b]str[/b]([b]string[/b](142))
        lcd.dec(set_temp)
        lcd.[b]str[/b]([b]string[/b](162)) 
        lcd.dec(temp)
        
    
    [b]pub[/b] menu
      lcd.cls
      lcd.[b]str[/b]([b]string[/b](134,"menu"))  
      [b]waitcnt[/b](clkfreq*1 + [b]cnt[/b])
      lcd.[b]str[/b]([b]string[/b](132,"set amps"))
      [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
    
    [b]repeat[/b] [b]until[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0   
       [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;3&#093; ==0
        lcd.cls
        lcd.[b]str[/b]([b]string[/b]("set amps:"))
        [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
          menu_set(set_amps,1,50)
         set_amps := value
        main
        
    lcd.cls
    lcd.[b]str[/b]([b]string[/b](134,"freq"))
     [b]waitcnt[/b](clkfreq*1 + [b]cnt[/b])
    [b]repeat[/b] [b]until[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0
       [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;3&#093; ==0
        lcd.cls
        lcd.[b]str[/b]([b]string[/b]("set freq:"))
        [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
          menu_set(set_freq,1,125)
          set_freq := value
        main
    
    lcd.cls
    lcd.[b]str[/b]([b]string[/b](129,"temp [b]max[/b]"))
    [b]waitcnt[/b](clkfreq*1 + [b]cnt[/b])
    [b]repeat[/b] [b]until[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0
       [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;3&#093; ==0
        lcd.cls
        lcd.[b]str[/b]([b]string[/b]("set maxtemp:"))
        [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b]) 
          menu_set(temp_max,1,200)
           temp_max := value
        main
    
    lcd.cls                    
    lcd.[b]str[/b]([b]string[/b](129,"temp [b]min[/b]"))
    [b]waitcnt[/b](clkfreq*1 + [b]cnt[/b])
    [b]repeat[/b] [b]until[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0
      [b]if[/b] [b]ina[/b] [noparse][[/noparse]&#173;3&#093; ==0
        lcd.cls
        lcd.[b]str[/b]([b]string[/b]("set [b]min[/b]:"))
        [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
        menu_set(temp_min,1,200) 
        temp_min := value
        main
     [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
    main  
    
    [b]pub[/b] menu_set(set_value,min_value,max_value) 
    [b]repeat[/b]
      [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;0&#093;==0
             set_value ++
             set_value <#= max_value
          [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
      [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;1&#093;==0
            set_value --
            set_value #>= min_value
            [b]waitcnt[/b](clkfreq/2 + [b]cnt[/b])
     [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0
      lcd.cls
      lcd.[b]str[/b]([b]string[/b]("changes saved",13))  
      [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
      value := set_value
      [b]return[/b]
     [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;3&#093; ==0
      lcd.cls
      lcd.[b]str[/b]([b]string[/b]("changes aborted",13))
      [b]waitcnt[/b](clkfreq*1 +[b]cnt[/b])
      main
     lcd.[b]str[/b]([b]string[/b](140))
     lcd.dec(set_value)
    
    
       
    [b]pub[/b] lcdbl
       [b]repeat[/b]
        [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;0&#093; ==0
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~~
         [b]waitcnt[/b](clkfreq * 2 + [b]cnt[/b])
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~
        [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;1&#093; ==0
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~~
         [b]waitcnt[/b](clkfreq * 2 + [b]cnt[/b])
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~
        
        [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;2&#093; ==0
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~~
         [b]waitcnt[/b](clkfreq * 2 + [b]cnt[/b])
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~
        
        [b]if[/b] [b]ina[/b][noparse][[/noparse]&#173;3&#093; ==0
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~~
         [b]waitcnt[/b](clkfreq * 2 + [b]cnt[/b])
         [b]outa[/b][noparse][[/noparse]&#173;4&#093;~
        [b]waitcnt[/b](clkfreq *1 + [b]cnt[/b])
       
         
    
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 16:22
    1) In quite a few places you have a call to "main" that, in turn, calls "menu" which calls "main" again. This is recursion and you'll rapidly run out of stack space. Typically people try this when they're trying to do a GOTO rather than using a REPEAT loop, but it doesn't work.

    2) The source code you've posted ("temp buttons.spin") doesn't have a COGNEW anywhere in it. From the original cut and paste, you had "cognew ((lcdbl), @ stack)". The "(lcdbl)" is incorrect. Please read the Propeller Manual section on the COGNEW statement. "lcdbl" without the parentheses would be correct.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-08 16:27
    tony_89,

    Thanks. Much better.

    Each cog has its own dira. Setting a bit in dira in one cog does not make it an output in another. Once you've made the corrections Mike has suggested, you may want to address this issue.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 9/8/2009 4:40:55 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 16:38
    3) You really need to clean up your indenting. It makes it very difficult to follow your code. Indenting is important in Spin.

    4) You could use ABORT to quit everything out to a certain level. In "init", you have a call to "main". You could change this to:
    repeat \main
    

    and everywhere you have a call to "main" that's intended to exit back to the top of "main", you'd put ABORT. Read the Propeller Manual section on the ABORT statement.

    5) What's this "INA[noparse][[/noparse] -1 ]"? There are no negative pin numbers. Spin uses just the least significant 5 bits of the pin number, so a -1 is the same as 31.

    Post Edited (Mike Green) : 9/8/2009 4:44:15 PM GMT
  • jazzedjazzed Posts: 11,803
    edited 2009-09-08 16:49
    The attachment manager does not work with the Google Chrome web browser.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 16:52
    How about using another web browser when you need to use the attachment manager? Maybe something like Firefox?
  • jazzedjazzed Posts: 11,803
    edited 2009-09-08 16:54
    Yup, that's what I do [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 17:04
    I took the cognew ((lcdbl),@stack) and changed it to·cognew (lcdbl,@stack) works great now--i will post it below.·I do not have a problem with cycling between menu and main unless i disconnect the pb switches i am desiging on a develoment board. i still have a lot to write on this code it is going to eventually replace a basic stamp code that i wrote. the spin code has some extra new features. i post·the basic stamp code below--it is really messy because it is a cut paste and modify from a lot of dif places but it works perfect. the next thing i am trying to find out is how to save my·set temp set amp set frerq and·temp·mini temp max into the eprom·the code to do this will go in line 41 i think.··Thanks for everyone's help!!!
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 17:14
    In the lcdbl pub how could i write the code to say that if ina [noparse][[/noparse]0..4] {if any of these =1 then } outa 4 .

    Sorry for the simple questions i have only been working with propeller for 13 days but i need to complete my design asap.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 17:15
    I guarantee that you will have all kinds of problems if you don't remove the potential recursion in your program. It's best to fix it now so you don't have to go back and rewrite your whole program later when it's even more complex.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 17:16
    "if ina[noparse][[/noparse] 0..4 ] <> 0"
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 17:23
    Mike i now see what u are saying about the potential recursion it is messing up when it get to that part of the code. How would u fix it.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 17:46
    Here's one example. I haven't changed what I think is your logic. I've cleaned up what I think is your indenting and eliminated the recursion.
  • tony_89tony_89 Posts: 14
    edited 2009-09-08 18:27
    I·made some changes so that the code would run.·I have them listed in the attached spin file, please see if these changes are ok i also have a question about eprom on there.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 18:40
    Sorry about the extra "abort true". I got carried away.

    Look at the "Basic_I2C_Driver" from the Object Exchange. You can use the routines in that to read and write EEPROM locations. The end of the EEPROM is usually unused (from the end of your program to the end of the EEPROM) and is not changed until you download a new program to the EEPROM. Typically you store persistent information starting at the end. If you need to store a 32-bit value, start at $7FFC and work downwards. The unused EEPROM is normally zeroed by the boot downloader.
  • RaymanRayman Posts: 14,849
    edited 2009-09-08 18:58
    I find it strange that cognew ((lcdbl),@stack) doesn't work... What does it do? Does it load up a cog as assembly at the address of the LCDBL routine?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-09-08 19:10
    No, it starts an assembly cog at the address returned by a call to lcdbl.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 19:13
    I believe it calls "lcdbl" and uses the returned value (zero in this case) as the address of an assembly routine to load into the cog.
  • RaymanRayman Posts: 14,849
    edited 2009-09-08 19:19
    Ok, that actually makes sense now that you both say it...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Sign In or Register to comment.