PEL4 Documentation in Microsoft Word forma

By Melvin Hunter,2014-06-11 13:35
14 views 0
PEL4 Documentation in Microsoft Word formain,In,Word,forma,WORD,Forma,word

     Power connector Power jumper: 7 to 28 volts position

    Pin 1 RS-232

    Connector to

    PC Pin 2

     32-pin I/O Reset switch Microcontroller: connector PIC 16C73


    Personal Electronics Laboratory 4

Complied by: M.J. Batchelder

    Date: October12, 1999

    Revised: January 18, 2000

    Based on data supplied by ChT

    All hardware and software is copyrighted by ChT Engineering Systems, 1998


    Power jumper top:

    Power in 7 to 28 Volts


    Power jumper bottom:

    Power in 5 volts Power In



    depends on

    power jumper


Important: Power jumper setting must be correct or PEL4

    could be damaged!



    The PIC 16C73 Microcontroller

    The “brain” in the PEL4 is a PIC 16C73 microcontroller from Microchip. The controller is equipped with 4k x 14 ROM and 192 x 8 RAM, and has an analog-to-digital (A/D) converter on board. It is running at 20Mhz. It has 22 I/O lines, used as follows:

    8 are used for digital output

    1 is used for turning on and off the LED's

    3 are used for digital input

    4 are used for analog to digital conversion

    2 are used for digital to analog conversion

    2 are used for pulse width modulation output

    2 are used for RS-232 serial communication

The PEL4 Interface

    The PEL4 interfaces to the world with three connectors in addition to a reset button and a 10-digit bargraph.

    +5 volts 1 2 +5 volts

    Digital In 0 3 4 Digital Out 0

    Digital In 1 5 6 Digital Out 1

    Digital In 2 7 8 Digital Out 2

    Digital In 3 9 10 Digital Out 3

    Digital In 4 11 12 Digital Out 4

    Digital In 5 13 14 Digital Out 5

    Digital In 6 15 16 Digital Out 6

    Digital In 7 17 18 Digital Out 7

    PWM 1 19 20 Extra LED 0

    PWM 2 21 22 Extra LED 1

    Analog In 0 23 24 Analog Out 0

    Analog In 1 25 26 Analog Out 1

    Analog In 2 27 28 I2C SCL

    Analog In 3 29 30 I2CSDA

    Ground 31 32 Ground

    Figure 1. Main Interface Header Layout

    Digital Out - There are 8 pins located for digital output. Digital Out 0 is the least significant bit (LSB)

    while Digital Out 7 is the most significant bit (MSB). Together they can represent a binary

    number from 0 to 255. Each bit can also be addressed individually.

    Digital In - Right next to the digital out ports, is the digital input side. Again, Digital In 0 is the LSB

    while Digital In 7 is the MSB. This input is latched through a 74LS165 to reduce the

    number of I/O pins used.

    PWM - Two pins are used for pulse width modulation (PWM), PWM1 and PWM2. PWM1 has a

    set frequency of 100 Hz and can be programmed with duty cycles from 25% to 75%.

    PWM2 can be programmed with various frequencies from 1250 Hz to 50KHz and variable

    duty cycles from 0% to 100%.

    Analog Out - There are two analog output pins. They both can be programmed from 0 to +5 volts (8-bit

    resolution). The D/A uses the power supply as its reference; thus, the accuracy of the output



    depends on the accuracy of the 5 volt power supply.. Note: jumpers on JP3 are required to

    use the analog output channels.

    Analog In - Four multiplexed analog-to-digital converters are located on the header. These will read

    voltages from 0 to +5 volts (8-bit resolution). The A/D converter uses successive

    approximation and yields an error of 1 bit or approximately 20 mV.

    Extra LED - There are also two pins made available that connect to the LED bargraph. These two ports

    have current-limiting resistors connected, meaning that a +5 volt source will make the

    LED's turn on.

    Power - There are four pins on the I/O interface that can either be used as power input or power

    output (depending on how JP1 is programmed). The total current through these pins should

    never go above 1 ampere. The power input, Vcc, is located at pin 1 and 2 while GND is

    located at 31 and 32.

    The board’s power is provided by using a male 2.5mm plug. The center pin is power while

    the sleeve is ground. Depending on the programming of JP1, a range of voltages can be


    A fuse, F1, and a rectifying diode provide a limited protection of the input power. In the

    case of reverse voltage, the diode will short the input and the fuse will blow. The system

    will not protect from using the wrong voltage with the wrong programming of JP1!

    To convert voltages over +5 volts a LM7805 voltage regulator is provided. When JP1 is

    correctly programmed it will take its input from the power connector and provide the PEL4

    with +5 volt regulated power. The input range should be between +7 and +28 VDC.

    A jumper (JP1) has been provided to allow for configuration of the power source to the

    PEL4 Great care should be taken when choosing the desired program. Incorrectly

    programmed jumper will result in the PEL4 being destroyed!!! Three valid programs can be

    used. (1) Use power from I/O Connector (Fuse disabled), (2) Use onboard voltage regulator

    (+7 to +28 should be provided on the power connector), (3) use external regulator (+5

    regulated power should be provided on power connector). CAUTION, never have two

    jumpers placed on JP1 at any time. This results in a hazardous situation where the voltage

    regulator can burn!!!

