Lab3 - Implementation of ARM7 based System with Multiple Analog and Digital Sensors

Lab 3 - Implementation of ARM7 based Embedded System with Multiple Analog and Digital Sensors

Abstract

Using ARM S3C44BOX development board, design and implementation of an embedded system with two digital sensors input and three analog sensors input is discussed. DS1620, digital temperature sensor, is used for digital input and potentiometer is used for analog input. For testing the digital part, temperature sensed by DS1620 is displayed and for analog part, calibration of potentiometer is shown by changing its value to different voltages and its digital value is read out.

1. Introduction

  • In this project interfacing of digital and analog device to the ARM S3C44BOX development board is depicted. In digital part, a temperature sensor DS1620 [Ref.4] is used. For implementing two digital sensors input to the S3C44BOX and having single data line, a device must be used such that at a time only one digital sensor can communicate to ARM board. This problem is solved by using digital multiplexer between ARM board and the sensors. Multiplexer has two or more input line and has only one output line. Configuring the selection pins of multiplexer, it can be decided that data which input line would be on output line. In this project mux is used for multiplexing the input data.
  • In analog part, for demonstrating the project only one analog sensor input is used. This analog device is potentiometer. For testing potentiometer output it is calibrated to different voltage values and its digital value is shown. Now, for implementing two or more analog devices, again analog multiplexer must be used to multiplex two or more analog device data. For this project DIP switch is used for multiplexing the analog inputs.

2. Methodology

  • In this section objectives and technical challenges of the project is discussed in first part. In second part, problem formulation and design of project including both hardware and software approaches are explained in detail.

2.1 Problem Formulation and Design

  • In this part analog and digital part of the project are discussed. In the first part of the discussion hardware problem formulation and design is explained. Fig. 2.1.1 shows the simplified block diagram. Block diagram shows the interfacing of for both analog and digital. In digital portion of the diagram single temperature sensor DS2620 is interfaced with ARM development board S3C44BOX.
  • Here 3- way communication is used for communicating between ARM board and DS1620. It is needed to connect 3 pins of DS1620, DQ, CLK/CONV and RST, to the CPU. In CPU side Port D is used to connect DS1620. Pin 1 of DS1620, DQ, is connected to the pin 98 of S3C44BOX , which is pin 0 of port D. Pin 2 of DS 1620 is CLK/CONV which is connected to pin 97, GPD1, of CPU. Pin3 of DS1620,RST, is connected to pin 96 which is GPD2. The supply voltage VDD of DS1620 is between 3V and 5V. Here 4.5V is supplied through battery.
  • In analog part, here potentiometer is used whose change in resistor will change the voltage and is given to ARM development board. Here operational amplifier LM741 is for gain. Supply voltage 5V is given to the potentiometer and potentiometer is connected to the non inverting pin of op-amp L741. The output of op-amp is connected to one of analog input pin of S3C44BOX. Here the output of op-amp is connected to AIN0, pin 75, of S3C44BOX.
  • In software part, the programming of project is explained by flow chart and pseudo code.

Flow chart of main program

Pseudo Code for main program

M1. Initialize the functions and variables.

M2. Port initialization Port_Init(); and UART initialization Uart_Init(0,115200);

M3. Enter the choice for the the input to be executed.

Either it is analog or it is digital.

Pseudo Code for Analog

A1. Configure analog to digital conversion control register rACCON.

A2. Start ADC converision at AIN0 rADCCON 0x1| (0x0<<2);

A3. Clear start bit to avoid first flag error case

While(rADCCON & 0x1);

A5. To avoid second flag error case put for loop

for(i=0;i<rADCPSR;i++);

A6. Display the output on hyper terminal

Flow chart of analog part

Flow Chart of Digital part

Pseudo Code for Digital

D1. Initialize the variables.

D2. Configure the Port D as output port.

D3. Activate 3- way communication by activating RST rPDATD= 0x004;

D4. Configure DS1620 in write mode datavalue= 0x000c;

D5. Configure DS1620 for CPU and 1SHOT mode datavalue= 0x0003;

