back to notes

The TEA 2 Hardware Guide For Programmers

by Kristof Van Laerhoven @ Starlab Belgium


Contents

  1. Required to program 
  2. Datasheets 
  3. The Layout 
  4. The Connectors 
    1. the serial connectors 
    2. the programmer connectors 
    3. the power connector
    4. the phone connector
  5. The 16F877 pin connections 
  6. How to program the PIC for... 
    1. the ADXL202 
    2. the DS1820 
    3. microphones 
    4. photodiodes 
    5. the touch sensor


Required to program

  1. MPLAB, MPLAB-ICD [download user's guide & tutorial]
  2. PIC C compiler (the PICC by CCS for example)
[go to top]


Datasheets

  1. 16F87X PIC by Microchip
  2. Max232E  RS232 Transceiver by Maxim
  3. SN74HC153 Data selector/Multiplexer by Texas Instruments
  4. DS1820 1-Wire Digital Thermometer by Dallas Semiconductors
  5. ADXL202 Accelerometer by Analog Devices
  6. TLC27L4 OpAmp by Texas Instruments
  7. Microphones
  8. TLC1515-3/5 by Linear Technology
[go to top]


The Layout / Design


[go to top]


The Connectors

serial connection to the TEA2 board:

To connect a standard 9-pin serial port to the TEA board, one has to connect pins 1, 2, and 3 of J4 to pins 2, 3, and 5 of the port.
 
J4 (the serial connector on the TEA board): standard 9-pin serial RS232 connector:
1: receive (2) 2: ground (3) 3: send (1)


1: not used 2: send 3: receive 4: not used 5: ground
6: not used 7: not used 8: not used 9: not used
[go to top]

programmer connection:

 The connector to the ICD-programmer  J5 (the programmer connector on the TEA board)


1: not used 2: clock 3: data 4: ground 5: VCC 6: reset

1: ground 2: data 3: clock 4: reset 5: VCC

[go to top]

power connection:

1: ground 2: 3.3 V

[go to top]

phone connection:

To use the phone connector, you have to:
  1. connect the phone to the connector (see figure)
  2. switch the jumpers in front of the phone connector
 The connector of a Nokia GSM  Pinout of the phone connector


  1. Charger input voltage 
  2. Charger control PWM 
  3. Mic input 
  4. Signal ground 
  5. Ear output 
  6. MBUS 9600 bit/seg. 
  7. FBUS-> RX 
  8. FBUS->TX
  9. Ground 

[go to top]
 


The 16F877 pin connections

PIN name
PIN nr
Function
Connected to ...
OSC1/CLKIN 14 Oscillator HS 20Mhz
OSC2/CLKOUT 15
MCLR/VPP 2 master clear programmer (J5)
RA0 3 read microphone1
RA1 4 read microphone2
RA2 5 read photodiode1
RA3 6 read photodiode2
RA4/T0CKI 7 (timer0 clock input)
RA5/SS 8 (synchronous serial slave select) J3
RB0 36 select 0 accelerometer (SN74HC153 -> ADXL202)
RB1 37 select 1
RB2 38 J1
RB3 39 J1
RB4 41 read/write temperature (DS1820)
RB5 42 read touch
RB6 43 serial programming clock programmer (J5)
RB7 44 serial programming data programmer (J5)
RC0/T1OSO/T1CK1 16 (timer1 oscillator i/o)
RC1 18 read accelerometer (SN74HC153 -> ADXL202)
RC2 19 read
RC3/SCK/SCL 20 (synchronous serial clock i/o for SPI or I2C)
RC4/SDI/SDA 25 (SPI Data in) (data I/O for I2C)
RC5/SDO 26 (SPI Data out)
RC6/TX 27 transmit RS232 (MAXIM220E)
RC7/RX 29 receive
RD0/PSP0 21 (parallel slave port) J8
RD1/PSP1 22 (parallel slave port) J8
RD2/PSP2 23 (parallel slave port) J8
RD3/PSP3 24 (parallel slave port) J8
RD4/PSP4 30 (parallel slave port) J8
RD5/PSP5 31 (parallel slave port) J8
RD6/PSP6 32 (parallel slave port) J8
RD7/PSP7 33 (parallel slave port) J8
RE0/RD 9 J3
RE1/WR 10 read touch
RE2/CS 11 J3
VSS 13 ground
VDD 12 positive
VSS 34 ground
NC 1
not internally connected
NC 17
NC 28
NC 40
NB: text between ( ) means this function is optional, but not used

[go to top]


Settings of the programmer

configuration bits: program options to check: further settings: Check also that the voltages are right ( around 5V for VDD, and around 13V for VPP)


How to program the PIC for...

1. The ADXL

The ADXL values are read by first selecting the desired value (X-axis or Y-axis acceleration): pins B0 and B1 are used for this:
 
To select... set pin B0 set pin B1
read X-axis 0 1
read Y-axis 1 1

Then, the value can be read from pin C1 or C2 (you choose). However, that's not it, yet: the values are given through duty cycles. This means that the values should be calculated by dividing the pulse-width by the period, eg. for:
 

     ______        __   _______      ________         _____       _______
____|      |______|  |_|       |____|        |_______|     |_____|       |__

                                    aaaaaaaaaa 
                                    bbbbbbbbbbbbbbbbb

the fourth incoming value would be calculated by (a/b).

example program in C:
 

if (read_X) 
            output_low(PIN_B0);
else // if read_Y
            output_high(PIN_B1);

output_high(PIN_B1);

while( input(PIN_C1) );   // wait until low
while( !input(PIN_C1) );  // wait until high
while( input(PIN_C1) ) {  // count high-time
            high++;
}
while( !input(PIN_C1) ) { // count low-time
            low++;
}
// calculate value:
value = high/(high+low);

[go to top]

2. The DS1820

The Dallas DS1820 is a 1-wire sensor, which means only one pin (B4 in this case) is needed to send a request and receive the temperature. The most used commands are:
 
command: value: (hex format)
skip ROM (for a single bus system) 0xCC
convert temperature (*) 0x44
Read DS1820's Scratchpad 0xBE

(*): note that this takes 500 ms !

You'll need to initialize the DS1820 every time you want to issue a command. This means forcing the pin to the sensor to a low state (=reset pulse) for 480 up to 960 µsecs, after which the DS1820 will send back a presence pulse lasting 60-240 µsecs. Thus, to just get the temperature, you need to do the following:

  1. initialise (= send reset pulse)
  2. skip ROM
  3. convert temperature
  4. initialise again
  5. skip ROM again
  6. read the 9 bytes from the Scratchpad (=result from measurement)
Here's the C source code to init, send and receive data (see the datasheet for in-depth description)- this should work using 4 for sensor, 0x86 for TRISB, 0x06 for PORTB, 0x03 for STATUS and 5 for RP0 (coming from the 16F877 datasheets):
 
void _1w_init(int sensor) {
   _1w_pin_hi(sensor);
   _1w_pin_low(sensor);
   delay_us(550); // ok.
   output_float(PIN_B4);
   delay_us(15);    // wait for presence pulse
   delay_us(285);   // wait until presence pulse is over 
}


int _1w_in_byte(int sensor) {
   int n, i_byte, temp, mask;
   mask = 0xff & (~(0x01<<sensor));
   for (n=0; n<8; n++) {
      PORTB=0x00;
      TRISB=mask;
      TRISB=0xff;
#asm
      CLRWDT
      NOP
      NOP
#endasm
      temp=PORTB;
      if (temp & ~mask) {
        i_byte=(i_byte>>1) | 0x80; // least sig bit first
      }
      else {
        i_byte=i_byte >> 1;
      }
      delay_us(60);
   }
   return(i_byte);
}


void _1w_out_byte(int d, int sensor) {
   int n, mask;
   mask = 0xff & (~(0x01<<sensor));
   for(n=0; n<8; n++) {
      if (d&0x01) {
         PORTB=0;
         TRISB=mask;  // momentary low
         TRISB=0xff;
         delay_us(60);
      }
      else {
          PORTB=0;
          TRISB=mask;
          delay_us(60);
          TRISB=0xff;
      }
      d=d>>1;
   }
}


void _1w_pin_hi(int sensor) {
   TRISB = 0xff;
}


void _1w_pin_low(int sensor) {
   PORTB = 0x00;
   TRISB = 0xff & (~(0x01 << sensor));
}


void _1w_strong_pull_up(int sensor) {
   PORTB = 0x01 << sensor;
   TRISB = 0xff & (~(0x01 << sensor));
   delay_ms(500);
   TRISB = 0xff;
}

The read Scratchpad gives 9 (nine!) bytes. The last byte is a CRC value, which can be used to check if the transmission of the first 8 bytes was flawless. To calculate the temperature, we need only the first two bytes.
 
 

Byte Description
0 Temperature Least Significat Byte (LSB)
1 Temperature MSB
2 Temperature High (TH) since last power-up
3 Temperature Low (TL) since last power-up
4 <reserved> 0b11111111
5 <reserved> 0b11111111
6 count remain for obtaining higher resolution
7 count per °C for obtaining higher resolution
8 CRC check

But even then, we have to do some minor calculations on the first two values before we get the temperature itself: the MSB byte is either 0b00000000 (for positive temperature) or 0b11111111 (for negative temperature). The first LSB byte is the actual temperature (absolute) value, multiplied by 2 for positive values, and twos complement multiplied by 2 for negative values. Thus to know the exact temperature, we need to divide the second byte by 2. Resolution is therefore 1/2°C. So the program to get a normal temperature value in °C should look like this:
 

// get the 9 bytes from DS1820
int i;
for (i=0; i<9; i++) {
          received[i] = inByte(PIN_B4);
}
// calculate temperature
if (received[1] == 1) { // if positive, divide by two
          value = received[0]/2.0;
}
else {                  // else 2's comp and divide by two
          received[1] = ((received[1] ^ 0xFF))+1;
          value = received[0]/2.0;
}

It is also possible to enhance the values's resolution, to do the CRC check, or to do something with the TL and TH values. Check the DS1820 datasheet/notes for those.

[go to top]
 

3. Microphones

Reading the microphones is easy: just convert the analog signal at PIN_A0 (or PIN_A1) to a digital value*:
 
int value;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
value = read_adc();

*remark: here we just take an 8-bit value, although the AD conversion really outputs a 10-bit value. Change int to long int to cope with this.

[go to top]
 

4. Photodiodes

Getting the data is easy. See Microphones and replace PIN_A0 and PIN_A1 with PIN_A2 and PIN_A3.

[go to top]
 

5. The Touch sensor

Same AD-conversion method as with the microphones and photodiodes.

[go to top]
 
 

For questions, remarks, etc. contact the author at kristof@starlab.net, or kofi@starlab.net (08/2001: obsolete: use the comp.lancs address)