Am I doing a right accuracy test?

Sean87

Member
Hi all,

Today I had a chance to use a friend's scope to test something. I programmed 20X2 with the simple program below and then tested the result using the scope:

Code:
main:
high 1
pause 1
low 1
pause 1

goto main
And here is the result from the scope (it is a 50MHz digital scope - so I guess it can provide enough bandwidth for my today's test):


The reason for doing this, is that I want to make a very simple square wave generator using 20x2. The idea is just making a pin output high and low in selectable time intervals. I know that this will produce naive waveforms but for my current need it would be enough.

So as you see I put in my program to wait 1ms between each high and low state. but the result I get on scope is around 1.4ms so I was wondering if this is a expected number ot not.

Also about the low state, as you can see it is -40mV so I was again wondering if this should be 0 or not? I tried with a bypass capacitor between +/- pins of the chip and this went lower to -120mV again is this expected?

OR my testing idea is completly rubbish and I am doing it wrong? Would be nice to hear some comments from pro users!
 
Last edited:

westaust55

Moderator
Each program command has a small timing overhead that adds to the overall timing.
Typically it is considered to be around 250usec per command for a non X2 part although the actual time does vary with specific commands at 4 MHz
For X2 parts there are slightly more overheads so the time per command is slightly greater.

With the PAUSE command you call for a 1 msec delay but then we must add 0.25 msec for the command itself then another 0.25 msec for HIGh or LOW and even again for the GOTO.
Thus your timing is as expected.
 

womai

Senior Member
For the voltage levels, you should look at Vbase (-4mV), not Vmin (-40mV). The latter is the peak negative excursion so is heavily influenced by noise, overshoot on the waveform etc. Also keep in mind an oscilloscope is not a high-accuracy voltmeter. The Rigol (and 99% of all other scopes) has 8 bit resolution; At 1V/div and 8 vertical divisions on the screen that corresponds to a resolution of just about 30mV. Also there will be gain and offset errors. So a reading of -4mV is more than close enough at the expected 0V.

Wolfgang
 

Goeytex

Senior Member
You can measure the the programming overhead by using pauseus (instead of pause). Increase the pauseus value
until you see a change of the pulse width on the the scope. This will also be the highest frequency that you can generate with your code.
To balance the overhead between the high and low commands for closer to 50% duty you can format the code a bit differently.

Code:
SetHi: High 2 : Pause 1 : Goto SetLo

SetLo:Low 2 : Pause 1 : Goto SetHi
or

Code:
main:
Toggle 2
Pause 1
Goto main
 

Sean87

Member
Thanks all for your answers.

Using Goeytex second code, toggle, I got better result and the duty cycle is now 50%



So the highest frequency I can go with 20x2 for generating waveform will be 1/1ms ? this result in a 145.3Hz waveform. What if I use
Code:
setfreq m64
 

hippy

Ex-Staff (retired)
So the highest frequency I can go with 20x2 for generating waveform will be 1/1ms ? this result in a 145.3Hz waveform. What if I use "setfreq m64"
Why not try it as you have a scope to hand ?

The answer is that using SETFREQ M64 will give a faster execution so a higher frequency. To get less than the 1ms/1ms you can also use PAUSEUS rather than PAUSE as suggested earlier.
 

Sean87

Member
Why not try it as you have a scope to hand ?

The answer is that using SETFREQ M64 will give a faster execution so a higher frequency. To get less than the 1ms/1ms you can also use PAUSEUS rather than PAUSE as suggested earlier.
I was wondering what is PAUSEUS! now I guess it is pause in µS ? have to look in manual. thanks.
 

eclectic

Moderator
I might have missed something,
but why tie up the Picaxe using pause / pauseus?

Use Pwmout (& Wizard)

Code:
#picaxe 20X2
Setfreq M4 ; change as required
pwmout pwmdiv16, C.5, 124, 250  ; 500 Hz
 
;pwmout pwmdiv4, C.5, 249, 500 ; 1 kHz
;pwmout pwmdiv4, C.5, 124, 250 ; 2 kHz
;and so on.
 

Do
Loop
e
 

westaust55

Moderator
I might have missed something,
but why tie up the Picaxe using pause / pauseus?

Use Pwmout (& Wizard)

e
Potentially very true eclectic.

Without knowing the bigger picture it can be a guess as to how improvement can be made.

- Is it just a quick experiment?

- Does the 20X2 mean that there will be other IO and code? and hence use of PWMOUT is very worthwhile, or

- If it is the sole task, might an 08M suffice? Maybe not since the suggestion of higher clock speed is mentioned.
 

Goeytex

Senior Member
If the idea is a low frequency VCO it can be relatively "glitchless" using an ADC and Pause/Pauseus, or even ADC/ settimer and an interrupt.
However, using PWMOUT to change the frequency on the fly causes a glitch in the signal. It also involves some math to keep the duty cycle at 50%.
 
Top