Shop OBEX P1 Docs P2 Docs Learn Events
simple programming hurdle — Parallax Forums

simple programming hurdle

shmowshmow Posts: 109
edited 2008-04-04 06:55 in Propeller 1
·Here's the lowdown:
-I'm trying to control a cog (and see it's status too) but I'm not sure if I've done it correctly programming-wise
-when the cog is running a piezo is energized (I've fiddled with the times: piezo and waitcnt command)
and the piezo "fumbles" its sound when the cog stops before piezo is finished
-a LED is supposed to energize when the cog is running but alas it doesn't

Would appreciate any insights or advice.
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

VAR
  long stack[noparse][[/noparse]200]
  byte Cog_Seven
  byte Value_One
   
OBJ
    BS2   : "BS2_Functions"    ' Create BS2 Object

PUB Main
  BS2.start (31,30)
  coginit(7, Lamp_Test, @stack[noparse][[/noparse]100]) 'initiate separate cog to operate LED on pin16
  repeat 'repeat endlessly
    if Value_One == 0                                
      Cog_Seven := cognew(ChimePulse, @stack[noparse][[/noparse]50])+1 'start method in new cog
      Value_One := Cog_Seven 'assign true value to conditional variable
    waitcnt(clkfreq+cnt) 'wait 3 seconds
    if Value_One 'stop cog with variable 
      cogstop(Cog_Seven~ - 1)
      Value_One := 0 'reset variable 
    
PUB ChimePulse
    BS2.FREQOUT(14, 1000, 3000) 'send tone on pin 14 for 1 second

PUB Lamp_Test
  dira[noparse][[/noparse]16]~~ 'set pin 16 to output
  repeat 'repeat endlessly
    outa[noparse][[/noparse]16] := Value_One 'set LED output to true
 

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-03 23:04
    I guess I don't understand why you need more than one cog anyway. The Lamp_Test routine doesn't need a cog since the output register keeps its value until changed and you don't need a cog just to turn the LED on and off. The ChimePulse routine isn't needed because your main cog doesn't do anything useful while the ChimePulse cog is making its sound. That probably uses a cog counter anyway to make the tone and just needs the processor to time the overall duration.

    If you are just trying to learn about cogs and multiprocessing, how about getting the program to work using just the initial cog, then gradually moving functionality to other cogs one step at a time?
  • shmowshmow Posts: 109
    edited 2008-04-04 01:11
    Mike,

    the sample of code in my previous message was part of a larger program I had written earlier.

    the original·program would run as I had planned, but when I added this piezo sequence the program had trouble managing all of the memory or I/O (that's my·guess anyway).

    I dedicated a cog to this piezo sequence and everything ran better.

    I wrote the code in my previous message so I could understand cogs a little better.

    The problem would arise, in my example, when the waitcnt command time was shorter than the time for the piezo to buzz.· If the piezo time equals the waitcnt command time then no problem but any difference would cause the piezo to sound intermittently.

    I'm just looking for a more efficient way to manage cogs.
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-04-04 06:55
    hello shmow,

    could you post a detailed description of what happened "had trouble managing all the memory or IO"

    If you use SPIN everything is done in HUB-RAM. The HUB-RAM is ONE block of 32kB of RAM.
    So i don't understand what you mean by "trouble managing memory" ?

    I'm really want to understand your problem. But with the information given yet i do not understand it.
    please post a REALLY DETAILED descritpion what you want to do and ask a CONCRETE question.

    The more CONCRETE the question is the faster you will get a satisfying answer.

    regards
    Stefan
Sign In or Register to comment.