Jump to content

PICAXE: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Removing link(s) Wikipedia:Articles for deletion/ARM express closed as delete (XFDcloser)
 
(239 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[File:Picaxe_20M2.JPG|thumb|right|PICAXE 20M2]]
'''PICAXE''' is the name of a UK-sourced [[microcontroller]] system based on a range of [[Microchip Technology|Microchip]] [[PIC microcontroller|PICs]]. There are 13 PICAXE variants of differing pin counts from 8 to 40 pins. Initially marketed for use in education and by electronics hobbyists, they are also used in commercial and technical fields, including rapid prototype development. All use pre-loaded factory [[booting|bootstrap]] interpretation code to allow user generated [[computer program|programs]] to be downloaded using a simple [[RS-232]] [[serial port|serial connection]].
'''PICAXE''' is a microcontroller system based on a range of [[Microchip Technology|Microchip]] [[PIC microcontroller|PIC]] [[microcontroller]]s. PICAXE devices are Microchip PIC devices with pre-programmed firmware that enables bootloading of code directly from a PC, simplifying hobbyist embedded development (not unlike the [[Arduino]] and [[Parallax, Inc. (company)|Parallax]] [[BASIC Stamp]] systems). PICAXE devices have been produced by Revolution Education (Rev-Ed) since 1999.{{Citation needed|date=August 2018}}
<!-- Image with unknown copyright status removed: [[Image:Picaxe.jpg|frame|right|Picaxe Microcontroller]] -->


==Hardware==
==Hardware==
Based upon a variety of Microchip PICs, the chips come in a number of [[dual inline package|DIP]] footprints, from an 8-pin, 128-byte program capacity device through to a 40-pin, 4096-byte program capacity device. With their DIP footprint they are suited for use with solderless [[breadboard]]s and more traditional PCBs designs, although surface mount versions are available.


There are currently six (6) PICAXE variants of differing pin counts (8-14-18-20-28-40) and are available as [[Dual in-line package|DIL]] and [[Surface-mount technology|SMD]].<ref name="chipsizes">{{cite web
The 8-pin PICAXE-08M is priced below GB£2 and is often chosen as an entry-level option as it lends itself to easy prototyping.
|title = PICAXE Chip Sizes
|url = http://www.picaxe.com/What-is-PICAXE/PICAXE-Chip-Sizes/
}}</ref>


PICAXE microcontrollers are pre-programmed with an [[Interpreter (computing)|interpreter]]<ref name="poke">{{cite web
The current recommended parts, as of April 2009, are
|title = poke - BASIC Commands - PICAXE
08M, 14M, 18M, 20M, 20X2,
|url = http://www.picaxe.com/BASIC-Commands/Variables/poke/
18X, 28X1, 40X1,
}}</ref> similar to the [[BASIC Stamp]] but using internal EEPROM instead, thus reducing cost. This also allows downloads to be made with a simple serial connection which eliminates the need for a [[Programmer (hardware)|PIC programmer]].<ref name="picaxe">{{cite web
20X2, 28X2, 40X2
|title = What is PICAXE? - PICAXE
|url = http://www.picaxe.com/What-is-PICAXE/
}}</ref> PICAXE is programmed using an RS-232 serial cable<ref name="serialcable">{{cite web
|title = Serial (9-way D) Download Cable - Hardware - PICAXE
|url = http://www.picaxe.com/Hardware/Cables/Serial-9-way-D-Download-Cable/
}}</ref> or a USB cable<ref name="usbcable">{{cite web
|title = PICAXE USB Download Cable (AXE027) - Hardware - PICAXE
|url = http://www.picaxe.com/Hardware/Cables/PICAXE-USB-Download-Cable/
}}</ref> which connects a [[Personal computer|computer]] to the download circuit, which normally uses a [[TRS connector|3.5&nbsp;mm jack]] and two [[resistors]].<ref name="downloadcircuit">{{cite web
|title = PICAXE Download Circuit
|url = http://www.picaxe.com/Site_Resources/Media/Site_1/pinout/serial.jpg
}}</ref>


===Programming language===
The 28, 28A, 28X and 40X have been discontinued as they have been superseded by the X1 parts. The 18 and 18A have been discontinued as they have been superseded by the 18M.
PICAXE microcontrollers are programmed using [[BASIC]].<ref name="basic">{{cite web
The 08, 18, 18A are still available, but not recommended for new designs.
|title = Index of - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/
}}</ref>


The PICAXE interpreter features [[Bit banging|bit-banged]] communications:
All current devices, use an internal 4/8 MHz oscillator, and hence require few components to create a basic hardware platform. The X1 and X2 parts also have the ability to operate from 31kHz to 8MHz in 7 steps using internal low frequency oscillators in addition to the internal resonator.
* [[Asynchronous serial communication|Serial]]<ref name="serin">{{cite web
|title = serin - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin/}}</ref><ref name="serout">{{cite web
|title = serout - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serout/}}</ref> (asynchronous serial)
* [[Serial Peripheral Interface Bus|SPI]]<ref name="shiftin">{{cite web
|title = shiftin - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/shiftin/}}</ref><ref name="shiftout">{{cite web
|title = shiftout - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/shiftout/}}</ref> (synchronous serial)
* [[Consumer IR|Infrared]] (using a 38&nbsp;kHz carrier, seven data bits and five ID bits)<ref name="irin">{{cite web
|title = irin - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/irin/
}}</ref>
* [[One-wire]]<ref name="owin">{{cite web
|title = owin - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/owin/}}</ref><ref name="owout">{{cite web
|title = owout - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/owout/}}</ref>
The "readtemp" command reads the temperature from a DS18B20 temperature [[sensor]] and converts it into [[Celsius]].<ref name="readtemp">{{cite web
|title = readtemp - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/readtemp}}</ref>