1) A reset button is provided on the board to restart the system.

    2) To better see the state of the digital output pins, a 10-digit LED bargraph is provided. Each LED will monitor the digital output line located right next to it. When a digital output pin is one (+5 volts), the LED will turn on. The two lower LED's are connected to the main interface, and can be activated by providing +5 volts to the Extra LED 0 and Extra LED 1 pins.



    PEL4 as PC Peripheral

    The PEL4 can be used as a peripheral connected to the PC through the serial port or it can be used as a stand-alone device. When connected to the PC it can be used in manual mode with a terminal program or in program mode with a user program controlling the PEL4.

    Manual Mode

    The PEL4 "Operating System"

    The PEL4 is fitted with a tiny operating system that gives the user easy access to the functions inside the firmware. Each command is typed in as a two-letter word, followed by parameters. Since the system is accessible through a standard Terminal program, these functions can by typed in by hand, or one can choose the “silence” mode to interface directly to a computer program. The cable to the PEL4 is a standard

    RS-232 cable; in other words pin 2 to 2, pin 3 to 3, and pin 5 to 5. (NOT A NULL MODEM). When using HyperTerminal to communicate with the PEL4 use the settings:

    Baudrate: 19200

    Data Bits: 8

    Parity: None

    Stop Bit: 1

    Flowcontrol: None

    Due to memory restrictions in the microcontroller, almost no error controls are performed. To correct an error simply type the command over again. Note that combinations of letters not listed in the next section can accidentally trigger a function.


    VO - Visible On. Turns on the visual interface. When the command is entered, the system logo will

    appear to indicate that the system works. Commands are echoed, and the error message is

    displayed when errors are detected.

    VF - Visible Off. There is no echo of typed commands and error messages are not displayed. Only

    return from input functions are displayed.

    LO - LED On. Will enable the LED's connected to the digital output port. The LED's will monitor

    the digital output port located next to it.

    LF - LED Off. This disables the LED's connected to the digital output port. The two extra LED

    interfaces will still be operational.

    DO,x - Digital Out, x is value 0 to 255 decimal. An eight bit binary value is placed on the digital

    output port. The port will keep its value until “overwritten”

