Lab4 - Implementation of Embedded System with Power Management Capability

Lab 4 - Implementation of Embedded System with Power Management Capability

AbstractIn this Lab we have to design and implement embedded system with power management capability. Here we have to develop system having Real Time Clock with battery support and when the system is in stop mode when system functionality is not in use and when the user demand for the functionality and generate the external interrupt or some fixed time after which system will come out of the stop mode and working inn the normal mode. Through this project we understand the application of RTC with battery support and power management capability of ARM 7TDMI especially the function of stop mode which is very useful to understand in many application of embedded world.


1. IntroductionBy this project we have to introduce the power management capability of ARM 7TDMI.

In this project first we have to connect battery on the board for RTC so that it updates time continuously even if system is not powered on. Then put the cpu into the stop mode so that cpu uses very low power. But when user requires full functionality he generates the external interrupt and cpu comes into the normal mode with full functionality.

At last we have to display the results which indicate the working above functions on hyper terminal using serial communication for verification.

2. Methodology

  • Here I am going to discuss all the objectives of the project and challenges that I faced during project. Here I finish my project by individually finish analog and digital part and then combine to accomplish the goal of the project.

2.1. Objectives and Technical Challenges

I am dividing this project into several parts to accomplish the final goals. Those steps are described below.

    • First connect the battery to the ARM board as shown in figure 2.1.1 for RTC. For that connect the positive node of battery to the pin 89 of the ARM cpu and negative terminal of battery is connected to ground.
    • After connecting battery write a program to set a correct time in real time clock.
    • Then make program to force the cpu in the soft mode from the normal mode.
    • Then according to the demand of user generate the external interrupt.
    • When the external interrupt is generated then system will come out of the stop mode.
    • After come out of the stop mode system should perform the user demanded function. Here we have to perform the function of lab3 as a user demanded function.

Technical challenges that I faced during the project is to put the system into the stop mode. Also I face some programming problem in preserving functions and capability of lab3 when the cpu come out of the stop mode.

2.2. Program Flow Chart

In fig 2.2.1 flowchart of the program is given which represent how the main program going to execute. Also right side of the flow chart there are notations which indicate the each step which are described below the flowchart one by one.

Analog Sensor Choices

Digital Sensor Choices

Fig 2.2.1 Flowchart of the program

2.2.3 Description of flow chart

As shown in fig 2.2.1 notation is given to the each step pf the program and it is described as below.

  • A1:- In this step initialization of all variable is done and before that all the header files are included mainly utilities.h where all functions are defined.
  • A2:- All ports are initialized by the function which is defined in the header file.
  • A.3:- UART is initialized by function of header file, UART 0 is selected and set the baud rate to 1152000.
  • A4:- Then using software user has to enter choice number and he can chose any one sensor application among two digital and three analog sensor application.

Analog Sensor Choice

If user chose among choice 1 or 2 or 3 then following steps are executed.

  • An.1:- Here one channel among total analog input channel is selected. C statement rADCCON = 0x1 | (0x0<<2); is selecting AIN0 input and start ADC conversion.
  • An.2: After conversion begins it will wait for the reading of one conversion of 9 bit and then execution comes out of the loop after statement “while(!(rADCCON & 0x40));” and conversion stops.
  • An.3:- Then print the converted digital value stored in ADCDAT register on the hyper terminal.
  • A4:- Then execution jumps back to the point where choice has been asked from the user.

Digital Sensor Choice

If user chose among choice 4 or 5 then following steps are executed.

  • Di.1:- Configure port D pins for input and output purpose. Here PDAT0 is connected to DQ and PDAT2 is connected to RST. So the following C statement represents the required function.
  • rPCOND = 0x9999;
  • rPDATD = 0x50;
  • Di.2:- Then user has been asked for enter choice for change higher or lower temperature limit, configure DS1620 and for read temperature.
  • Di.3:- Then start 3-Wire communication by activating RST pin high.
  • Di.4:- Then configure DS 1620 in write mode by sending command 0CH and also set CPU bit and 1SHOT bit of configuration register for continuous temperature conversion.
  • Di.5:- By selecting choice 1 and 2 user can select upper and lower temperature value otherwise by default value is already there in DS 1620.
  • Di.6:- Start the temperature conversion by issuing command EEH.
  • Di.7:- Give some delay so that DS1620 can take some time in responding command value coming from arm cpu.
  • Di.8:- After conversion of temperature issue the stop conversion command 22H.
  • Di.9:- When user select the chose 4 then configure the port D pin in read configuration mode by making PDATD0 low and other is high.
  • Di.10:- In read configuration loop cpu can read temperature from DS1620 and also read higher and lower temperature limit.
  • Di.11:- Then output of selected choice is displayed on the hyper terminal console.
  • A.4:- Then program execution goes back to section of choice.