All current PICAXEs have commands for using hardware features of the underlying PIC microcontrollers:
The X2 parts can also operate at higher speeds from the internal oscillators. The X1 and X2 parts can also use an external resonator for up to 20MHz (X1 parts) and up to 64 MHz for the X2 parts.
* [[Universal asynchronous receiver/transmitter|Hardware asynchronous serial]]<ref name="hsersetup">{{cite web
|title = hsersetup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/hsersetup/}}</ref>
* Hardware synchronous serial<ref name="hspisetup">{{cite web
|title = hspisetup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/hspisetup/}}</ref><ref name="hi2csetup">{{cite web
|title = hi2csetup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/hi2csetup/}}</ref>
* Hardware [[Pulse-width modulation|PWM]]<ref name="hpwm">{{cite web
|title = hpwm - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/hpwm/}}</ref>
* [[Digital-to-analog converter|DAC]]<ref name="dacsetup">{{cite web
|title = dacsetup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/dacsetup/}}</ref>
* [[Analog-to-digital converter|ADC]]<ref name="readadc10">{{cite web
|title = readadc10 - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/readadc10/}}</ref>
* [[SR Latch]]<ref name="srlatch">{{cite web
|title = srlatch - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-IO-Interfacing/srlatch/}}</ref>
* Timers (two on X2/X1 parts<ref name="settimer">{{cite web
|title = settimer - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/settimer/}}</ref><ref name="tmr3setup">{{cite web
|title = tmr3setup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/tmr3setup/}}</ref> which have settable intervals, only one on M2 parts with a fixed interval,<ref name="enabletime">{{cite web
|title = enabletime - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/enabletime/}}</ref> older parts have none)
* [[Comparator]]s<ref name="compsetup">{{cite web
|title = compsetup - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/compsetup/}}</ref>
* Internal temperature measurement<ref name="readinternaltemp">{{cite web
|title = readinternaltemp - BASIC Commands - PICAXE
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/readinternaltemp/}}</ref>


===Minimal configurations===
===Program space===
All current PICAXE chips have at least 2048 bytes of on board program memory available for user programs:<ref name="chipsizes"/>
All current devices require nothing more than the connection of power and configuration of the Serial In pin used for downloading.
* 08M2 - 2048 [[byte]]s
* 14M2 - 2048
* 18M2+ - 2048
* 20M2 - 2048
* 20X2 - 4096
* 28X1 - 4096
* 40X1 - 4096
* 28X2 - 4096 per slot with four slots for a total of 16&nbsp;KiB
* 40X2 - 4096 per slot with four slots for a total of 16&nbsp;KiB


===Clock speeds===
The 18, 28 and 40-pin devices requires a [[pull-up resistor]] from the Reset pin and the 28 and 40X require the connection of a resonator or crystal.
The default clock speed for all M2 and X1 parts is 4&nbsp;MHz and for the X2 parts is 8&nbsp;MHz.
The SETFREQ command allows speeds from 31&nbsp;kHz up to 8&nbsp;MHz for X1 parts, 31&nbsp;kHz up to 32&nbsp;MHz for M2 parts and 31&nbsp;kHz up to 16&nbsp;MHz for X2 parts (up to 64&nbsp;MHz for the 20X2) using the internal resonator.


An external resonator can be used with the X1 parts for from 4&nbsp;MHz to 20&nbsp;MHz clock speeds and with the X2 parts for 16&nbsp;MHz to 64&nbsp;MHz clock speeds.<ref name="setfreq">{{cite web
|title = setfreq - BASIC Commands
|url = http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/setfreq/
}}</ref>


===Power supply requirements===
===Project boards===
Project boards for different applications are sold<ref name="projectboards">{{cite web
Power supply voltages are very flexible allowing operation from batteries or regulated power supplies.
|title = Project Boards - Hardware
Most of the PICAXE range is nominally 4.5V to 5Vdc but can operate down to approximately 3V dc.
|url = http://www.picaxe.com/Hardware/Project-Boards/
The X2 range also includes special low power (1.8V to 3.3Vdc) variants.

}}</ref> by Rev-Ed which contain the PICAXE, download circuit and may also contain a prototyping area<ref name="axe021">{{cite web
===Low power modes===
|title = PICAXE-08 Proto Board (AXE021) - Hardware - PICAXE
There are a number of commands (SLEEP, NAP, HIBERNATE, DOZE) to put the device into low power operating modes in order to conserve power and extend operational lifetime when powered by batteries.
|url = http://www.picaxe.com/Hardware/Project-Boards/PICAXE-08-Proto-Board/

Many of the variants have controllable clocks, allowing for operation below their nominal operating frequencies, to achieve minimal lower power consumption. Execution speed can be controlled by the user program.
}}</ref> or high power output drivers.<ref name="chi035">{{cite web

|title = PICAXE-18 High Power Project Board (CHI035) - Hardware - PICAXE
===Non-volatile data storage===
|url = http://www.picaxe.com/Hardware/Project-Boards/PICAXE-18-High-Power-Project-Board/
All devices contain non-volatile data memory which allows data to be stored and recovered when power is removed. Access to the non-volatile data memory is through the use of the READ and WRITE commands and, on the 28A, the READMEM and WRITEMEM commands can also be used.

}}</ref>
The amount of non-volatile data memory available depends upon the device:
*The 08 and 18 have 128 bytes of EEPROM which is used to store both downloaded program and for non-volatile data memory use.
*The 08M, 14M, 18M, 20M have 256 bytes of EEPROM which is used to store both downloaded program and for non-volatile data memory use.
*The 18A and 18X have 256 bytes of EEPROM exclusively available for non-volatile data memory use.
*The 28 has 64 bytes of EEPROM exclusively available for non-volatile data memory use.
*The 28A has 64 bytes of EEPROM exclusively available for non-volatile data memory use and also has 256 bytes of Flash memory which may be used for non-volatile data storage using the READMEM and WRITEMEM commands.
*The 28X and 40X have 128 bytes of EEPROM exclusively available for non-volatile data memory use.
*The 28X1 and 40X1 have 4096 bytes of program space, double the variable memory and additional 128 bytes scratchpad memory. These also many new features for IO etc.
*The 20X2, 28X2 and 40X2 a slightly different arrangement with up to 4 internal program memory slots, 32 external memory slots, 1024 bytes of scratchpad memory and more versatile bidirectional IO.