D6. Set upper and lower limit of temperature datavalue= 0x001; & datavalue= 0x002;

D7. Issue start conversion.

D8. Issue stop conversion after some time.

D9. Configure port D pin 0 as input.

D10. Set DS1620 in read mode.

D11. Read low and high temperature limit.

D12. Display the output on hyper terminal.

3. Implementation

  • In this section implementation of the project is discussed. Hardware implementation is discussed first. You need to establish the hardware properly. For digital portion pin 1,2 &3 (DQ, CLK/CONV & RST) of DS1620 should be connected properly to ARM board. For knowledge of pin assignment and features of DS1620 refer the appendix 2. For analog part you need only to connect potentiometer properly to op-amp LM741 for non-inverting configuration. For detail information of op-amp LM741 refer appendix.
  • Then the output of op-amp is connected to ARM CPU. For the software section you need to write a C program for that. ARM Project manager is used to compile the C code. For writing C program you need to configure many special function registers like PCOND, PDATD, ADCCON, ADCPSR etc. How to configure all these register according to their need is given appendix. There are also three registers in DS1620. They are TH, TL, and Temperature. For information of these register refer appendix 2.

4. Testing and verification

The HyperTerminal program is used to verify the design. The following procedure has been followed to execute the program.

  1. Compile the program as a bootable image.
  2. Download the binary to the board.
  3. Connect the serial port of the board to the PC.
  4. Launch and initialize HyperTerminal.
  5. Power up the board.
  6. On hyper terminal there is selection shown. Select the sensor whose output you want to see on hyper terminal.
  7. For digital part the concerned temperature can be seen on the screen.
  8. For analog part the related output can be seen on the hyper terminal. As the there is change in resistor, there is a change in output.

Figure 4.1 shows the result of the tests.

5. Conclusion

This project involves the design and implementation of analog and digital sensors to ARM board. The design has been successfully implemented and verified to be correct. More experience can be acquired by this project and it can be utilized for more complicated projects.

6. References

[1] H. Li, “Author Guidelines for CMPE 242 Project Report”, Lecture Notes of CMPE 242, Computer Engineering Department, 2007.

[2] CTI Development Board Distribution CD, CTI Plus Corporation, Palo Alto.

[3] Datasheet of S3C44BOX development board.

[4] Datasheet of DS 1620.


