Shop OBEX P1 Docs P2 Docs Learn Events
RC Time problem — Parallax Forums

RC Time problem

kenmackenmac Posts: 96
edited 2007-08-25 06:56 in Propeller 1
I have been working on the CTR/RC Time program, displaying the PHSA number on LCD.
It works OK, reading/displaying the number on the first pass through the loop.
However, subsequent passes (thru loop) only read the number as 0.
I added in a LED to trap if the PHSA = or > 0 on each pass - it confirms what was displayed.
I used a fixed 10K/0.1uF combination on Pin 8.

The code used is as follows: (display stuff left out)

con
  _clkmode = xtal1 + pll16x ' System clock → 80 MHz
  _clkfreq = 5_000_000
   
var
 long num

pub start  
  dira[noparse][[/noparse]16..17]~~                                      ' set as output
  ctra[noparse][[/noparse]30..26] := %01000                         ' set counter mode = pos detect
  ctra[noparse][[/noparse]5..0] := 8                                      ' set CTR to use Pin 8
  frqa := 1                                              ' number to increment PHSA
  repeat
    { charge capacitor & time discharge (accumulate number in PHSA)   }
    outa[noparse][[/noparse]8]~~                                          ' set Pin8 high to charge capacitor
    uSdelay(5000)                                    ' wait 5mS
    phsa~                                                ' clear PHSA
    dira[noparse][[/noparse]8]~                                             ' change Pin 8 to input - commence discharge
    uSdelay(50_000)                                ' wait to allow for discharge time
    num := phsa                                      ' read PHSA
    !outa[noparse][[/noparse]16]                                           ' visual indicate that number is read  
    if num == 0
      outa[noparse][[/noparse]17]~~                                      ' num > 0
    else
      outa[noparse][[/noparse]17]~                                        ' num = 0
    uSdelay(20_000_000)                         ' delay between readings
    

pub uSdelay(DelayuS)                            ' Delay  microseconds
  waitcnt((clkfreq/1_000_000) * DelayuS + cnt)



Can anyone spot any obvious code error or know why the PHSA number is 0 for all passes except the first?

kenmac

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 08:39
    Maybe a DIRA[noparse][[/noparse]8]~~ somewhere will help smile.gif
  • kenmackenmac Posts: 96
    edited 2007-08-24 09:37
    Actually, there was a Dira[noparse][[/noparse]8] in there but it accidentally got deleted when I edited out some non-used code from this copy.
    The actual code area reads like this:

    pub start  
      dira[noparse][[/noparse]16..17]~~                                       ' set as output
      dira[noparse][[/noparse]8]~~                                             '
      outa[noparse][[/noparse]8]~                                              ' clear
    
    



    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 11:04
    Sorry, that was not the right place - try again smile.gif
  • kenmackenmac Posts: 96
    edited 2007-08-24 11:42
    Ah, my tired eyes have spotted it!
    In the loop I used Dira[noparse][[/noparse]8]~ where it should have been Outa[noparse][[/noparse]8]~ .
    Just shows you sometimes need someone else to look at it.

    Thanks, deSilva.

    I know you are very busy - How do you get the time to handle simple stuff like this?
    Anyway, I'm grateful for the assistance.


    Now for some sleep!

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 12:05
    kenmac said...
    In the loop I used Dira[noparse][[/noparse]8]~ where it should have been Outa[noparse][[/noparse]8]~
    Are you really sure ?
    kenmac said...

    I know you are very busy - How do you get the time to handle simple stuff like this?
    Soon I shall spend hours finding such problems in other person's code - I am practicing smile.gif
  • kenmackenmac Posts: 96
    edited 2007-08-25 02:04
    Just to complete this thread.
    My last post was incorrect - a decision by a "tired mind".
    Anyway, with a fresh mind it is now obvious.
    The reason why it didn't work correctly was that the Pin mode needed to be toggled at each pass thru the loop, and so the Dira[noparse][[/noparse]8]~~ needed to be in the loop for this to happen.
    It has been corrected and the program now works OK.

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-25 06:56
    smile.gif
Sign In or Register to comment.