==Software==
==Software==
Revolution Education develop software for writing programs for PICAXE.
All programming development is done using the Programming Editor or the AXEpad editor. These are both free software downloads supporting the entire development process from source code editing to program downloading. Microsoft (Windows 98 and later), Linux and Macintosh operating systems are supported. Historically a serial port was required to download programs, however a USB download cable is now available from the developers. The cable incorporates a USB-serial adapter moulded into its plug, eliminating the need for a separate adapter for users of modern USB-only PCs.


===PICAXE Programming Editor===
The Programming Editor and AXEpad also include a number of Wizards which aid in program and project development.
PICAXE Programming Editor is a [[Microsoft Windows|Windows]]-only [[Integrated development environment|IDE]] for writing PICAXE programs in BASIC code or a simple flowchart.


PICAXE Programming Editor features:<ref name="pe">{{cite web
Editing can be done in plain text or RTF with color syntax highlighting. Source code can be created outside the Programming Editor and imported for downloading. Programs can be created in a Basic-like language or by using [[visual programming language|a visual flowcharting tool]]. The Programming Editor also supports PICmicro Assembly Language programming.
|title = PICAXE Programming Editor (BAS805) - Software - PICAXE
|url = http://www.picaxe.com/Software/PICAXE/PICAXE-Programming-Editor
}}</ref>
* source code colour [[syntax highlighting]]
* auto indentation
* syntax check and program download
* code explorer to shown variable, label and constant values
* full on screen simulation with animated chips and line by line code highlighting
* simulation breakpoints by line number and variable value
* debug and serial terminal windows
* AXE027 download cable testing and port identification tools
* various testing tools such as the analogue calibration wizard
* various code generation wizards (pwmout, tune, RTC setting, etc.)


===Simulator===
===AXEpad===
AXEpad is a cross-platform application recommended for [[Linux]] and [[macOS|Mac]] users.<ref name="axepad">{{cite web
The Programming Editor software includes a comprehensive line by line on-screen simulation of the BASIC program. This enables users to step through the program on-screen, to watch the program in operation, and help identify any programming errors.
|title = AXEPAD (PAD001) - Software - PICAXE
|url = http://www.picaxe.com/Software/PICAXE/AXEpad
}}</ref> It lacks some of Programming Editor's wizards, simulation and [[Multiple Document Interface|MDI]].


===Tune wizard===
===Logicator for PICAXE===
Logicator is an easy to use [[shareware]] flowcharting program.<ref name="logicator">{{cite web
This Wizard is used to create TUNE commands which can be used with the 08M, 14M, 18M, 20M, 28X1 and 40X1.
|title = Logicator for PICAXE (LGC010) - Software - PICAXE
The Wizard includes the ability to import suitable mobile telephone ring tones and convert them to appropriate TUNE commands.
|url = http://www.picaxe.com/Software/PICAXE/Logicator-for-PICAXE/
}}</ref> The Logicator web page is out of date as the free version does support all commands but shows [[Nagware|nag screens]].


PICAXE Programming Editor 6, the successor to PICAXE Programming Editor 5, has Logicator flowcharting merged into it so separate Logicator software is no longer required.<ref name="pe6beta1">{{cite web
===Serial LCD CGRAM wizard===
|title = PE6 Beta testing Briefing
This Wizard provides a visual means to create custom defined characters to be used with serial LCD displays. The desired character is specified by selecting pixels which will be displayed on a 7x5 grid and the necessary command to program that character within the LCD is generated.
|url = http://www.picaxe.com/docs/pe6.pdf
}}</ref> Like PICAXE Programming Editor 5, PICAXE Programming Editor 6 is freeware.


===Datalogger wizard===
==Third-party software==
This Wizard is used to generate datalogging programs.


===PICAXE connect wizard===
===Yenka===
Yenka is a program developed by Crocodile Clips Ltd which has flowcharts and simulation.<ref name="yenkapics">{{cite web
This Wizard allows the configuration of MaxStream XBee ([[ZigBee]]) modules to be configured for use.
|title = Yenka PICs

|url = http://www.yenka.com/en/Yenka_PICs/
===PICAXE net server wizard===
This Wizard allows configuration of the PICAXE.net Web Server product. The Wizard provides the ability to create and upload page images and to upgrade the web server firmware.

==Programming language==
The programming language is BASIC-like and very similar to that used by the Basic Stamp 1 (BS1). Most programs written for the BS1 should be easily convertible for use. The most notable difference is that the BS1's POT command has been replaced by the READADC command which allows an analogue voltage to be read directly. READADC10 allows analogue inputs to be read to 10-bit resolution.

The programming language includes high-level support for underlying processor capabilities and additional functionality for various devices. All variants support a common core programming command set but not all support all commands.

===Variables===
The programming language provides 14 byte variables on smaller PICAXE chips, 28 byte variables for X1 parts and 56 byte variables for the latest X2 parts through the Programming Editor. This memory can be manipulated in measures of bits (as bit0-15 for smaller parts at bit0-31 for larger parts), bytes (b0-b13, b27 or b55), and 16-bit words (w0-6, w0-13 and w0-27). The bit, byte, and word variables all overlap in the same memory area. Every two byte variables overlap with a word variable, so b0 & b1 make up w0, b2 & b3 compose w1, and so on. The bit values bit1 to bit7 overlap b0, and bit8 to bit15 overlap b1, etc (which also covers w0). This can be used to carve apart variables, or simply make the most efficient use of the limited memory given.
}}</ref>
Variables can be given meaningful names (aliases) for use within a program through use of the SYMBOL directive. The SYMBOL directive can also be used to create named constants.