BO,x,y - Bit Out, x is the bit (0-7), y is the value (0 1). To set (+5 volts) or clear (GND) a single pin

    this command can be used. If a bit is already set (or cleared) no change will appear. The pin

    will keep its value until “overwritten”

    DI - Digital In, Displays value of input port. This command will read the value of the digital input

    port, and display the value as a number between 0 and 255.

    BI,x - Bit In, x is the bit (0-7). Each bit can be read independently by this command. The result will

    be either 0; the bit is cleared (GND) or 1; the bit is set (+5 volts)



    DC,x - Digital In Continuously, x is delay (0-255) in ms between readings. If continuously reading of

    the digital input port is desired, this command can be used. Each reading will be separated by a

    pause in 0-255 ms. To stop the reading press any key.

    AO,x,y - Analog Out, x is channel (0 or 1), y is the value (0-255). To place an analog signal on the

    analog output port, choose the channel and the desired value. The signal will be in form of a

    voltage representation (0 to +5 volts) of the input value (0 to 255). The output signal will be on

    the port until it is “overwritten” or power is turned off.

    AI,x - Analog In, x is the channel (0 or 3). Four analog-to-digital converters can be read by this

    function. Simply specify the port number (0 to 3) and the function will return a number

    between 0 and 255 representing the voltage (0 to +5 volts).

    AC,x,y - Analog Continuously In, x is the channel (0 or 3), y is the delay in ms (0-255) between each

    reading. Use this function to rapidly read an analog input port. A delay between 0 and 255 ms

    can be inserted between each reading. Any key will halt the process.

    AA,x,y -- All Analog Continuously In, x is the delay between each channel in ms (0-255), and y is the

    number of sets (0-255). This is the same function as AC, but this will read all four analog input

    ports. A delay between each channel reading can be inserted, and the number of sets can be set.

    If the number of sets is set to 255, the system will keep reading the channels until a key is hit.

    TI,x - First Pulse Width Modulator, set frequency at 100Hz, x is pulse width (25-75) in percent. This

    function will provide a pulse of 100Hz on the PWM1 port. The duty cycle of the signal can be

    changed between 25% and 75%. Once started it will only change if a new value is written to it.

    Reset will turn of the PWM generator.

    PS,x - Set PWM2 Frequency, x is the frequency (1250, 2000, 3000, 4000,…, 19000, 20000, 25000,

    30000, … ,50000) in hertz. To get increased frequency range and wider range of duty cycles,

    PWM2 should be used. This function will set the frequency of the PWM2. 26 different

    frequencies are provided, ranging from 1250Hz to 50000Hz. To stop the function the duty

    cycle should be set to 0 or 100.

PW,x - Set PWM2 duty cycle, x is the duty cycle in percent (0-100). This will set the PWM2’s duty

    cycle. Any value from 0% to 100% is accepted.



    Program Mode

The normal use of the PEL4 is with a program on the PC that issues the commands to the PEL4 "operating

    system". The interface code to the PEL4 is contained in PEL4.h that should be included in a C++ program

    that uses the PEL4 as the following example shows.

    //---------------------------------------------------- // DATE: Dec 29, 1999

    // PROGRAMMER: M.J. Batchelder

    // ORGANIZATION: Mechatronics Class

    // STATUS: Alpha test

    // FILE: PELtest1.cpp

    // COMPILER: Borland C++

    // DESCRIPTION: Simple test program to read the A/D converter // and display result on the screen.


#include "pel4.h" //PEL 4 functions

    #include //cin, cout functions #include //kbhit, getch, clrscr functions #include //delay function

void main()


    int Channel = 0; //A/D channel number

    int NoSamples = 10; //Number of samples to read

    int TimeInMs = 100; //Time between each sample

    int i; //Loop variable

    char ch; //

    PelInit(1); //Init PEL 4 to operate on comm port 1

    while (!kbhit()); //wait for start keypress

    ch=getch(); //clear keyboard buffer of keypress

    clrscr(); //Clear screen

    for (i=1; i <= NoSamples; i++) //Read a sample from the A/D


    cout << AnalogIn(Channel) << endl; //Read value and print

    delay(TimeInMs); //delay





    PEL4 Standalone

    The PEL4 can be used as a standalone device by programming the PIC microcontroller directly in PIC assembly language or using the PCM PIC C compiler (or other compiler generating PIC code). A PIC programmer is required to use the PEL4 in this manner. An example program using the PCM compiler follows. The program reads the digital input and sends the value out through the serial port.

     /***************************************************************************/ /*** Title : PEL Jr. Sample Code 004 ***/ /*** File : PJR_S004.C ***/ /*** Descr.: This code is to be used on the PEL Jr. using a PIC16C73 or ***/ /*** compatible chip. ***/ /*** ***/ /*** The PEL Jr. will read the digital input and display the ***/ /*** result on the serial interface. ***/ /*** ***/ /*** Author: Alf Riisnaes ***/ /*** Date : 02/07/99 ***/ /*** Inst. : ChT Engineering Systems ***/ /*** Source: CCS Compiler v2.631, C ***/ /*** SW Rev: 1.4 ***/ /*** HW Rev: 3 Proto ***/ /*** ***/ /*** This code sample should only be used as a tool in introducing the ***/ /*** user to program the PEL Jr., and should not be redistributed!!!!! ***/ /*** ***/ /*** Copyright 1999 ChT Engineering Systems, All Rights Reserved ***/ /***************************************************************************/ /***************************************************************************/ /*** I N C L U D E S ***/ /***************************************************************************/ #include <16C73.H> // PIC16C73 library (Modified Version) #include /***************************************************************************/ /*** D E F I N E S ***/ /***************************************************************************/ #define Dig_In_Data PIN_C0 #define Dig_In_Clk PIN_C1 #define Dig_In_Latch PIN_C5 #define RS232_TX PIN_C6 #define RS232_RX PIN_C7 #define En_Dis_LED PIN_A5 #define all_out 0 /***************************************************************************/ /*** C O M P I L E R S E T U P ***/ /***************************************************************************/ #byte portb=6 // Must be used to get direct access to port b #use delay(clock=20000000) // Use 20 Mhz crystal #use rs232(baud=19200, xmit=RS232_TX, rcv=RS232_RX) // Use 19200 =baud /***************************************************************************/ /*** M A I N P R O G R A M ***/ /***************************************************************************/ void main(void) { char in_key; byte i; // Temporary counter byte dig_in; // The value found on the port output_high(En_Dis_LED); // Disable LED's printf("\n\r\n\r");



