PICAXE 28X2 PulsOUT command data doesn't match actual output.

SolidWorksMagi

Senior Member
The program listing;

Code:
; 28X2+TIC+RC+StepperMotor.bas

#picaxe 28X2 ; Identify the chip being used

; Begin Declare Variables and Constants * * * * * * * * * * * * * * *
symbol StepperMotor = B.0

symbol i = b0

; BEGIN Initialization * * * * * * * * * * * * * * *
; hserout pin = C.6 = PIN 11
hsersetup B9600_8, %00000    ; 9600 baud, non-inverted polarity
; END Initialization * * * * * * * * * * * * * * * *

; BEGIN Main Body * * * * * * * * * * * * * * *
do
gosub Left1
gosub STOPP
pause 1000
gosub Right1
gosub STOPP
pause 1000
loop
; END Main Body * * * * * * * * * * * * * * * *
end

; BEGIN Subroutines * * * * * * * * * * * * * * *
; BEGIN Motor Subroutines * * * * * * * * * * * * * * *
STOPP:
for i = 0 to 10
pulsout B.0,150
;servopos B.0,150
pause 20
next i
return

Left1:
for i = 0 to 100
pulsout StepperMotor,200
pause 20
next i
return

Right1:
pulsout StepperMotor,140
return
; END Motor Subroutines * * * * * * * * * * * * * * * *
; END Subroutines * * * * * * * * * * * * * * * *
end
Here are the images from my DSO nano;

24621 24622

Looks like the actual output is more like 2700µs instead of 2000µ

Is this caused by the PICAXE 28X2 chips internal clock?
 

AllyCat

Senior Member
Hi,

PICaxe Basic is an "Interpreted" language, so EVERY instruction has a very significant "Timing Overhead" whilst the processor fetches and decodes several bytes and "decides" how to execute each instruction (before actually doing it). At the (X2 default) frequency of 8 MHz, the "fastest" instructions execute in a minimum of about 200 us and a Subroutine Call and Return takes well over 1 ms. I don't know which part of that program is shown on the 'scope, however the width of the PULSOUT should be "correct", but the instruction itself will have an overhead of around 200 us, as will a PAUSE. Then, a FOR .. NEXT loop takes significantly longer, so I'd expect an overhead of at least 700 us between pulses and am surpised it isn't more.

EDIT: But to be honest, I can't see what in the program would generate a 2000 us pulse (at 8 MHz clock), nor in the photos anything that shows a period of 2700 us. :confused:

Cheers, Alan.
 
Last edited:

Goeytex

Senior Member
As Alan explained a Picaxe has significant overhead as it processes instructions. This overhead must be accounted for in order to get accurate timings.

Therefore in practice a Pause 20 will never actually pause exactly 20 ms.

According to your scope shots the "period" is about 22 ms for a frequency of 45Hz. This is a bit slow for servo control that should ideally be 50hz.
So try changing pause 20 to pause 18.

There are other issues with bit-banging servo code on a Picaxe ( or any microcontroller) which you will realize soon enough.

Ideally servo control should be done via a PIC CCP module. But this is near impossible with a Picaxe.
 

SolidWorksMagi

Senior Member
Hi,

Introduction.
Revolution Education develop and publish three specialised Windows applications to support programming and simulation of the PICAXE microcontrollers.

• PICAXE Programming Editor Programming Editor is the default free development system for PICAXE microcontrollers. It supports programming and simulation of PICAXE chips via BASIC program listings and/or graphical flowcharts.

• PICAXE VSM PICAXE VSM is a powerful Berkeley SPICE based circuit simulator that simulates complete PICAXE electronic circuits.

• Logicator for PIC and PICAXE microcontrollers Logicator is a flowcharting application that is widely used within schools for developing and simulating PICAXE programs.

All three applications make use of the PICAXE compiler files (Windows version) to compile the ‘BASIC program text’ into the actual the ‘PICAXE code’.


I did fix my problem by changing the pause to 18

24631

Works perfectly! 😁

 

AllyCat

Senior Member
Hi,

The Pulse still looks to be a little less than 1 ms, which (whatever it is) should of course also be subtracted from the required delay, to set in the PAUSE command, to regulate the complete cycle. And the timing overheads add another ms, or you could get better resolution by using the PAUSEUS command, but its overhead is a little longer (perhaps another 200 us).

Cheers, Alan.
 
Top