===Others===
In addition to the pre-defined variables, all but the 08 have access to the some of the internal SFR (Special Function Registers) and General Purpose Registers of the PICmicro they are based upon, allowing many of the unused Registers to be used as Random Access Memory (RAM) during execution. This can be used for temporary storage of variable values (using PEEK and POKE) and allows re-use of variables within subroutines and other code sections. The smaller PICAXE parts have 48 bytes free for use, while the other parts have access to greater number of registers enhanced parts as 95/96 bytes for the 18X, 28X1 and 40X1, 112 bytes for the 28X and 40X, 72 bytes for the 20X2 and 200 bytes for the 28X2/40X2.
Many companies and organizations have put out their own editors with special features. Some include language translators or serial connectors, so there is a wide variety of consoles to be used.{{Citation needed|date=August 2018}}


==Support==
The PEEK and POKE commands can also be used to implement byte arrays and software stacks.
Support is available at the Technical Support section of the PICAXE website and at the PICAXE Forum.<ref name="support">{{cite web
|title = Technical Support - Getting Started - PICAXE
|url = http://www.picaxe.com/Getting-Started/Technical-Support/


}}</ref>
The 20X2, 28X1, 40X1 parts also have 128 bytes of 'scratchpad' memory available while the 28X2 and 40X2 parts have 1024 bytes of ‘scratchpad’ memory.
The scratchpad memory can be accessed directly (PUT and GET commands) or indirectly via the scratchpad pointer '@ptr'.


The PICAXE Forum has a finished projects section where completed projects and PICAXE programs are posted,<ref name="forum">{{cite web
|title = Finished User PICAXE Projects
|url = http://www.picaxeforum.co.uk/forumdisplay.php?34


}}</ref> plus there is a similar section on the PICAXE website.<ref name="sitefinishedprojects">{{cite web
The READ and WRITE commands, which allow data to be stored in and retrieved from non-volatile EEPROM memory, can be used to retain data and settings while powered down.
|title = Index of - Project Gallery - PICAXE
|url = http://www.picaxe.com/Project-Gallery/


}}</ref>
===Arithmetical manipulation===
All arithmetical operations are performed using 16-bit, unsigned, positive only operations. Variables are expanded as required to 16-bits on use by leading zero padding and results of processing are stored by truncating the resultant value to an appropriate number of bits before storage. A byte variable will have the eight least significant bits of the result stored, a bit variable will be set to the least significant bit value of the result.


== See also ==
Note that when using byte size variables, the internal maths are done using 16-bits so intermediate results on a line can exceed the maximum byte value of 255 but must not exceed 65535 otherwise erroneous results will occur.
*[[Arduino]]
*[[BASIC Atom]]
*[[BASIC Stamp]]
*[[Maximite]]
*[[OOPic]]
*KodeKLIX - PICAXE chip based snap-together educational system


==References==
Care must therefore be taken when manipulating variables and values to consider the effect of wrap-round, underflow and overflow. In particular it must be noted that a value can never be less than zero, and a byte value can never exceed 255. These issues must be considered in the implementation of FOR-NEXT loops and other looping constructs, which may, under some circumstances, never meet their terminating conditions. There is no facility to automatically report or indicate warp-round, underflow or overflow.
{{Reflist}}


==Further reading==
All arithmetical expressions in assignments (LET) are evaluated in a strictly left-to-right manner.
{{Refbegin}}
There is no operator precedence. Note that the keyword "LET" is optional.


*{{Cite book
In the future, the use of parenthesis for maths precedence to control calculations will be possible on the X1 and X2 parts. This is currently awaiting an update of the Programming Editor by the PICAXE makers, Rev Ed.
| first1 = David
| last1 = Lincoln
| date = December 13, 2010
| title = Programming and Customizing the PICAXE Microcontroller
| edition = 2nd
| publisher = Mc Graw Hill/Tab Electronics
| isbn = 978-0-07-174554-3
}}


*{{Cite book
The 28X1 and 40X1 parts have additional unary maths functions which include: Sin, Cos, Sqr, Inv, NCD, DCD, BintoBCD and BCDtoBin functions. Whn unary maths fucntions are used, they MUST be the first command on a program line. The unary functions can be followed by additional "normal" maths functions on the same line. For example:
| first1 = Ron
LET b1 = COS 30 + 55 / 10
| last1 = Hackett
is valid
| date = August 12, 2010
| title = PICAXE Microcontroller Projects for the Evil Genius
| edition = 1st
| publisher = Mc Graw Hill/Tab Electronics
| isbn = 9780071703260
}}


{{Refend}}
===Program flow control===
A number of control constructs are provided to handle program flow -
*[[GOTO]] - Redirects program execution to another location in the program.
*IF-THEN - Not the usual "IF ''condition'' THEN ''statement''". The only ''statement'' IF/THEN takes is a Label: , which it does a "GOTO" when the ''condition'' is true. IF/THEN falls to the next line when the ''condition'' is false.
*BRANCH - Conditionally redirects program execution to one of a number of locations in the program (same as ON-GOTO).
*[[GOSUB]] - Redirects program execution to another location in the program, then continues after the GOSUB command following the execution of a RETURN in the subroutine.
*[[Return statement|RETURN]] - Returns program execution to after the most recent GOSUB.
*SETINT - Enables polled interrupts and automatically redirects program execution to an interrupt handler when an interrupt is detected.
*SETINTFLAGS - Enables polled interrupts on certain flag-byte conditions.
For both SETINT and SETINTFLAGS, program execution continues from where the program was diverted from upon execution
of a RETURN within the interrupt handler.

*[[For loop|FOR-NEXT]] - Repeats a section of code while a variable value is within a specified range.