2.3 Pseudo code of Program

2.3.1. Pseudo Code for Main Program

  • Include the files 44b.h, 44blib.h, def.h, option.h
  • I/O Port initialization.
  • Uart 0 is selected and set the baud rate to 115200
  • Choice from 0 to 5 comes and user has to select one of the choice.

2.3.2. Pseudo Code for Analog Sensor Choice

  • If choice is from 1 to 3 then one of the three analog sensors is selected.
  • Select one channel from total 8 available analog channel
  • ADC conversion begins.
  • Wait for 1 complete conversion and then stop ADC conversion further.
  • Show the value on the hyper terminal.
  • Return to the selection of choice

2.3.3. Pseudo Code for Digital Sensor Choice

  • If the choice from 4 or 5 is selected then one of two available digital sensors is selected.
  • Configure port D pins as output configuration.
    • Making RST pin high 3-wire communication begin between ARM cpu and DS1620.
    • Send the write configuration command and configure DS 1620.
    • By selecting choice 1 or 2 you can select higher and lower temperature range.
    • Send command EEh for temperature conversion.
    • Giving 2000ms delay to DS 1620 to response on command and in temperature conversion.
    • Then issue stop temperature conversion command when user demanding for reading of temperature.
    • Read temperature by configuring 0 pin of port D pin as input and take temperature value into ARM.
    • Display value on hyper terminal.
  • Go back to select choice from 1 to 5.

4. Testing and Verification

This project can be verified using hyper terminal and viewing the output on hyper terminal console.

    • Initially for debugging purpose I download my program in ram location of ARM cpu and finally I got the required output.
    • Debug the program so .axf file of the program is created and compile the program using following command to get the binary file of program.

fromelf –nozeropad project1.axf –bin project1.bin

In this way binary file of project1.axf is generated and named project1.bin

    • Load that binary file in flash memory using JTEG.
    • After completion of burning flash memory connect the serial port of PC to the ARM board.
    • Open the hyper terminal and then set the baud rate 115200 and chose flow control as none and other settings remain as it is.
    • Then turn on the arm development board supply and then program ask for the choice to enter from 1 to 5 for selecting particular sensor application.
    • After entering number program gives output of selecting sensor application.

5. Conclusion

This project gives the idea of how we can use RTC with battery support to maintain time when power is removed. Also learn the important features of ARM 7TDMI that how we can use stop mode for power management capability. Using this stop mode we can make embedded system with facility that when the system functionality is in idle mode at that time system use very low power. In this way this project gives good experience of learning power management using stop mode, use of real time clock by adding battery support and its use when power is removed in embedded application.

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.

Appendix

7.1 Schematics of lab 2 project

7.2 Architecture of ARM7TDMI

7.3 Real Time Clock (RTC)

(a) Features

  • BCD number: second, minute, hour, date, day, month, year
  • Leap year generator
  • Alarm function: alarm interrupt or wake-up from power down mode.
  • Year 2000 problem is removed.
  • Independent power pin (VDDRTC)
  • Supports millisecond tick time interrupt for RTOS kernel time tick.
  • Round reset function

(b) Read / Write Registers in RTC

  • Bit 0 of the RTCCON register must be set in order to read and write the register in RTC block. To display the sec., min., hour, date, month, and year, the CPU should read the data in BCDSEC, BCDMIN, BCDHOUR, BCDDAY, BCDDATE, BCDMON, and BCDYEAR registers, respectively, in the RTC block.
  • However, a one second deviation may exist because multiple registers are read. For example, when the user reads the registers from BCDYEAR to BCDMIN, the result is assumed to be 1959(Year), 12(Month), 31(Date), 23(Hour) and 59(Minute).
  • When the user read the BCDSEC register and the result is a value from 1 to 59(Second), there is no problem, but, if the result is 0 sec., the year, month, date, hour, and minute may be changed to 1960(Year), 1(Month), 1(Date), 0(Hour) and 0(Minute) because of the one second deviation that was mentioned. In this case, user should re-read from BCDYEAR to BCDSEC if BCDSEC is zero.