Appendix 1: Source Code
#include <string.h>
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\utilities.h"
void Main(void)
{
  int i,j;
  int mclk=MCLK;
  rSYSCFG=SYSCFG_8KB;
 #if (PLLON==1)
   ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
   Port_Init();
   Uart_Init(0,115200);
   Uart_Select(0);
   Delay(20);  //calibrate Delay()
      
while (1)
   {
     j=0;
Uart_Printf (" Digital and Analog Sensor Interface Design   \n");
     
     Uart_Printf("%s:%s\n","Select 1","Analog sensor 1");
     Uart_Printf("%s:%s\n","Select 2","Analog sensor 2");
     Uart_Printf("%s:%s\n","Select 3","Analog sensor 3");
     Uart_Printf("%s:%s\n","Select 4","DS1620 sensor 1");
     Uart_Printf("%s:%s\n","Select 5","DS1620 sensor 2");
     Uart_Printf("%s:%s\n","6","Exit");
     Uart_Printf("\nSelect the function to test?");
     j=Uart_GetIntNum();
     Uart_Printf("\n");
      switch(j)
    {
     case 1 :  
Uart_Printf ("   Analog Sensor  \n");
rADCCON=0x1|(0x0<<2);      
while(rADCCON &0x1);
while(!(rADCCON & 0x40))
for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
Uart_Printf("Analog sensor1 output =%03x h\n",rADCDAT);
break;
      
case 2 :
Uart_Printf ("\n\n\nAnalog Sensor 2\n");
rADCCON=0x1|(0x1<<2); //Start A/D conversion AIN1
while(rADCCON &0x1); //To avoid The first FLAG error
while(!(rADCCON & 0x40));
for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
Uart_Printf("Analog sensor2 output =%03x h\n",rADCDAT);
break;
      
case 3 :
Uart_Printf ("   Analog Sensor 3 \n"); rADCCON=0x1|(0x2<<2); //Start A/D conversion AIN2
while(rADCCON &0x1); //To avoid The first FLAG error
while(!(rADCCON & 0x40));
for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
Uart_Printf("Analog sensor3 output =%03x h\n",rADCDAT);
break;
      
case 4 :
rPCOND = 0x9999;
rPDATD = 0x50;
while (1)
{
  i=0;
Uart_Printf ("#   Digital Sensor System 1   #\n"); Uart_Printf("%s:%s\n","1","High Threshold Temperature for DS1620");
Uart_Printf("%s:%s\n","2","Low Threshold Temperature for DS1620")
Uart_Printf("%s:%s\n","3","Configure DS1620");
 Uart_Printf("%s:%s\n","4","Read DS1620 Temperature");
Uart_Printf("\nSelect the function to test?");
i=Uart_GetIntNum();
Uart_Printf("\n")
switch(i)
{
case 1 :  
       Set_Temperature(1)
       break;
case 2 :
       Set_Temperature (0);
       break;
case 3 :
       Set_Temperature (2);
       break;
case 4 :        
       Read_Temperature();
       break;
case 5 :         
       Rtc_Init();
       break;
case 6 :         
       Rtc_display();
       break;
default :
       break;
 }
}
break;
case 5:
rPCOND = 0x9999;  
rPDATD = 0x50;
while (1)
{
  i=0;
  Uart_Printf ("#  Digital Sensor System 2   #\n");
  Uart_Printf("%s:%s\n","1","High Threshold Temperature for DS1620");
Uart_Printf("%s:%s\n","2","Low Threshold Temperature for DS1620");
Uart_Printf("%s:%s\n","3","Configure DS1620");
Uart_Printf("%s:%s\n","4","Read DS1620 Temperature");
Uart_Printf("\nSelect the function to test?")
i=Uart_GetIntNum();
Uart_Printf("\n");
switch(i)
{
case 1 :  
          Set_Temperature(1);
          break;
case 2 :
          Set_Temperature (0);
          break;
case 3 :
          Set_Temperature (2);
          break;
case 4 :        
          Read_Temperature();
          break;
 }
 Uart_Printf("Digital Sensor2 out put is : xxx\n");
 break;
  }
}
void Set_Temperature(int level)
{
Send_data_bits_count = 9;
Send_command_bits_count = 8;
rPCONF = 0x0000aa;
if (level == 0)
{
Uart_Printf("Enter the low threshold temperature to set : ");
  Temperature_Threshold=Uart_GetIntNum();
   command_word = 0x02;
   command_loop_count = 0;
   data_loop_count = 0;
  }
else if (level == 1)
   {
Uart_Printf("Enter the high threshold temperature to set ");
    Temperature_Threshold=Uart_GetIntNum();
    command_word = 0x01;
    command_loop_count = 0;
    data_loop_count = 0;
   }
else if (level == 2)
   {
    Uart_Printf("Configuring DS1620\n");
    Temperature_Threshold = 0x88;
    Send_data_bits_count = 8;
    Send_command_bits_count = 8;  
    command_word = 0x0c;  
    command_loop_count = 0;
    data_loop_count = 0;
   }
rPCOND = 0x9999;  


rPDATD = 0x54;
while (Send_command_bits_count)
  {
   rPDATE=0xf7;
   Uart_Printf("Inside Send Loop....Sending Command bit:%2d\n\n",command_loop_count);
   command_bit = command_word & 0x01;
   command_bit = command_bit | 0x54;
   rPDATD = command_bit;
   Delay(1000);
   command_word = command_word >> 1;
   Send_command_bits_count--;
   command_loop_count++;
   rPDATE=0xff;
   Delay(2000);
  }
while (Send_data_bits_count)
  {
   rPDATE=0xf7;
   Uart_Printf("Inside Send Loop....Sending Data  Bit:%2d\n\n",data_loop_count);
data_transmit_bit = Temperature_Threshold & 0x01;
Uart_Printf("Inside Send Loop....Data transmit bit:%4d\n\n",data_transmit_bit);
data_transmit_bit = data_transmit_bit | 0x54;
rPDATD = data_transmit_bit;  
Temperature_Threshold = Temperature_Threshold >> 1;
Send_data_bits_count--;
data_loop_count++;
rPDATE=0xff;
Delay(2000);
}
rPDATD = 0x50;
}
void Read_Temperature(void)
{
    int temperature_sign;
    Uart_Printf("Please Wait....\n");
    Delay(2000);
    Receive_data_bits_count = 9;
    Send_command_bits_count = 8;
    rPCONF = 0x0000aa;
    command_loop_count = 0;
    data_loop_count = 0;
    Temperature_Read = 0x0000;
    command_word = 0xaa;
   rPCOND = 0x9999;
   rPDATD = 0x54;
   while (Send_command_bits_count)
   {
      rPDATE=0xf7;
Uart_Printf("Sending Command bit:%2d\n",command_loop_count);
command_bit = command_word & 0x01;
command_bit = command_bit | 0x54;
rPDATD = command_bit;
Delay(1000);
command_word = command_word >> 1;
Send_command_bits_count--;
command_loop_count++;
rPDATE=0xff;
      Delay(0);
   }
  
   while (Receive_data_bits_count)
   {
     rPDATE=0xf7;
     Delay(2000);
     rPCOND = 0x9998;
     Uart_Printf("Received Bit %2d\n",data_loop_count);
     Delay(500);
     data_mask = rPDATD & 0x01;
     Uart_Printf("Data bit read : %4d\n",data_mask);
     data_mask = data_mask << 8 ;
     Temperature_Read = Temperature_Read & 0xf0ff;
     Temperature_Read = Temperature_Read | data_mask ;
     Temperature_Read = Temperature_Read >> 1;
     Uart_Printf("The Temperature String : %x  \n",Temperature_Read);
     Receive_data_bits_count--;
     data_loop_count++;
     rPDATE=0xff;
     Delay(200);
  }
 
  if (Receive_data_bits_count == 0)
  {
     // Wait until clock becomes high
     while ( (rPDATF & 0x010) == 0)
     {
        Delay(500);
     }
     Delay (1000);
     rPDATD = 0x50;
     // Disable All interrupts
     rINTMSK=0x07ffffff;  
     Stop_Timer0();
     temperature_sign = Temperature_Read & 0x0100;
     if (temperature_sign == 1)
     {
         Temperature_Read = Temperature_Read & 0x00ff;
         Temperature_Read = !Temperature_Read;
         //Temperature_Read = (Temperature_Read + 1)* 0.5;
         Uart_Printf("\n\nTemperature reading is (in centigrade): -%4d\n\n",Temperature_Read);
     }
     else
     {
         // Temperature_Read = (Temperature_Read) * 0.5;
         Uart_Printf("\n\nTemperature reading is (in centigrade): %4d\n\n",Temperature_Read);
     }
  }    
 
  Reference_temperature =  Temperature_Read + 2;
  Uart_Printf("Temperature read is less than Refernce    Temperature : %4d\n",Reference_temperature);
  rPDATD = 0x40;
  Delay(5000);
 
  Reference_temperature =  Temperature_Read - 2;
  Uart_Printf("Temperature read is more than Refernce Temperature : %4d\n",Reference_temperature);
  rPDATD = 0x10;
  Delay(5000);
  rPDATD = 0x50;
}
void Initialize_Timer0(void)
{
  // Set pre sacalar and divider for Timer 0
 rTCFG0 = 0x000000ff;
 rTCFG1 = 0x00000004;
 rTCNTB0 = 0X4000; // load 0xffff(64K) to Timer 0
 rTCMPB0 = 0X2000; // load 0x8000(32K) to Compare register to generate clock for DS1620
 rTCON = 0x000000a; // manual update of rTCNTB0 and rTCMPB0
}
void Start_Timer0(void)
{
 rTCON = 0x0000009; // Start the Timer 0
}
 void Stop_Timer0(void)
{
 rTCON = 0x00000008;
}

Appendix-2: DS1620

Features

__Requires no external components

__Supply voltage range covers from 2.7V to 5.5V

__Measures temperatures from -55°C to +125°C in 0.5°C increments; Fahrenheit equivalent is

-67°F to +257°F in 0.9°F increments

__Temperature is read as a 9-bit value

__Converts temperature to digital word in 750ms (max)

__Thermostatic settings are user-definable and nonvolatile

__Data is read from/written via a 3-wire serial interface (CLK, DQ, RST )

__Applications include thermostatic controls, industrial systems, consumer products, thermometers, or any thermally sensitive system

__8-pin DIP or SOIC (208-mil) packages

Description

  • The DS1620 Digital Thermometer and Thermostat provides 9–bit temperature readings which indicate the temperature of the device. With three thermal alarm outputs, the DS1620 can also act as a thermostat. THIGH is driven high if the DS1620’s temperature is greater than or equal to a user–defined temperature TH. TLOW is driven high if the DS1620’s temperature is less than or equal to a user–defined temperature TL. TCOM is driven high when the temperature exceeds TH and stays high until the temperature falls below that of TL.

Pin assignment

Pin Description

Register summary

3–WIRE COMMUNICATIONS

  • The 3–wire bus is comprised of three signals. These are the RST (reset) signal, the CLK (clock) signal, and the DQ (data) signal. All data transfers are initiated by driving the RST input high. Driving the RST input low terminates communication. (See Figures 4 and 5.) A clock cycle is a sequence of a falling edge followed by a rising edge. For data inputs, the data must be valid during the rising edge of a clock cycle. Data bits are output on the falling edge of the clock and remain valid through the rising edge. When reading data from the DS1620, the DQ pin goes to a high-impedance state while the clock is high. Taking RST low will terminate any communication and cause the DQ pin to go to a high-impedance state. Data over the 3–wire interface is communicated LSB first. The command set for the 3–wire interface as shown in Table 4 is as follows.

Read Temperature [AAh]

  • This command reads the contents of the register which contains the last temperature conversion result. The next nine clock cycles will output the contents of this register.

Write TH [01h]

  • This command writes to the TH (HIGH TEMPERATURE) register. After issuing this command the next nine clock cycles clock in the 9–bit temperature limit which will set the threshold for operation of the THIGH output.

Write TL [02h]

  • This command writes to the TL (LOW TEMPERATURE) register. After issuing this command the next nine clock cycles clock in the 9–bit temperature limit which will set the threshold for operation of the TLOW output.

Read TH [A1h]

  • This command reads the value of the TH (HIGH TEMPERATURE) register. After issuing this command the next nine clock cycles clock out the 9–bit temperature limit which sets the threshold for operation of the THIGH output.

Read TL [A2h]

  • This command reads the value of the TL (LOW TEMPERATURE) register. After issuing this command the next nine clock cycles clock out the 9–bit temperature limit which sets the threshold for operation of the TLOW output.

Read Counter [A0h]

  • This command reads the value of the counter byte. The next nine clock cycles will output the contents of this register.

Read Slope [A9h]

  • This command reads the value of the slope counter byte from the DS1620. The next nine clock cycles will output the contents of this register.

Start Convert T [EEh]

  • This command begins a temperature conversion. No further data is required. In one–shot mode the temperature conversion will be performed and then the DS1620 will remain idle. In continuous mode this command will initiate continuous conversions.

Stop Convert T [22h]

  • This command stops temperature conversion. No further data is required. This command may be used to halt a DS1620 in continuous conversion mode. After issuing this command the current temperature measurement will be completed and then the DS1620 will remain idle until a Start Convert T is issued to resume continuous operation.

Write Config [0Ch]

  • This command writes to the configuration register. After issuing this command the next eight clock cycles clock in the value of the configuration register.

Read Config [ACh]

  • This command reads the value in the configuration register. After issuing this command the next eight clock cycles output the value of the configuration register.

Appendix 3: Special Function Register