A number of block structured constructs and constructs found in other BASIC language dialects exist -
*IF-THEN-ELSE-ENDIF - Selects one of two paths of execution dependent upon conditions. Also supports an ELSEIF clause.
*SELECT-CASE-ENDSELECT - Selects one of a number of paths of execution depending upon value of a variable matched against a list of conditions.
*DO-LOOP - Conditionally repeats a section of code. Allows construction of WHILE-DO and REPEAT-UNTIL loops.
*ON-GOTO - Conditionally redirects program execution to one of a number of locations in the program.
*ON-GOSUB - Conditionally calls one of a number of subroutines in the program.

===Program size===
The size of program permitted is dictated by the on-chip EEPROM or Flash capacity.
*The 08 and 18 have 128 bytes of program memory allowing programs of approximately 40 lines of source code.
*The 08M, 18A, 18M, 28 and 28A have 256 bytes of program memory allowing programs of approximately 80 lines of source code.
*The X-range have 2048 bytes of program memory allowing approximately 600 lines of source code.
*The X1 and X2 ranges have 4096 bytes of program memory allowing approximately 1000 lines of source code. The X2 parts furthermore have up to 4 internal program slots.

Because the program downloaded is stored as variable length tokens, it is not possible to easily predict the size of program which will be generated from any given source code. In particular, the program size will vary depending upon what value constants are used and which input and output pins are referenced in various commands. The Programming Editor does however provide a Syntax Check function which allows the size of program generated to be determined without having to download the program. This also allows programs to be developed and checked even without access to target hardware.

The variable length size of tokens, coupled with the inability to predict their alignment within the program memory also means that it is not possible to accurately predict the execution speed of any particular command, although typically this will be a minimum of 250 microseconds at normal 4 MHz operating speed. <!-- Changed from ~500 microseconds - see discussion page -->

===Subroutine nesting===
For non “X” part PICAXE chips, a maximum of 16 subroutine call statements (GOSUB) is supported within a program (15 if interrupts are supported). The X, X1 and X2 ranges support up to 256 GOSUB statements.

Subroutines can be nested to a depth of 4 levels for most PICAXE chips and to a depth of 8 levels for the X1 and X2 parts. One level of depth must be reserved for interrupt handler use when interrupts are enabled.

===Illusion of limited capabilities===
Although these are constrained devices, with a limited number of variables, limitations in the programming command structures and, on lower-end devices, limited program memory, these limitations have not prevented many successful projects and applications from emerging. The PICAXE is increasingly being used in (and to support) many commercial products.

Provided as a range of devices, each offering differing capabilities and functionality, projects and designs can be tailored to meet requirements such as cost. Their low cost also allows multiple PICAXE configurations to be used and still be cost effective to alternative single-chip solutions. Using multiple devices also has many advantages in system design and modularisation.

===Points of Interest===
====PEEK and READ====
Whereas most internal processing is done using 16-bits, a value read using the PEEK or READ commands is returned as an 8-bit value, and when stored in a word variable, only the least significant bits of that word will be altered.

====RANDOM====
The RANDOM command provides pseudo-random number generator functionality which updates a variable to a new value when it is used. The new value is determined by the existing value of the variable when the RANDOM command is used.

Because all variables are initialised to zero when power is applied or a reset occurs, the variables to be used with RANDOM should be seeded first to prevent the same sequence of random numbers being generated whenever the program is started. Seeding can be done by storing and updating a seeding value within non-volatile EEPROM memory.

A mechanism to avoid seeding is to repeatedly execute the RANDOM command (such as when waiting for an input condition) so the value it has generated will be unpredictable when it is used later.
For the X1 and X2 parts, an alternative to repeated execution of the RANDOM command is to set the timer running and then use the timer variable to ‘seed’ the random command. This will give much better results.

Although RANDOM can be used with a byte variable, because such a byte value is expanded to 16-bits before the randomising function is applied, the sequence of 'random results' will be very short and produce only a limited set of values.

====MIN and MAX====
The MIN and MAX operators using in assignments are 'limiting operations', ensuring that the result of the expression evaluated to that point never falls below or exceeds a specified value respectively.

Although somewhat counter-intuitive, MIN can also be thought of as returning the highest of two values, and MAX can be thought of as returning the lowest of the two.

==Programming interface==
Programs are downloaded from the Programming Editor using a serial link, either a physical serial port or a USB to serial adapter. USB serial ports must be able to support RS232 break signalling for successful use.

The basic programming interface consists of just two resistors and does not need RS232 level converters.

===Debugging facilities===
*If spare output lines are available, these can be used to control LEDs or Piezo sounders to visually or audibly indicate the program's execution reaching the points where such commands are placed. The Serial Output command (SEROUT) can be used to send execution progress indicators and variable content information to a PC or other terminal device.
*Many of the variants support the SERTXD command which is equivalent to using the SEROUT command to return information about program execution but it uses the Serial Out line of the download interface alleviating the need to use a Digital Output line for this purpose.
*The DEBUG command can be used with the Debug Monitoring facilities of the Programming Editor, the contents of variables when the DEBUG command is executed can be observed.

==Interfacing==
Being based upon the PICmicro, the PICAXE has great versatility in interfacing. Most variants support the on-chip hardware of the underlying PICmicro.

===Digital outputs===
Digital Outputs can each sink and source around 20mA and are capable of driving LEDs and other small loads directly. Be aware that while each output can handle 20mA there is limits for each port and for the entire chip that typically prevents 20mA being used on every output. For some PICAXE chips, the port and total limit is around 95mA while for others the limit can be around 200mA. A review of the datasheet for the core PICmicro chip is recommended.

===Digital inputs===
Most Digital Inputs are protected by diode clamps to the power rails, which as well as offering good ESD protection, allows interfacing to high voltage signals often with little more than a current limiting resistor being required.

This is particularly useful for interfacing to PCs, PDAs and terminals where a complete serial interface can be implemented using just one resistor. This allows for low-cost designs which do not necessitate the use of RS232 level conversion circuits, although such converters can be used to provide a more traditional interface if desired.

