Shop OBEX P1 Docs P2 Docs Learn Events
Adjusting PW in Repeat loop — Parallax Forums

Adjusting PW in Repeat loop

lardomlardom Posts: 1,659
edited 2014-05-10 09:00 in Propeller 1
I'm working on a way to adjust current for my electrolysis experiments. I'm using a parent object to pass values at the moment. I'll use a pot for my next set of tests. The code works. I want Hi and Lo to update. Is there an expression that simplifies the process?
(I switched set/Post set assignment operators but that's minor)
VAR
    long stack[10], Incr, Hi, Lo
    word cog

'Low frequency current control for electrolysis
'child object  

PUB Start

    cog := cognew(TestArea, @stack) + 1

PUB Stop                                                   

    If cog 
      cogstop(cog~ - 1)  

PUB Main(a, b)    'Parent passes values to this method

    Hi := a
    Lo := b  

PUB TestArea     'Hz * PW = increments

    Incr := (clkfreq/10_000)     '1Khz
    dira[1]~~
    repeat
      Hi:= Hi       'Is there a better way to update
      outa[1]~
      waitcnt(Incr*Hi+cnt)
      Lo:= Lo       'Is there a better way to update
      outa[1]~~        
      waitcnt(Incr*Lo+cnt)    

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-10 08:53
    The update will happen in "Main". You don't need "Hi := Hi" or "Lo := Lo". They add nothing to the program.

    The various cogs all use the same hub RAM for variables. There aren't multiple instances of "Hi" and "Lo".

    Cog RAM is being used to run the Spin interpreter. Your variables are not stored in cog RAM.
  • lardomlardom Posts: 1,659
    edited 2014-05-10 09:00
    Ha! It works. For some reason I thought I'd already tried that. Thanks Duane.
Sign In or Register to comment.