EmbDev.net

Forum: µC & Digital Electronics SMT160-30 PIC asm code to regular c code for lpc2148


von Timo K. (timok16)


Rate this post
useful
not useful
Hi,

I found the c code for smt160-30 temp sensor, but main area is written
to the PIC asm code. I need change the asm-code to regular c code for
lpc2148.
Can somebode who knows something about PIC assemly code and trasnslate
it to the regular c code for lpc2148?

#define PORT          PORTB
#define PIN           2          // pin number where is sensor
#define CIDLO           PORT,PIN
#define SMT160_INPUT   TRISB,PIN
#define MAX          80
/* MAX [0-135]
    Tmax = (MAX/2 + 60); ex. MAX=130  => Tmax=130/2 + 60=125 C
    Tmin = [(MAX+1)-136]/2  when MAX=130 then Tmin=-2,5C
     => deltaT=127.5C, resolution 0.5C

    MAX         0      10      50      80     100    120     130  135
    Tmax [C]   60      65      85     100     110    120     125
127.5
    Tmin [C]  -67.5*  -62.5*  -42.5   -27.5   -17.5   -7.5    -2      0

       * - out of sensor range (-45C - +130C)
*/

char countL ;        //  counter lower byte
char countH ;        //  counter higher byte
char stridaL ;       //  log1 lower counter (if stridaL=256 => 0.5C)
char stridaH ;        //  log1 higher counter
char TEMP_J;              //  measured tempearture - tenths [C]
char TEMP_D;          //  measured tempearture - tens (hundreds) [C]
char minus ;            //  this is negative values flag, if is 1 we are
under zero


void temperature()      // main rutine
{
  TEMP_D=0;
  TEMP_J=0;
asm
{
       MOVLW d'32'   ;  2 cycles
       MOVWF _countL
       MOVLW d'54'   ;    2
       MOVWF _countH

       CLRF _stridaL ;  1
       CLRF _stridaH ;  1

       BCF STATUS,Z  ;  1

repeatA     nop         ;  1  measuring loop (sampling time) - 13600x
repeatB

      BTFSC CIDLO       ;1/2
      INCF  _stridaL,1  ;1

      BTFSC STATUS,Z       ;1/2
      INCF  _stridaH,1    ;1

         DECFSZ _countL,1     ;3/2
      GOTO repeatA
      DECFSZ _countH,1     ;3/2
      GOTO repeatB

          ; 3x rotate meassured DC
       BCF STATUS,C
      RLF _stridaL,1
      RLF _stridaH,1
      RLF _stridaL,1
      RLF _stridaH,1
      RLF _stridaL,1
      RLF _stridaH,1
      ; RETURN
 }
     // and now convert temperature from DC to degrees (linear
dependence)
     if (stridaH < MAX)     //60C - Tmax
    {
        minus=0;
         TEMP_D=stridaH>>1;
       TEMP_J=stridaH;
       TEMP_D=TEMP_D+60;
       if (TEMP_J % 2) TEMP_J=5;     // 0,5 C or 0.0C
       else TEMP_J=0;
    }
     else
     {
        if(stridaH>135)    //(Tmin - 60C)
       {
         minus=0;
           TEMP_D=(stridaH - 136);      // ex.TEMP_J=185-136 = 49C
         TEMP_J=TEMP_D;
         TEMP_D>>=1;                  // temp_d/2
         if (TEMP_J % 2) TEMP_J=5;    // 0,5 C
         else TEMP_J=0;
       }
        else              // (Tmin - 0C) ex. stridaH=130 =>
t=(136-130)/2=-3C
        {
           minus=1;
           TEMP_D=(136-stridaH);
         TEMP_J=TEMP_D;
         TEMP_D>>=1;
         if (TEMP_J % 2) TEMP_J=5;
         else TEMP_J=0;
      }
   }
}

Thanx Timo

von Martin Thomas (Guest)


Rate this post
useful
not useful
Timo Kuisma wrote:
> Hi,
>
> I found the c code for smt160-30 temp sensor, but main area is written
> to the PIC asm code. I need change the asm-code to regular c code for
> lpc2148.
> Can somebode who knows something about PIC assemly code and trasnslate
> it to the regular c code for lpc2148?

The SMT160 outputs the temperature in as "PWM"-signal where the
duty-cylce depends on the temperature. I don't know PIC assembler but
the code looks like it counts high/low but uses "well know" instruction
cyle times. For the LPC2000 you could calibrate some kind of
"delay-loop" for the sampling but it might be a better idea to use the
timer/capture-function of the LPC's timers. Another approach is to
simply poll the state of the data-pin in a timer-ISR which has a
"predeterminde" frequency and count "low" and "high" states of the pin
for a given time-intervall (ISR hits).

Martin Thomas

von Miroslav Fiala (Guest)


Rate this post
useful
not useful
Hi,

the asm code samples signal from SMT160-30 for a while and counts number
of samles when there is 0 and when there is 1, these two counters make
the DC. It's not very acurate but PIC ain't very fast... On ARM You can
use some IRQ input and using timer measure the DC more precisly...

Have a nice day. Mirek

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.