===Bi-directional inputs and outputs===
The 18, 18A, 18M, 18X, 20M, 28 and 28A have fixed direction Input and Output pins. That is to say that every pin is pre-defined as either an input or an output and this use cannot be explicitly changed under program control.

The 08 and 08M have three bi-directional pins which can be either input or output pins and can be explicitly set as such and changed under program control. The 14M has nine bi-directional pins when used in its advanced configuration.

The 28X/X1 and 40X/X1 also have eight 'PORTC' lines which can be made inputs or outputs under program control.
The 28X/X1 and 40X/X1 have another eight "PortB' lines which are [[always]] defined as output.
Some of the additional pins/legs on the 40X/X1 chips provide a further eight 'PortD' lines which are always set as inputs.

At the start of program execution (after power is applied or reset occurs) all of the bi-directional pins will automatically be set as inputs and only become outputs when instructed by the executing program.

Because it is not always clear what program has previously been downloaded into a PICAXE which supports bi-directional pins, care must be taken when inserting those into alternative hardware. It is recommended that any existing program be erased before it is inserted into hardware different to that which it was previously used with. Inadvertently, or deliberately, making an input line an output line may have damaging effects upon the chip itself and any hardware connected to those pins.

===Interrupts===
The 08M, 18A, 18M and all X parts support hardware interrupting on a pattern match with the input pins.

===Analogue inputs===
Analogue input is supported across the entire range. The 08 and 18 support only coarse, low-resolution analogue inputs which is delivered as one of 16 8-bit levels. The others support full 256-level, 8-bit analogue input, and some offer 1024-level, 10-bit inputs.

The number of analogue inputs depends on the actual device, and in some cases the analogue inputs and digital inputs share the same pins, allowing them to be used as either analogue or digital inputs, and with some design, both.

===Analogue outputs===
Like most microcontrollers, there is no ability to generate an analogue output voltage directly, however analogue voltages can be produced by using PWM output capabilities plus the addition of suitable circuitry.

===Dallas one-wire device===
The firmware supports interfacing with some Dallas [[1-Wire]] devices, including the iButton and DS18B20 Temperature sensor. The firmware also provides the ability, through the READOWSN command, to read the unique serial number of any 1-Wire device, whether it can access and use that device's capabilities or not.

===I²C===
All of the X Parts (18X, 20X2, 28X, 28X1, 28X2, 40X, 40X1 and 40X2) have the capability to use the in-built I²C commands for reading and writing to most I²C devices.

Prior to firmware revision 8.6 on the 18X, and 7.7 on the 28X and 40X, the device being accessed must require at least two data bytes (3 bytes total including the address byte) to be able to be used with the built-in commands. Starting with the above mentioned firmware revisions, and the latest editor software, devices that only require two bytes (an address byte and a data byte) can be used.

Some limitations with the firmware controlled I²C functions are that there is no control beyond read and write commands. Protocol options like repeated start, early stop, attention are not supported. By [[bit-banging]] the signals, however, the entire gamut of I²C options can be used, but this requires an in depth familiarity with the I²C protocol itself.

The X1 and X2 parts can also be operated as I²C slave devices.

===Infrared===
For the non X1/X2 parts, there are three commands to support infrared interfacing -
* INFRAIN - Allows reception of infrared signals which use Sony's SIRC protocol. This command is tailored to supporting key press codes which would be sent from a TV remote control and supports only a subset of possible remote control commands.
* INFRAIN2 - Allows reception of infrared signals which use Sony's SIRC protocol. This command allows the reception of any remote control command.
* INFRAOUT - Allows the generation of an infrared signal using Sony's SIRC protocol.

The INFRAIN and INFRAIN2 commands require that an external infrared sensor (TSOP18) is used to demodulate the incoming infrared signal for processing. INFRAOUT can be used to drive an infrared LED (and optional visible light LED) directly.

Even without the INFRAIN and INFRAIN2 commands, infrared signals which use Sony's SIRC protocol can be read by means of bit-banging; sampling the signal provided by the infrared sensor and determining the remote control command sent. This technique is also applicable for decoding infrared signals sent using other protocols, but is not suitable for all such protocols.

For the 28X1 and 40X1 parts, there are two different commands (keywords) with slightly different functionality:
* IRIN - This command is similar to the ‘infrain2’ command found on other PICAXE devices, but can be used on any input pin. There is also an optional timeout feature
* IROUT - This command is similar to the ‘infraout’ command found on other PICAXE devices, but can be used on any output pin.

===LCD===
All variants can interface to serially controlled LCDs using the SEROUT command providing they use a baud rate which is supported.

All but the 08 and 08M can directly control Hitachi [[HD44780 Character LCD|HD44780]] and similar LCDs operating in parallel, 4-bit mode. Those having too few output lines to support direct interfacing, can connect to such displays, but only through additional interface circuitry, for example by using shift registers. Such interfacing schemes can always be used instead of direct parallel connections.

===PC keyboard===
The 18A, 18M, 28A and the X-range all provide the ability to interface to a PC keyboard using the KEYIN and KEYLED commands.

These two commands respectively determine which key was pressed on a PC keyboard through its scan code and control the setting of the keyboard LEDs. The KEYLED command can be used to flash the keyboard LEDs to indicate when a key press has been received.

===PWM output===
The 08 and 08M support the PWM command and the 08M, 18M and the X-range support the PWMOUT command.

The PWM command provides for a burst of a pulse-width modulated signal to be generated which may be used to charge a simple Resistor-Capacitor circuit to generate an analogue voltage output. PWM can be used with any Digital Output pin.

The PWMOUT command allows a pulse-width modulated signal to be continually generated while execution continues, which may be used to generate analogue voltages, as with PWM, but can also be used for speed control of motors and brightness control of visual indicators. PWMOUT can only be used with certain Digital Output pins. The 08M and 18X provide only a single PWMOUT output, while the 28X and 40X provide two.

