RC Time problem
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)
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
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
The actual code area reads like this:
kenmac
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8
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
Soon I shall spend hours finding such problems in other person's code - I am practicing
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