PDA

View Full Version : unstable ADCIN readings when using DT ELAPSED.PBP



peter_wiersig
- 18th February 2010, 20:31
Hi,

when we measure a voltage divider and have activated the timer for ELAPSED.PBP from Darrel Taylor, every 40th measurement or so is way off. When we never call start_timer from that file our readings are as stable as we expect.

If we call stop_timer before the ADCIN command and start_timer afterwards our measurements are still off. I also tried to disable the timer0 interrupts via PIE1.0 = 0.

Admittingly our version of ELAPSED.PBP is from 12/16/2003 but the examples from Darrels site show no big differences when using (assembler?) interrupts for measuring elapsed time periods.

Is there anything to have in mind when mixing ADC and interrupts?

Darrel Taylor
- 18th February 2010, 22:47
What chip are you using?

Which wsave? variables do you have uncommented?

What version of PBP are you using?

Have you modified the files?

Have you changed any Interrupt registers?

Can you post your code?
<br>

peter_wiersig
- 19th February 2010, 23:30
Hi Darrel, thanks for your fast reply. Thanks for your libs!

See the attached ZIP for the code

The PIC is a 18F2423 Device ID Revision = 00000007

Darrel Taylor
- 20th February 2010, 01:37
Peter,

You are using an 18F with the Elapsed Timer for 14-bit cores.

You should be using the one in post #18 of the original thread ...

http://www.picbasic.co.uk/forum/showthread.php?p=15575#post15575
<br>

peter_wiersig
- 20th February 2010, 15:07
Hi Darrel,

my fears came truth. I've inherited the codebase and suspected that those parts need updates as I visited your page and saw that updates were released after 2003 :rolleyes: BTW: The ELAPSED-18.bas still list 12/16/2003 as date.

But I lucked out as your promise from the thread holds true: Your *-18.bas files are drop-in replacements for the old versions. No line modified, just the extension changed to .pbp as .bas is reserved for the Visual Basic code.

The code is reduced to the clock output shown below, the clock counting is working without errors, but the display has artefacts, as about every 10 seconds the display has wrong information in the places of the clock, never where the separators are appearing.

I need a hint:
Do we have to protect instructions like ARRAYWRITE or is it rather the SPI were the interrupts are interfering?

actually: scratch that, it must be the ARRAYWRITE as else the separators would be influenced too. :eek: time to read assembler. Stuff that I avoided since 1990.

if the PAUSE before the last GOTO is removed, the problem isn't visible bt I think the updates are simply happening more often and the problem is still appearing.


'Code is licensed as http://creativecommons.org/licenses/by-sa/3.0/de/
'(c) 2010 Ing Buero A. Czech

DEFINE DEBUG_MODE 1 'Auf 1 setzen, wenn keine Debuggen notwendig
DEFINE DEBUGIN_MODE 1

INCLUDE "BS1DEFS.bas"
INCLUDE "EBS18F2423.pbp"
INCLUDE "EBSMasterKonf.pbp"
INCLUDE "EBSMasterVar.pbp"
INCLUDE "Elapsed-18.pbp"
INCLUDE "LCDAusgabe.pbp"

'================================================= ==============================
'VP: LCD Initialisierung
'================================================= ==============================
GOSUB EBSLCDINIT
LCDTextAnz = 16

GOSUB ResetTime
GOSUB StartTimer

'================================================= ==============================
' Hauptprogramm
'================================================= ==============================
HauptSchleife:
GOSUB EBSLCDZeile1
ARRAYWRITE LCDText,[DEC2 days, "+", DEC2 Hours, ":", DEC2 Minutes, ":", DEC2 seconds, REP 32\11]
GOSUB EBSLCDTEXTOUT
'DEBUG
PAUSE 500
GOTO HauptSchleife

peter_wiersig
- 20th February 2010, 16:02
actually: scratch that, it must be the ARRAYWRITE as else the separators would be influenced too. :eek: time to read assembler. Stuff that I avoided since 1990.


I chickened out, if I use this construct:


T1CON.0 = 0 ; Turn OFF Timer1
ARRAYWRITE LCDText,[DEC2 days, "+", DEC2 Hours, ":", DEC2 Minutes, ":", DEC2 seconds, REP 32\11]
T1CON.0 = 1 ; Turn OFF Timer1


the clock is working without problems and the ADC readings are stable. It was the output and not the measurement that had the problem.

Darrel Taylor
- 20th February 2010, 23:28
You shouldn't need to turn the timer off. And doing so will affect the accuracy of the Elapsed Timer.
And the Interrupts won't interfere with the MSSP module.

I think you just need to wait for the SecondsChanged flag before sending it to the LCD.
Then it won't be changing the time while you're trying to display it.



HauptSchleife:
IF SecondsChanged THEN
SecondsChanged = 0
GOSUB EBSLCDZeile1
ARRAYWRITE LCDText,[DEC2 days, "+", DEC2 Hours, ":", DEC2 Minutes, ":", DEC2 seconds, REP 32\11]
GOSUB EBSLCDTEXTOUT
ENDIF
PAUSE 1
GOTO HauptSchleife

peter_wiersig
- 27th February 2010, 16:40
You shouldn't need to turn the timer off. And doing so will affect the accuracy of the Elapsed Timer.


Yes, expected the inaccuracy. As our process is finished in ~10 hours this inaccuracy is no issue.

We are seeing with this code irregular values in the first line and no issues in the second line. The interrupts are interfering with the arraywrite instruction.

It's never that anything is printed beyond the 10th char but that random characters are printed anywhere in the digits, all zeroes and non-numbers are also seen.


'Code is licensed as http://creativecommons.org/licenses/by-sa/3.0/de/
'(c) 2010 Ing Buero A. Czech

DEFINE DEBUG_MODE 1 'Auf 1 setzen, wenn keine Debuggen notwendig
DEFINE DEBUGIN_MODE 1

INCLUDE "BS1DEFS.bas"
INCLUDE "EBS18F2423.pbp"
INCLUDE "EBSMasterKonf.pbp"
INCLUDE "EBSMasterVar.pbp"
INCLUDE "Elapsed-18.pbp"
INCLUDE "LCDAusgabe.pbp"

'================================================= ==============================
'VP: LCD Initialisierung
'================================================= ==============================
GOSUB EBSLCDINIT
LCDTextAnz = 16

GOSUB ResetTime
GOSUB StartTimer

DebugLoop:
GOSUB EBSLCDZeile1
ARRAYWRITE LCDText, [DEC10 LCDTextAnz, REP 32\11]
GOSUB EBSLCDTEXTOUT
T1CON.0 = 0 ; Turn OFF Timer1
ARRAYWRITE LCDText,[DEC2 days, "+", DEC2 Hours, ":", DEC2 Minutes, ":", DEC2 seconds, REP 32\11]
T1CON.0 = 1 ; Turn OFF Timer1
GOSUB EBSLCDZeile2
GOSUB EBSLCDTEXTOUT
PAUSE 200

Darrel Taylor
- 27th February 2010, 19:16
ARRAYWRITE LCDText, [DEC10 LCDTextAnz, REP 32\11]
It appears that you are using PBPL now.

There was no such thing as PBPL when I wrote the elapsed timer in 2003.
And that version does not save system vars properly for PBPL.

I believe you can change the save variables to LONG's and get better results...
R0save var LONG
R1save var LONG
R4save var LONG


Or, unless there is some reason you really need to use PBPL ...
Switch back to PBPW.

You could also use this version of the Elapsed Timer, which is known to be compatible with PBPL.
http://darreltaylor.com/DT_INTS-18/elapsed.html
<br>