For the 14M, the 28X1 and 40X1 parts, there are different PWM commands.

* HPWM - (which stands for hardware PWM) allows selection of the mode, polarity, setting period and duty. Hardware PWM is an advanced method of motor control using PWM methods. HPWM can provide up to 4 separate pins with a PWM output as defined by the PIC microcontroller’s internal pwm hardware.
hpwm can be used instead of, not at the same time as, the pwmout command on 2. However pwmout on 1 can be used simultaneously if desired.

HPWMDUTY – On the X1 and X2 parts only, the hpwmduty command can be used to alter the hpwm duty cycle without resetting the internal timer (as occurs with a hpwm command). A hpwm command must be issued before this command will function.

===Serial===
User programmed serial input and output is implemented in the firmware, allowing the serial communications to be received on any Digital Input pin and transmitted on any Digital Output Pin. The serial interface supports a variety of baud rates between 300 and 4800 baud when operating at 4 MHz, up to 9600 baud at 8 MHz (M, A, and X parts), and up to 19,200 baud at 16 MHz (28X and 40X only).

On the 18X, 28X and 40X access to the on-chip [[universal asynchronous receiver/transmitter|AUSART]] through the use of PEEK and POKE allows bytes to be sent and received at higher baud rates. Those which allow access to the AUSART are capable of transmitting [[MIDI]] compatible data and potentially [[DMX512-A|DMX-512]] data streams.

===Servo control===
All except the 08 and 18 can simultaneously support the control of multiple servos connected to any of its Digital Output pins.

Up to eight servos can be controlled directly using the SERVO command. Once the servo positions have been specified, the required signal stream for each servo is sent while program execution continues.

===Sound and Tune Control===
The SOUND command allows tone generation on any of the Digital Outputs. Piezo sounders can be directly connected to the Digital Output pins and loudspeakers can be driven through a simple amplifier circuit.

The 08M, 14M, 18M, 20M, 20X2, 28X1, 28X2, 40X1 and 40X2 have the PLAY command which allows the playing of between one and four pre-programmed tunes depending upon which PICAXE chip is used. For the 08M only, there is capability to optionally flash LEDs in step with the tune's beat.

The next command available for the 08M, 14M, 18M, 20M, 20X2, 28X1, 28X2, 40X1 and 40X2 is the TUNE command.
Whereas the SOUND command provides for the frequency of a tone (or white noise) and its duration to be specified, the TUNE command allows the tone to be user specified in terms of a musical note and the tempo of the tune to be specified.

The Programming Editor includes a Wizard to convert suitable mobile phone ringtones to an equivalent TUNE command with the necessary data.

===SPI===
Native support for [[Serial Peripheral Interface Bus|SPI]] and similar interfacing is provided on the X1 and X2 and can be implemented by direct control of the digital output lines, using a technique known as [[bit-banging]].

== See also ==
*[[Arduino]]
*[[BASIC Stamp]]
*[[OOPic]]


