Ain - 24 V1.2 Guide V1.1
Ain - 24 V1.2 Guide V1.1
Ain - 24 V1.2 Guide V1.1
Contents
• (1) Product Image
• (2) Description
• (2) Key Features
• (2) Board Layout
• (3) Connector CN1
• (3) Connector CN2
• (3) Connector CN3
• (3) Connector CN4
• (4) Connector CN5
• (4) Jumper JP1
• (4) Jumper JP2
• (5) ESD200 Installation & Configuration
• (6) Micro Controller Schematic
• (7) Analogue Capture / Digital IO X 8
• (7) UART 1 / Serial Port 1
• (7) LED Indicators
• (8) EEPROM Schematic
• (8) EEPROM Operation
(8) RS232 Schematic
• (8) UART2 / Serial Port 2
• (9) PWM Multiplexor Schematic
• (9) PWM Multiplexor Operation
• (11) Code Examples
• (11) Software License Agreement
• (11) Processor Initialisation
• (16) Port & Hardware Initialisation
• (20) RS232 Communications
• (22) EEPROM Read & Write
• (25) Delay Routines
• (26) PWM Multiplexer
• (30) Legal (Please Read First)
Description
The p.Brain-µ24 has be designed for use in advanced hobby robotics, where multiple R/C type
servos need to be controlled with a standard PWM signal, such as hexapod robots. At the core
of the p.Brain-µ24 is a microchip dsPIC33F 16bit micro controller with 128Kb programme flash,
8Kb RAM and 32Kb external EEPROM. This micro controller can be programmed using
microchips ICD2 programmer and MPLAB IDE. Although the micro controller can be
programmed in assembler, I suggest using a C compiler such as Hi-techs (www.htsoft.com) All
programming examples are written for the Hi-tech compiler.
The p.Brain-µ24 has 24 PWM channels for R/C servo control, along with a variety of other
peripherals such as UART's, I2C, ADC and Digital I/O. Unlike the p.Brain-ds24, the p.brain-µ24
does not require a motherboard for operation, all 24 PWM signals are routed to servo
connector pins with power supplied from a terminal block.
Key Features
p.Brain LAYOUT
SERVO 1-4 SERVO 5-8 SERVO 8-12 JP2
CN3
CN2
CN4 &
CN5
JP1
SERVO 21-24 CN1
SERVO 17-20 SERVO 13-16
micromagic systems ltd • Registered in England no 3745348
www.micromagicsystems.com
Page 3/30
P.Brain-µ24 (v1.1) User Guide
Pin 1
Pin 3
Pin 5
Pin 7
Pin 9
Pin 11
Note: Servo power is fused via a polyswitch. This fuse will trip at approx 8.5Amps, and will
reset when the short circuit condition has been removed. The fuse is rated at 16V max.
An RS-232 RJ11 to DB9 cable is available separately (p.Brain-RJ232) or you can make your
own serial lead using the following wiring:
CN5 comprises of two connectors for fitting the ESD200 bluetotth module.
CN5
CN5 Part1
PIN NAME DESCRIPTION PART1
1 GND Power Ground PIN1
2 VCC 3.3V Power
3 Connected Connection Status
4 RESET Reset Config Defaults
CN5 Part2
PIN NAME DESCRIPTION
1 GND Power Ground
2 N/C Not Connected
3 RX Data out
4 TX Data in CN5
PART2
PIN1
This jumper selects between RS232 or ESD200 bluetooth input to UART2 RX. The PCB is
indicated with a 'B' and 'R' position for the jumper: B = bluetooth, R = RS232. The output
transmit of UART2 is always routed to both RS-232 and the ESD200 socket. This means that if
you are using the p.Brain-µ24 configured in bluetooth mode JP1=B, you could plug in an
RJ-232 adaptor lead to a serial port to monitor the data being sent to the ESD200, or visa
versa.
This jumper connects the fused side of the servo power supply VS to the logic power supply
VL. This allows the processor to run from the same power as the servos, however, in some
cases power fluctuations on the servo power source may cause the processor to reset.
Ensure the power to the p.Brain-µ24 is switched off, and insert the ESD200 into the socket as
shown in the image.
Before you configure the ESD200 device, you may need to change the desired baud rate, this
defaults to 115200. If you require a different baud rate, you will need to use the RJ-232
adaptor and configure the HexEngine TBR setting before proceeding. Note, the baud rate into
the ESD200 does not have to match the baud rate on the host PC bluetooth adaptor.
Although not essential, if you have an RJ-232 adaptor lead, it is advised to plug this in during
ESD200 configuration so that the progress and any configuration errors can be monitored.
Connect the RJ-232 lead from the RJ11 port to a free serial port on your host PC, and start up
your terminal software.
Place the JP1 jumper in the 'B' position, switch on power to the p.Brain-µ24, wait until the unit
has booted up, (approx 2 seconds), then press and hold the small tactile switch located under
the power terminal CN3 for at least 2 seconds, then release. All going well your ESD200 will be
configured in approximately 5 seconds.
The bluetooth pass key or pin code is: 1138 This is only true for version 1.2 and higher of the
HexEngine, for versions below 1.2, please see the relative documentation.
Once configuration is complete, your ESD200 should now be in discover mode, this means that
you should be able to pair with your ESD200 using Windows bluetooth utility or similar. During
the pairing procedure you will be asked for the pass key defined above. When pairing is
complete, you should be able to connect you your ESD200 with the COM port assigned by your
host operating system.
The blue LED next to the ESD200 is the connection LED. This should illuminate when a
connection is made between the device and a host system. Note I have noticed in some cases
the LED does not light even when a connection is established, this seems to be determined by
the host software initiating the connection!?
This schematic displays the micro controller connections to the PWM block, EEPROM, LED's and
various ports which are described in more detail in the following pages.
There are eight p.Brain pins that can be configured as either analogue capture or digital IO:
DIG4/AN4 and DIG5/AN5 can be configured as input capture ports if needed. DIG0 thru DIG5
have a programmable weak pull-up and change notification interrupt capabilities. DIG6 and
DIG7 have no internal pull up resistors and are also the ICSP pins.
For further information on analogue capture, input capture and change notification pins, please
see microchips data sheet at www.microchip.com or the supplied sample code.
Serial port 1 can only operate at Inverted TTL levels. In order to use the port the following
micro controller pins are required:
To use serial port 1, RF3 needs to be configured as an output, and RF2 as an input. Also the
associated UART registers require configuration.
For further information on accessing ports or using the UART please refer to the data sheet at
www.microchip.com or see the supplied code samples.
LED Indicators
There are two LED's on the p.Brain module accessible by the user. These LED's have there
anode's connected to the port pins defined above. To turn on an LED, enable the relative port
bit as an output, and set the port pin high. For further information on accessing ports please
see microchips data sheet at www.microchip.com or the supplied code samples.
EEPROM Schematic
EEPROM Operation
The on board EEPROM is a microchip 24LC64 device which can accessed using the pins in the
above table. The write protect pin and address pins on the EEPROM have been tied to GND,
which gives a base address of 0xA0. Communication with the device is achieved using the
Synchronous Serial Port 1 in I2C master mode. RG2 & 3 must be configured as inputs, and
the SSP port configured as I2C master mode. For further information on accessing ports or the
24LCxx series EEPROM's please see microchips data sheet at www.microchip.com or the
supplied code samples.
RS232 Schematic
The RS232 transceiver is connected to UART2 on the PIC micro controller. In order for the
RS232 receiver to be connected to UART2 RX, JP2 must be installed in the 'R' position. This is
due to UART2 being shared between RS232 and/or ESD200 bluetooth module. See below for
operation information.
Serial port 2 can be configured as either RS232 or Bluetooth using the optional ESD200
module. UART2 TX pin is sent to both the RS232 transceiver and the ESD200 module socket.
UART2 RX pin is switched using JP2 to be driven either from the RS232 transceiver or the
ESD200 module. In order to use the port the following micro controller pins are required:
To use serial port 2, RF0,4 need to be configured as outputs, and RF5 as an input. Also the
associated UART registers require configuration.
For further information on accessing ports or using the UART please refer to the data sheet at
www.microchip.com or see the supplied code samples.
In order to get 24 channels of PWM from the dsPIC, three 1 to 8 channel multiplexors are
used. Each multiplexor has 3 address lines A, B and C and a gait line which is tied to one of
the PWM outputs from the micro controller, PWM1, PWM2 and PWM3. There are two more gaits
on the multiplexors which are tied to ground and so are not used. With this arrangement,
three PWM channels are driven at a time, one on each multiplexor. Once the PWM cycle is
complete for the current three channels, the address select lines are incremented and the next
three channels can be driven. This is repeated eight times to give the full 24 channels.
The average R/C PWM signal is 1 to 2ms long, and repeats 50 times per second. With the
multiplexor arrangement we need to output 8 PWM signals sequentially, so if we were to say
the longest PWM time is 2ms then the maximum time for 8 channels would be 16ms which
would give a maximum refresh rate of 62.5Hz. Given that there would be some time required
to service interrupts and setup registers, a more realistic refresh rate would be 60Hz.
This of course gives the maximum refresh rate for all 24 channels at 2ms PWM pulse width.
With less channels, higher refresh rates can be achieved, however, 50 or 60hz is sufficient.
You will notice in the multiplexor schematic that PWM1 does not correspond to the first
multiplexor, and the multiplexor outputs are not necessarily in ascending order in reference to
servo output connectors. This is due to PCB routing constraints and may seem confusing at
first, however, all PWM outputs can be re-mapped in software to the correct servo output pin.
(see example code)
In order to access the multiplexor block, RD0,1,2,8,9,10 must be configured as outputs in the
port configuration registers. Also output compare registers 1 thru 3 must be configured for
PWM output. For further information on accessing ports, and output compare registers please
see microchips data sheet at www.microchip.com or the supplied code samples.
Code Examples
All code examples are written for the Hitec dsPICC compiler. All code examples are subject to
the following license agreement.
The software supplied herewith by micromagic systems limited (the “Company”) for its p.Brain
controller is intended and supplied to you, the Company’s customer, for use solely and
exclusively on micromagic systems p.Brain controller products. The software is owned by the
Company and/or its supplier, and is protected under applicable copyright laws. All rights are
reserved. Any use in violation of the foregoing restrictions may subject the user to criminal
sanctions under applicable laws, as well as to civil liability for the breach of the terms and
conditions of this license.
Processor Initialisation
In the following code example you will see how to initialize the processor oscillator and
configuration bits. The processor is configured to run at 32Mhz using the 8Mhz external
resonator. The main programme then uses functions for port initialisation, serial
communications, time delays and EEPROM access. These functions are defined in the code
examples sections below.
// *********************************************************************
// DEFINITIONS
// *********************************************************************
// *********************************************************************
// HEADER FILES
// *********************************************************************
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
// *********************************************************************
// CONST STRING DATA
// *********************************************************************
// *********************************************************************
// CONFIGURATION BITS
// *********************************************************************
// *********************************************************************
// PSECT. NOT NECESSARY BUT CAN BE USEFULL FOR DEBUGGING
// *********************************************************************
// *********************************************************************
// PORT DEFINITIONS
// *********************************************************************
// *********************************************************************
// SERIAL PORT DEFINITIONS AND GLOBAL VARIABLES
// *********************************************************************
// THE FOLLOWING BAUD RATE VALUES ARE FOR CLOCK SPEEDS OF 32 MHZ
// PLEASE CONSULT THE dsPIC33F DATA SHEET FOR BAUD RATE CALCULATIONS
// OR USE THE Pic Baud Calcualator TOOL FROM MICROMAGIC SYSTEMS.
// NOTE: DO NOT USE BRGH=1 SETTING ON THIS PROCESSOR, IT DOES NOT WORK
// ON EARLY SILICON REVISIONS
// MOST PC BASED UARTS WILL ACCEPT BAUD RATE ERRORS OF +/- 3.55%, HOWEVER
// IF YOUR HOST SYSTEM ALSO HAS A BAUD RATE ERROR, YOU MAY EXPERIENCE PROBLEMS.
// *********************************************************************
// PWM DEFINITIONS & GLOBAL VARIABLES
// *********************************************************************
// *********************************************************************
// USEFULL DELAY MACROS
// *********************************************************************
// *********************************************************************
// FUNCTION PROTOTYPES
// *********************************************************************
// *********************************************************************
// MAIN CODE
// *********************************************************************
void main()
{
BYTE lT;
int lI;
// DISPLAY MESSAGE
printf(“Hello World!\r\n\r\nPress SPACE bar to continue.”);
lI = 0;
while(1) // LOOP
{
if( T1IF )
{
T1IF = 0; // RESET T1 FLAG
RED_LED ^= 1; // FLASH LED
The following example demonstrates the initialization of the processor ports and hardware
configuration registers. This function is called “Initialise()”
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTF = 0;
PORTG = 0;
// ****************************************************************
// INTERRUPT SETUP
// ****************************************************************
// ****************************************************************
// TIMER MODULES SETUP
// ****************************************************************
T1CON = 0; //
T1CKPS0 = 1; // PRESCALER 1:8
PR1 = TIMERVAL;
T1ON = 1; // T1 ON
T3CON = 0;
T3CKPS0 = 1; // PRESCALER 1:8
PR3 = 0xffff;
T3IP0 = 1; // T3 INTERRUPT PRIORITY 3
T3IP1 = 1;
T3IP2 = 0;
T3ON = 1; // T3 ON
// ****************************************************************
// INPUT CAPTURE SETUP
// ****************************************************************
// ****************************************************************
// OUTPUT COMPARE SETUP
// ****************************************************************
// ****************************************************************
// SPI MODULE SETUP
// ****************************************************************
SPI1STAT = 0; // UNUSED
SPI2STAT = 0;
// ****************************************************************
// I2C MODULE SETUP
// ****************************************************************
// ****************************************************************
// DATA CONVERTER INTERFACE MODULE SETUP
// ****************************************************************
DCICON1 = 0; // UNUSED
// ****************************************************************
// ADC
// ****************************************************************
AD1CON1 = 0; // UNUSED
AD1CON2 = 0;
AD1CON3 = 0;
AD1CON4 = 0;
AD1CHS123 = 0;
AD1CHS0 = 0;
// ****************************************************************
// UART1 SETUP
// ****************************************************************
// ****************************************************************
// UART 2 SETUP
// ****************************************************************
PMD1 = 0b1000011100011110;
PMD2 = 0b1111111111110000;
PMD3 = 0b1111111111111111;
RS232 Communications
In this example interrupt driven communications will be configured for the RS232 serial port
on UART2. The following are high level serial port functions:
//**************************************************************************
// PUTCH USED BY PRINTF COMMANDS TO TERMINAL PORT
//**************************************************************************
//**************************************************************************
// GETCHE GET BYTE FROM TERMINAL SERIAL PORT
//**************************************************************************
//**************************************************************************
// GETCHE GET BYTE FROM TERMINAL SERIAL PORT AND ECHO BACK
//**************************************************************************
lC = getch();
putch( lC );
return lC;
}
//**************************************************************************
// KBHIT FUNCTION, EG. ARE THERE ANY BYTES IN RX FIFO
//**************************************************************************
//**************************************************************************
// UART2 TX ISR
//**************************************************************************
//**************************************************************************
// UART2 RX ISR
//**************************************************************************
These examples demonstrate how to read and write to the on-board EEPROM. First we define
the low level I2C access functions:
//******************************************************************************************
// WAIT FOR I2C IDLE STATE
//******************************************************************************************
//******************************************************************************************
// START I2C
//******************************************************************************************
void i2cStart()
{
i2cWaitForIdle();
I2C1_SEN = 1;
}
//******************************************************************************************
// I2C REPEAT START
//******************************************************************************************
void i2cRepStart()
{
i2cWaitForIdle();
I2C1_RSEN = 1;
}
//******************************************************************************************
// I2C STOP
//******************************************************************************************
void i2cStop()
{
i2cWaitForIdle();
I2C1_PEN = 1;
}
//******************************************************************************************
// I2C READ BYTE
//******************************************************************************************
i2cWaitForIdle();
I2C1_RCEN=1;
i2cWaitForIdle();
i2cWaitForIdle();
if ( pAck )
I2C1_ACKDT = 0;
else
I2C1_ACKDT = 1;
return( lData );
}
//******************************************************************************************
// I2C WRITE DATA
//******************************************************************************************
I2C1TRN = pData;
High level EEPROM functions used for storing BYTE data etc:
// ************************************************************************************
// WRITE EEPROM BYTE
// ************************************************************************************
// ************************************************************************************
// READ EEPROM DATA
// ************************************************************************************
return( pData );
// ************************************************************************************
// WRITE EEPROM 32 BYTE BUFFER
// ************************************************************************************
// MUST NOT CROSS PAGE BOUNDARY OF 32, EG ONLY 5 LOWER ADDRESS BITS ARE INTERNALY
// INCREMENTED.
Delay Routines
// ************************************************************************************
// DELAY MICRO SECONDS. NEEDS ADJUSTING FOR DIFFERENT PROCESSOR SPEEDS
// ************************************************************************************
// ************************************************************************************
// DELAY MILLI SECONDS.
// ************************************************************************************
while (pDelay--)
{
CLRWDT();
lI = 4;
while(lI--)
{
DelayUs( 250 ); // ADJUST FOR ERROR
}
}
}
PWM Multiplexor
This example demonstrates how to configure the interrupt service routines for the PWM
multiplexor block. For the purpose of this example, each PWM frame will be started in the main
programme loop, once the frame is started, the output compare ISR's will continiue until all 24
PWM channels are complete. There are four multiplexors, each with six outputs giving 24
channels of PWM, using multiplexing techniques, PWM signals are created in banks of four, one
ofr each of the four Output Compare registers. See the schematic of the PWM block for further
details.
PWM Definitions
// *******************************************************
// OC1 ISR
// *******************************************************
// *******************************************************
// OC2 ISR
// *******************************************************
// *******************************************************
// OC3 ISR
// *******************************************************
// *******************************************************
// IF ALL 4 PWM OUTPUTS IN THE CURRENT BANK ARE DISABLED
// THIS TIMER IS USED TO FORCE AN INTERRUPT TO START
// THE NEXT PWM BANK.
// *******************************************************
// *******************************************************
// USED TO START THE PWM FRAME, SETS MUX ADDRESS TO 0
// *******************************************************
OC1IE = 0; // DISABLE ALL OC INTERRPUTS, INCASE WE IGNORE THE ABOVE ERROR CONDITION
OC2IE = 0;
OC3IE = 0;
// ***********************************************************************************
// THIS FUNCTION CONFIGURESS THE OC REGISTERS WITH THE NEXT BANK OF PWM VALUES
// EACH PWM START TIME IS OFFSET BY A SMALL AMOUNT DEFINED BELOW. THIS IS TO REDUCE
// SIGNAL NOISE ON THE P.BRAIN, BUT IS NOT ENTIRELY NECESSARY.
// ***********************************************************************************
#define PWM1_START_COUNT 2
#define PWM2_START_COUNT 4
#define PWM3_START_COUNT 6
// SETUP T3 TO INTERRUPT IN 50uS IN THE CASE THAT NONE OF THE CURRENT PWM BANK SERVOS
// ARE ENABLED. IF ANY OF THE FOLLOWING 4 ARE ENABLED, THE T3 INTS ARE DISABLED
// AND PR3 REG SET TO MAX.
// ***********************************************************************************
// ONCE THE PWM FRAME HAS BEEN STARTED, THIS FUNCTION IS CALLED WITHIN EACH OC ISR
// AND WITHIN THE T3 ISR (IF ENABLED) TO DETERMINE IF THE CURRENT PWM BANK IS COMPLET
// EG, ALL FOUR PWM OUTPUTS OF THE BANK ARE FINISHED. IF ALL FOUR CHANNELS OF THE BANK
// ARE COMPLETE, IT THEN CHECKS IF THE FRAME IS COMPLETE.
// ***********************************************************************************
if( OC1IE || OC2IE || OC3IE ) // IF WE HAVE NOT DONE ALL 4 OUTPUTS, RETURN.
return;
// ***********************************************************************************
// WHEN DESIGNING THE p.Brain-u24 MODULE, IT IS NOT ALWAYS
// POSSIBLE TO ROUTE THE PWM OUTPUTS TO THE MOTHERBOARD AREA THAT IS DESIRED, THEREFORE
// IT IS NECESSARY TO RE-MAP THE SERVO OUTPUTS IN SOFTWARE.
// ***********************************************************************************
Legal
Please read fully before purchasing any merchandise from micromagic systems ltd.
PRODUCTS
In no event shall micromagic systems be liable for any claim for incidental, consequential damages, or any
injuries sustained due to the use of or improper use of products and / or kits purchased out of or in connection
thereof with the manufacture, sale, delivery or use of any product in this catalogue or web site. All micromagic
systems products purchased should NOT be used for medical, life-saving, life-support, or any applications that
could cause injury, dangerous / hazardous situations or consequential damages resulting from the use of the
mechanical, hardware or software products sold or represented by micromagic systems.
All products sold by micromagic systems are for Self Learning Experiences, and for Safe Entertainment.
Note
Product specifications, prices listed and availability of items in our web site and in our printed catalogue are
subject to change without notice. All prices shown in our web site and in our printed catalogue are believed
accurate at time of publication, but subject to change without any notice. We will always advise you of the new
price increase and seek your approval before processing any orders you place.
If you receive damaged merchandise, you must contact micromagic systems within 2 days of receipt of your
original order. Specify clearly the reason for your refusal. We will exchange returned merchandise for same new
merchandise, or for the item sterling amount within 7 days once we receive the returned damaged items from
you. Proof of mailing is advised, as we cannot be held responsible for loss of the returned merchandise in mail
transit. All return postage is non-refundable. The merchandise, including packing and wrapping material, being
returned should be in the same condition as when you received them. Please contact us via e-mail at
[email protected]. Defective merchandise will be replaced (No cash will be refunded). We
reserve the right to refuse to replace any merchandise, which our micromagic systems technicians determine to
be damaged by the user, or through inappropriate use of that merchandise.
WARRANTY POLICY
We guarantee all products except electronic kits to be free of defects in workmanship and material for 30 days
from the purchase, delivery date. We will repair or replace non-electronic kits (No cash will be refunded), at our
option providing there is no evidence of customer misuse or alteration to that product item.
micromagic systems carries a limited 30 day warranty on most all items, some items carry an additional
number of warranty days or special restrictions. If you want specific warranty information about a product
contact micromagic systems to obtain that information.
We are not able to offer any refunds or accept returns for the following items and products: Electronic Kits.
CANCELLATION POLICY
Please be aware that if you cancel an order you may be responsible for restocking fees and / or shipping
charges, including charges for return shipping. Cancelled orders are subject to a 25% or £10.00 minimum
restocking fee. Orders cancelled within 24 hours of order placement will not be subject to restocking fees
however this does not apply to orders with Express Shipping and Handling.