PDA

View Full Version : PAUSEUS does not working properly (wrong timing)



CuriousOne
- 31st July 2013, 10:49
Hello.

Here's simple code:



define OSC 4
TRISB = %00000000
charte var PORTB.2
gamorte var PORTB.3

AGAIN:
pulsout charte,1
pauseus 100
pulsout gamorte,1
pause 1000
pulsout charte,1
pauseus 200
pulsout gamorte,1
pause 1000
pulsout charte,1
pauseus 300
pulsout gamorte,1
pause 1000


GOTO AGAIN


When run on 16F628A, instead of 100, 200 and 300 uS delays, it gives: 290, 400, 490us delay, measured with digital scope.

I've modified code for 16F819, for 8mhz oscillator, by changing to: define OSC 8 and adding: OSCCON=%01110100

In this case, linearity improved, but PAUSEUS are still out of definitions:

100uS gives 270 uS
200uS gives 370 uS
300uS gives 470 uS

Why this happens and what I'm doing wrong?

HenrikOlsson
- 31st July 2013, 15:24
Hi,
Are you sure you don't have the timebase setting on the scope set in the uncal mode, ie. not an even 1-2-5 whatever per division? Try something simple like

TRISB = 0
Again:
PortB.2 = 1
Pause 500
PortB.2 = 0
Pause 500
Goto Again
That should give you a 1Hz toggle which would be easy enough to eyeball with a simple a LED. Then change to PAUSE 5 and check again with scope. I'm pretty sure it has nothing to do with the PAUSEUS statement in your code but rather something like the oscillator isn't running at the correct frequency or you're not measuring it correctly. But of course, I could be wrong.

/Henrik.

LinkMTech
- 31st July 2013, 15:48
After you find your real timing problem, don't forget to consider the Pulsout statement execution time.

I measured 47us delay between these signals running at 4MHz:


AGAIN:
PULSOUT PORTC.3, 1
PULSOUT PORTC.3, 1
GOTO AGAIN


This showed 147us between the end of one to beginning of the next pulse:


AGAIN:
PULSOUT PORTC.3, 1
PAUSEUS 100
PULSOUT PORTC.3, 1
PAUSE 100
GOTO AGAIN

CuriousOne
- 31st July 2013, 21:01
Scope xefinetly not the case, and the pause statement is working properly. the problem is with pauseus statement and only on small durations. say, pauseus 1200 and above, give almost perfect result. it is very interesting fact that, pauseus 1, gives 200 us delay between pulsout statements on 16 f628a @ 4 mhz, and only 48 us delay on 12 f683!

AvionicsMaster1
- 31st July 2013, 23:23
The define OSC 4 needs to be DEFINE OSC 4 though I think the default is 4Meg it might require a correct DEFINE statement to make it work.

With the 12f683 internal oscillator you need both the DEFINE OSC and the OSCCON to make it work properly. Not sure with the 16F628 if you need a PCON statement in addition to the DEFINE OSC.