==External links==
==External links==
*[http://www.picaxe.co.uk Official PICAXE Website]
*[http://www.picaxe.com Official PICAXE Website]
*[http://www.picaxe.com/BASIC-Commands/A-Z/ BASIC commands]

*[http://www.hvwtech.com/products_view.asp?ProductID=875 PICAXE Suppliers] HVW Tech
*[http://www.maxmcarter.com/picaxe/picaxe_server.html web server/PICAXE interface]
*[http://www.picaxe.com/Distributors Distributors - PICAXE]
*[http://world-educational-services.info/cart/index.php?main_page=index&cPath=9 PICAXE Suppliers] Advanced MicroCircuits
*[http://www.sparkfun.com/commerce/product_info.php?products_id=8330 PICAXE Suppliers] SparkFun
*[http://www.allaboutcircuits.com/technical-articles/intro-to-picaxe Introducing the PICAXE System]
*[http://www.kodeklix.com.au/ Snap Electronics educational system using PICAXE]


{{Microchip Technology}}
{{DEFAULTSORT:Picaxe}}
[[Category:Microcontrollers]]
[[Category:Microcontrollers]]
[[Category:Microchip Technology hardware]]

[[it:PICAXE]]

Latest revision as of 19:45, 16 June 2022

PICAXE 20M2

PICAXE is a microcontroller system based on a range of Microchip PIC microcontrollers. PICAXE devices are Microchip PIC devices with pre-programmed firmware that enables bootloading of code directly from a PC, simplifying hobbyist embedded development (not unlike the Arduino and Parallax BASIC Stamp systems). PICAXE devices have been produced by Revolution Education (Rev-Ed) since 1999.[citation needed]

Hardware

[edit]

There are currently six (6) PICAXE variants of differing pin counts (8-14-18-20-28-40) and are available as DIL and SMD.[1]

PICAXE microcontrollers are pre-programmed with an interpreter[2] similar to the BASIC Stamp but using internal EEPROM instead, thus reducing cost. This also allows downloads to be made with a simple serial connection which eliminates the need for a PIC programmer.[3] PICAXE is programmed using an RS-232 serial cable[4] or a USB cable[5] which connects a computer to the download circuit, which normally uses a 3.5 mm jack and two resistors.[6]

Programming language

[edit]

PICAXE microcontrollers are programmed using BASIC.[7]

The PICAXE interpreter features bit-banged communications:

The "readtemp" command reads the temperature from a DS18B20 temperature sensor and converts it into Celsius.[15]

All current PICAXEs have commands for using hardware features of the underlying PIC microcontrollers:

Program space

[edit]

All current PICAXE chips have at least 2048 bytes of on board program memory available for user programs:[1]

  • 08M2 - 2048 bytes
  • 14M2 - 2048
  • 18M2+ - 2048
  • 20M2 - 2048
  • 20X2 - 4096
  • 28X1 - 4096
  • 40X1 - 4096
  • 28X2 - 4096 per slot with four slots for a total of 16 KiB
  • 40X2 - 4096 per slot with four slots for a total of 16 KiB

Clock speeds

[edit]

The default clock speed for all M2 and X1 parts is 4 MHz and for the X2 parts is 8 MHz.

The SETFREQ command allows speeds from 31 kHz up to 8 MHz for X1 parts, 31 kHz up to 32 MHz for M2 parts and 31 kHz up to 16 MHz for X2 parts (up to 64 MHz for the 20X2) using the internal resonator.

An external resonator can be used with the X1 parts for from 4 MHz to 20 MHz clock speeds and with the X2 parts for 16 MHz to 64 MHz clock speeds.[28]

Project boards

[edit]

Project boards for different applications are sold[29] by Rev-Ed which contain the PICAXE, download circuit and may also contain a prototyping area[30] or high power output drivers.[31]

Software

[edit]

Revolution Education develop software for writing programs for PICAXE.

PICAXE Programming Editor

[edit]

PICAXE Programming Editor is a Windows-only IDE for writing PICAXE programs in BASIC code or a simple flowchart.

PICAXE Programming Editor features:[32]

  • source code colour syntax highlighting
  • auto indentation
  • syntax check and program download
  • code explorer to shown variable, label and constant values
  • full on screen simulation with animated chips and line by line code highlighting
  • simulation breakpoints by line number and variable value
  • debug and serial terminal windows
  • AXE027 download cable testing and port identification tools
  • various testing tools such as the analogue calibration wizard
  • various code generation wizards (pwmout, tune, RTC setting, etc.)

AXEpad

[edit]

AXEpad is a cross-platform application recommended for Linux and Mac users.[33] It lacks some of Programming Editor's wizards, simulation and MDI.

Logicator for PICAXE

[edit]

Logicator is an easy to use shareware flowcharting program.[34] The Logicator web page is out of date as the free version does support all commands but shows nag screens.

PICAXE Programming Editor 6, the successor to PICAXE Programming Editor 5, has Logicator flowcharting merged into it so separate Logicator software is no longer required.[35] Like PICAXE Programming Editor 5, PICAXE Programming Editor 6 is freeware.

Third-party software

[edit]

Yenka

[edit]

Yenka is a program developed by Crocodile Clips Ltd which has flowcharts and simulation.[36]

Others

[edit]

Many companies and organizations have put out their own editors with special features. Some include language translators or serial connectors, so there is a wide variety of consoles to be used.[citation needed]

Support

[edit]

Support is available at the Technical Support section of the PICAXE website and at the PICAXE Forum.[37]

The PICAXE Forum has a finished projects section where completed projects and PICAXE programs are posted,[38] plus there is a similar section on the PICAXE website.[39]

See also

[edit]

References

[edit]
  1. ^ a b "PICAXE Chip Sizes".
  2. ^ "poke - BASIC Commands - PICAXE".
  3. ^ "What is PICAXE? - PICAXE".
  4. ^ "Serial (9-way D) Download Cable - Hardware - PICAXE".
  5. ^ "PICAXE USB Download Cable (AXE027) - Hardware - PICAXE".
  6. ^ "PICAXE Download Circuit".
  7. ^ "Index of - BASIC Commands - PICAXE".
  8. ^ "serin - BASIC Commands - PICAXE".
  9. ^ "serout - BASIC Commands - PICAXE".
  10. ^ "shiftin - BASIC Commands - PICAXE".
  11. ^ "shiftout - BASIC Commands - PICAXE".
  12. ^ "irin - BASIC Commands - PICAXE".
  13. ^ "owin - BASIC Commands - PICAXE".
  14. ^ "owout - BASIC Commands - PICAXE".
  15. ^ "readtemp - BASIC Commands - PICAXE".
  16. ^ "hsersetup - BASIC Commands - PICAXE".
  17. ^ "hspisetup - BASIC Commands - PICAXE".
  18. ^ "hi2csetup - BASIC Commands - PICAXE".
  19. ^ "hpwm - BASIC Commands - PICAXE".
  20. ^ "dacsetup - BASIC Commands - PICAXE".
  21. ^ "readadc10 - BASIC Commands - PICAXE".
  22. ^ "srlatch - BASIC Commands - PICAXE".
  23. ^ "settimer - BASIC Commands - PICAXE".
  24. ^ "tmr3setup - BASIC Commands - PICAXE".
  25. ^ "enabletime - BASIC Commands - PICAXE".
  26. ^ "compsetup - BASIC Commands - PICAXE".
  27. ^ "readinternaltemp - BASIC Commands - PICAXE".
  28. ^ "setfreq - BASIC Commands".
  29. ^ "Project Boards - Hardware".
  30. ^ "PICAXE-08 Proto Board (AXE021) - Hardware - PICAXE".
  31. ^ "PICAXE-18 High Power Project Board (CHI035) - Hardware - PICAXE".
  32. ^ "PICAXE Programming Editor (BAS805) - Software - PICAXE".
  33. ^ "AXEPAD (PAD001) - Software - PICAXE".
  34. ^ "Logicator for PICAXE (LGC010) - Software - PICAXE".
  35. ^ "PE6 Beta testing Briefing" (PDF).
  36. ^ "Yenka PICs".
  37. ^ "Technical Support - Getting Started - PICAXE".
  38. ^ "Finished User PICAXE Projects".
  39. ^ "Index of - Project Gallery - PICAXE".

Further reading

[edit]
  • Lincoln, David (December 13, 2010). Programming and Customizing the PICAXE Microcontroller (2nd ed.). Mc Graw Hill/Tab Electronics. ISBN 978-0-07-174554-3.
  • Hackett, Ron (August 12, 2010). PICAXE Microcontroller Projects for the Evil Genius (1st ed.). Mc Graw Hill/Tab Electronics. ISBN 9780071703260.
[edit]