Shop OBEX P1 Docs P2 Docs Learn Events
Clearing PHSA and PHSB with LONGFILL? — Parallax Forums

Clearing PHSA and PHSB with LONGFILL?

I've got some dirt-simple code that is running in a "background" cog; part of that code reads two pots through a standard RC circuit. The background loop runs every millisecond, so I use a timer variable to keep track of the RC state.

This works:
pri measure_pots                                                 ' call only from support()

  if (pottimer == 0)
    dira[L_VOL..R_VOL] := %11                                    ' charge caps 

  elseif (pottimer == 2)                                
    phsa := 0
    dira[L_VOL] := 0
    phsb := 0
    dira[R_VOL] := 0

  elseif (pottimer == 4)
    lvolpot := (0 #> ((phsa >> 4) - 37) <# 400) >> 2             ' scale results, 0..100   
    rvolpot := (0 #> ((phsb >> 4) - 37) <# 400) >> 2
                    
  if (++pottimer => 5)
    pottimer := 0

After looking at it a while I thought I could shave off a couple instructions by changing the milddle section to this:
elseif (pottimer == 2)
  longfill($1FC, 0, 2)
  dira[L_VOL..R_VOL] := %00

No bueno, and I cannot sort out while. $1FC is the address of phsa in a cog, right? (I did confirm that in the data sheet).

It's been a long day for me, and I've probably overlooked something simple, but it would be nice to know what that is.

Comments

  • I believe that LongFill writes to main ( hub ) memory. You need to write to $1FC and $1FD in cog memory
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-08-30 06:29
    You're absolutely right. Thank you. I think it's time for a beer and then some shut-eye.
  • So um, Jon. Could you maybe post the corrected Pri measure_pots? Just for science. It's a closure thing.

    Hope you had a good snooze, btw.
Sign In or Register to comment.