(c) Leap Year Generator

  • This block can determine whether the last date of each month is 28, 29, 30, or 31, based on data from BCDDAY, BCDMON, and BCDYEAR.
  • This block considers the leap year in deciding on the last date. An 8-bit counter can only represent 2 BCD digits, so it cannot decide whether 00 year is a leap year or not.
  • For example, it can not discriminate between 1900 and 2000. To solve this problem, the RTC block in S3C44B0X has hard-wired logic to support the leap year in 2000. Please note 1900 is not leap year while 2000 is leap year. Therefore, two digits of 00 in S3C44B0X denote 2000, not 1900.

7.4 Power Management Mode

(a) Description

The Clock Generator in S3C44B0X can generate the required clock signals for the CPU as well as peripherals. The Clock Generator can be controlled to supply or disconnect the clock to each peripheral block by S/W, which will reduce the power. As well as this kind of S/W controllability, S3C44B0X has various power management schemes to keep optimal power consumption for a given task.

The power management in S3C44B0X consists of five modes:

Normal mode, Slow mode, Idle mode, Stop mode and SL Idle mode for LCD.

  • The Normal mode is used to supply clocks to CPU as well as all peripherals in S3C44B0X. In this case, the power consumption will be maximized when all peripherals are turned on. The user can control the operation of peripherals by S/W. For example, if a timer and DMA are not needed, the user can disconnect the clock to the timer and DMA to reduce power.
  • The Slow mode is non-PLL mode. Unlike the Normal mode, the Slow mode uses an external clock directly as master clock in S3C44B0X without PLL. In this case, the power consumption depends on the frequency of the external clock only. The power consumption due to PLL itself is excluded. The Idle mode disconnects the clock only to CPU core while it supplies the clock to all peripherals.
  • By using this Idle mode, power consumption due to CPU core can be reduced. Any interrupt request to CPU can wake-up from Idle mode.
  • The Stop mode freezes all clocks to the CPU as well as peripherals by disabling PLL. The power consumption is only due to the leakage current in S3C44B0X, which is less than 10 uA. The wake-up from Stop mode can be done by external interrupt to CPU.
  • The SL Idle mode causes the LCD controller to work. In this case, the clock to CPU and all peripherals except LCD controller should be stopped, therefore, the power consumption in the SL Idle mode is less than that in the Idle mode.

(b) Clock Generator & Power Management Special Register

PLL Control Register (PLLCON)

Fpllo = (m * Fin) / (p * 2s)

m = (MDIV + 8), p = (PDIV + 2), s = SDIV

Fpllo must be greater than 20 MHz and less than 66 MHz.

PLL Value Selection Guide

1. Fpllo * 2s has to be less than 170 MHz.

2. S should be as great as possible.

3. (Fin / p) is recommended to be 1 MHz or above. But, (Fin / p) < 2 MHz

