picaxe 08m speed

bugmenot1234

New Member
if i turn a pin on and off and goto the beginning i'm only getting a speed of about 1200hz and about 2400 when overclocked to 8mhz. my question, what's happening to all the cycles. shouldn't i be able to get more than 1200hz out of 4 or 8 mhz?
 

westaust55

Moderator
It will depend upon the entire program that you have written.

Lets say that it is simply
Code:
Main:
  Low 4
  High 4
  GOTO Main
Firstly when the chip is clocked at 4Mhz internally it takes 4 clock cycles to execute one machine code instruction.

But the PICAXE chips use a BASIC interpreter and your Low 4, High 4 and GOTO Main
instructions must each in turn be:
1. read from program memory,
2. interpreted
3. executed – this can involve several machine code instructions

Additionally even in machine code, a brck takes around twice as long as a simple instruction

On average, each PICAXE BASIC program command takes around 0.25 msec.
Lets say Low 4 and High 4 have a duration of 1 unit of time and the GOTIO Main has a duration of 2 units of time

So 4 unit of time * 0.00025 sec/instruction = 1 msec

Frequency (ore repetition rate) for our small program is thus 1/ 0.001 = 1,000
So since you are seeing 1200 program cycles per second we are doing well. :D
 

MartinM57

Moderator
Firstly when the chip is clocked at 4Mhz internally it takes 4 clock cycles to execute one machine code instruction.
Something wrong with the logic there Westy...the number of clock cycles for one machine code instruction is invariant with the clock frequency.

I also hear rumours that some of the later PICs (no idea which, might even be ones that are turned into PICAXEs?) have a more RISC-like instruction set with one cycle for some/most instructions...

@bugmenot1234 - the time is lost, simply-speaking, in the overheads of PICAXE Basic and the way it runs in the PICAXE. PICAXE Basic is not compiled directly into machine code and if you take 0.25ms as about the time taken by each command at SETFREQ m4, you won't be far (well within about 50%:)) out
 

westaust55

Moderator
Something wrong with the logic there Westy...the number of clock cycles for one machine code instruction is invariant with the clock frequency.
True Martin. :eek:

At any speed clock speed the chip takes 4 clock cycles to execute one "normal" instruction and from my knowledge (but never having programming PICs in machine code) twice as long for a branch instructuction.
 

inglewoodpete

Senior Member
if i turn a pin on and off and goto the beginning i'm only getting a speed of about 1200hz and about 2400 when overclocked to 8mhz. my question, what's happening to all the cycles. shouldn't i be able to get more than 1200hz out of 4 or 8 mhz?
If you just want a fast toggling output, use PWMOut (or possibly PWM).
 

hippy

Ex-Staff (retired)
@ bugmenot1234 : westaust55 is right; what you are seeing is the result of the PICAXE being an 'interpreter' of instructions which makes up your PICAXE program.

If your job were to obey instructions from your boss, you might be given a stack of envelopes each of which contains an instruction. You have to walk to the envelope pile, take the top one, take the instruction out, work out what it means, and if something like "turn the bedroom light on", you then have to go and do that, then walk back, take the next envelope from the top of the pile. All this adds up to time which determines how quickly you could be turning the light on and off.

inglewoodpete's suggestion of PWMOUT is similar to saying, if I'm running backwards and forwards, turning the light on and off, why don't we just get a flashing light and put that in place ? That flashing light can flash quicker than running around turning a light on and off.
 

bugmenot1234

New Member
thank you all for your responses. i understand what you are saying.
if i write the code in assembly it wouldn't have to be interpreted right? and writing the code in assembly for this device is possible right?

in the mean time i'm trying my luck with a 20mhz pic 18f4550 and i will also give the pwm output a try.

my goal will ultimately be 100us cycles and i'm not sure yet if i can achieve this without extra hardware.
 

hippy

Ex-Staff (retired)
That's correct when you write in assembler you write 'native code' and that doesn't require interpreting. With assembler you should be able to achieve 100us (10kHz) easily though it depends what else you are doing within that loop.

You cannot program a PICAXE in assembly language, not without erasing the firmware and it no longer being a PICAXE. 10kHz PWMOUT on the PICAXE is also easily achievable.
 
Top