puts(" Please press a key when the digital input should be sampled!!"); in_key=getc(); output_high(Dig_In_Clk); // Set clock high output_low(Dig_In_Latch); // Set latch low output_high(Dig_In_Latch); // Set latch high to initiate input for(i=1;i<=8;++i) // Find 8 bits { shift_left(&dig_in,1,input(Dig_In_Data));// Place bit in dig_in and shl output_low(Dig_In_Clk); // Clock the shift register to next bit output_high(Dig_In_Clk); } output_low(Dig_In_Latch); // Set latch low to end session printf("\n\rThe value on the DigIn port is %u",dig_in); printf("\n\rEND!!!!\n\r\n\r"); }



Adding I2C Interface on I/O Connector

    To be able to connect several PEL4 together the two I2C pins are provided on the I/O Connector. These pins are also controlling the Digital to Analog Converter (DAC), so care must be taken whenever these two pins are used (the I2C address of the ADC is 0x58). If the DAC is not used, the pins can be used as standard I/O pins. Depending on the application the pull up resistors might have to be disabled by removing jumpers on JP3.

Programmable Pull-ups on I2C lines.

    JP3 has been provided to enable (jumpered) or disable (not jumpered) the pull-up resistors on the I2C lines. Be advised that with the pull-ups disabled the digital to analog converter will not work, and subsequently the output from the DAC (pin 24 and 26 on the I/O Connector) has undetermined value.

Optional RS-485 Interface

    The PEL4 has place for an optional circuit to provide an RS-485 interface. It uses the same lines as the I2C interface, and thus the DAC can not operate at the same time as the RS-485. In addition, the I2C pull-ups should be disconnected before the circuitry will work properly. To be able to use the RS-485 Interface the optional RJ-45 connector should also be chosen. To provide proper termination

Optional RJ-45 Connector

    The RJ-45 optional connector will provide the PEL4 with all power and interface needs. The connector will provide power (connected to the power connector input), ground, RS-485 interface and RS-232 interface. In other words, the unit can be accessed with only one cable through this connector. The RJ-45 Connector is physically placed on top of the DB-9 connector, and thus only one can be used at a time.

Optional Development Board Hardware

    The Development Board consist of four major parts; (1) a male header that fit into the female I/O Connector on the PEL4, (2) a double RJ-45 connector which is daisy chained, (3) a RS-485 driver and (4) a prototype area.

    A jumper has been provided to enable termination of the RS-485 line. Only the first and the last in the chain should be terminated.

    Power can either be supplied to the PEL4 or taken from the PEL. If the board is supplying the PEL4, only +5 volts should be used. The programmable power jumper on the PEL4 should be programmed accordingly.


Report this document

For any questions or suggestions please email