7.5 Program Code
#include <string.h>
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\utilities.h"
#include "..\inc\def.h"
void Main(void)
{
 
  int i,j;
  int mclk=MCLK;
  rSYSCFG=SYSCFG_8KB;
 
  Port_Init();
     
  Uart_Select(0);
  Led_Display(0);
  Delay(10000);
  Led_Display(7);
  Delay(10000);
  Led_Display(0);
  while (1)
  {
    j=0;   
     
Uart_Printf ("Implementation of Embedded System with Multiple Analog and Digital Sensors \n");  
Uart_Printf("%s:%s\n","Select 1","Sensor 1(Analog)");
Uart_Printf("%s:%s\n","Select 2","Sensor 2(Analog)");
Uart_Printf("%s:%s\n","Select 3","Sensor 3(Analog)");
Uart_Printf("%s:%s\n","Select 4","Sensor 1(Digital)");
Uart_Printf("%s:%s\n","Select 5","Sensor 2(Digital)");
Uart_Printf("%s:%s\n","6","Exit");
Uart_Printf("\n Select the Sensor from 3 analog and 2 digital sensor?");
j=Uart_GetIntNum();
Uart_Printf("\n");
switch(j)
{


      case 1 :  
Uart_Printf ("Sensor 1(Analog)\n\n");
rADCCON=0x1|(0x0<<2); //Start A/D conversion AIN0
while(rADCCON &0x1); //To avoid The first FLAG error case.
//(The START bit is cleared in one ADC clock.)
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 Sensor 2(Analog)\n");

 rADCCON=0x1|(0x1<<2); //Start A/D conversion AIN1
while(rADCCON &0x1); //To avoid The first FLAG error case.
//(The START bit is cleared in one ADC clock.)
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 ("Sensor 3(Analog)\n");

rADCCON=0x1|(0x2<<2); //Start A/D conversion AIN2
while(rADCCON &0x1); //To avoid The first FLAG error case.
//(The START bit is cleared in one ADC clock.)
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 1\n");
{
         Set_Temperature(1);
            break;
  case 5 :         
           Rtc_Init();
 }
}
case 5:

{

  }    
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("%s:%s\n","#","Press RESET TO MAIN MENU");
Uart_Printf("\nSelect the function to test?");
i=Uart_GetIntNum();
Uart_Printf("\n");
switch(i)
case 1 :  
        break;
case 2 :
        Set_Temperature (0);
        break;
case 3 :
          Set_Temperature (2);
          break;  
case 4 :         
           Read_Temperature();
           break;

default :
           break;

break;


rPCOND = 0x9999;
rPDATD = 0x50;
while (1)
{
i=0;  
Uart_Printf ("Sensor 2(Digital)\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("%s:%s\n","#","Press RESET TO MAIN MENU");
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;
  default :
  break;
}

}

  Uart_Printf("Digital Sensor2 out put is : xxx\n");
           break;
   
   case 6 :         
   Stop_Timer0();
   exit();
}
}
}
Utilities.c program where all functions are defined for send command to ds 1620 or read temperature from ds1620
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\utilities.h"
#include "..\inc\def.h"
int Temperature_Threshold;
int Temperature_Read;
int Reference_temperature;
int data_mask;
char command_word;
char command_bit;
char data_transmit_bit;
char data_receive_bit;
int Send_data_bits_count = 0;
int Send_command_bits_count = 0;
int Receive_data_bits_count= 0;
int command_loop_count = 0;
int data_loop_count = 0;
void Set_Temperature(int level)
{


Send_data_bits_count = 9;
Send_command_bits_count = 8;

rPCONF = 0x0000aa; // 10101010 - aa

if (level == 0)
  {
   Uart_Printf("Enter the low threshold temperature to set (in centigrade) : ");
   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 (in centigrade) : ");
    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;
    //VFRAME o/p VLINE i/o VD3 o/p VD1  O/P

// 10,01, 10, 01, 10, 01, 10, 01

   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)
   {
     //VFRAME o/p VLINE i/o VD3 o/p VD1  i/P

// 10,01, 10, 01, 10, 01, 10, 00

     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;
}
void Initialize_Interrupts(void)
{  
 int i;
 pISR_EINT4567 = (unsigned)Send_Data_To_Sensor;
 pISR_EINT2 =  (unsigned)Receive_Data_From_Sensor;
 for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
   {
    *((volatile unsigned *)i)=0xEA000000+0x1FFE;
   }
   
  rPCONG=0xfff0; // EINT2,3,4,5,6,7 PG0 and PG1 i/p
  rPUPG=0x00;    //pull up enabled
  rEXTINT=0x22222222; // falling edge triggered interrupt
  rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
  rINTMOD=0x0000000;  // All=IRQ mode
  rINTMSK=0x07ffffff; // disable all interrupts
}
void __irq Send_Data_To_Sensor(void)
{
rEXTINPND = 0xf;
rI_ISPC=BIT_EINT4567;
if (Send_command_bits_count != 0)
  {
   Uart_Printf("Sending the Command bit:%2d\n",command_loop_count);
   command_bit = command_word & 0x01;
   command_bit = command_bit | 0x54;
   rPDATD = command_bit;
   command_word = command_word >> 1;
   Send_command_bits_count--;
   command_loop_count++;
  }
  else
  {
   Uart_Printf("Sending Data Bit:%2d\n",data_loop_count);
   data_transmit_bit = Temperature_Threshold & 0x01;
   Uart_Printf("Data transmitting bit:%4d\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++;
  }
}
void __irq Receive_Data_From_Sensor(void)
{
rI_ISPC=BIT_EINT2;
if (Send_command_bits_count != 0)
  {
   Uart_Printf("Sending the Command Bit %2d\n",command_loop_count);
   command_bit = command_word & 0x01;
   command_bit = command_bit | 0x54;
   rPDATD = command_bit;


   command_word = command_word >> 1;
   Send_command_bits_count--;
   command_loop_count++;
  }
  else
  {
   //VFRAME o/p VLINE i/o VD3 o/p VD1  i/P

// 10,01, 10, 01, 10, 01, 10, 00

   rPCOND = 0x9998;
   Uart_Printf("Receiving 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++;
  }
}