IF time > 59 THEN : time = 0 : ENDIFwill always take around 1200 Instruction Cycles.
Many of the forum members have been interested in what speed the interpreted BASIC commands take.do all processes take the same time
Many thanks, that's sort of what I was expecting. I'm driving a small stepper motor and its response to input via an ADC is a little slow.Due to the way PICAXE source code is 'tokenised', it is difficult to determine when code will run faster or slower. Generally, you can expect a decision (like If ValueA = ValueB Then ...) to take longer than simply Goto Main.
Code that is downloaded into a PICAXE chip is not compiled like may other microcontroller systems. The PICAXE has a permanent 'operating system' in its flash memory that interprets tokenised code that is downloaded into the chip. These code 'tokens' are either 5-bits wide (M2 chips) or 6-bits wide (X2 chips). When your PICAXE code is 'run', the firmware extracts each token and performs the task that is required. Since the tokens are stored in 8-bit bytes, extracting each one will result in a range of different times to execute it, depending on were the token is actually stored on a particular download. The result is very compact storage of code but slower and potentially variable execution speed.
Yes that's correct, but nobody (except me) normally discusses the PIC Instruction cycle rate, only the "headline" SETFREQ value (M4 or M8, etc.). However, most of the internal timers, and it happens the X2's external crystal resonator when used, do operate at the PIC's Instruction Cycle frequency.I had thought that most PICs (including the 16F1829 'range' PicAxe M2 devices are based on) had a 4 Clock Instruction Cycle?
Thanks for the input.Hi,
It depends what the ADC is required to do and the function of the motor, but IMHO Stepper Motors are a particular area where it's important to use an "appropriate" code structure and command set (and driver hardware). That might need a skilled eye to look over the program, but unless attempting something too "ambitious", I would not normally expect to (need to) raise the clock frequency much above 4 MHz.
Here's a video of a Picaxe 20M2 reading a barometric pressure sensor, driving a stepper motor, detecting touch switches, and updating an OLED display:Thanks for the input.
The driving of the stepper is via a dedicated IC driver which only wants step plus direction. The motor tracks a constantly varying input voltage. I've set my processor to 32Mhz which improves things a lot. The 64Mhz of the X series may do it but when I was planning on just an 08M it seems a bit of overkill.
All I have to do is read a value into the ADC and decide whether to go CW or ACW but this is tested every single step. This is probably where my issue lies. Brute processing speed is being dictated by my crude code.
So the simple solution is to use a PICaxe PWM Output to clock the Stepper driver and use the Program to update the direction and the PWM period (speed) asynchronously as required. Then it should be sufficient (and probably better) to use the PICaxe at its default (4 MHz) frequency. There are (at least) two potential "disadvantages" in using a higher frequency: The minimum available PWM (i.e. stepping) frequency would be higher and (I believe) the ADC runs from its own (fixed) clock, which may be non-optimum at the highest Program speeds.The driving of the stepper is via a dedicated IC driver which only wants step plus direction.