ms5540.c File Reference

Include dependency graph for ms5540.c:

Defines

#define MS5540_DELAY_AMOUNT   2

Functions

void ms5540_calc_temp_and_pressure ()
uns16 ms5540_get_config (uns8 config_word)
uns16 ms5540_get_raw_pressure ()
uns16 ms5540_get_raw_temp ()
void ms5540_init ()
void ms5540_pulse_sclk ()
void ms5540_reset ()
void ms5540_send_start ()
void ms5540_send_stop ()
void ms5540_setup_io (void)

Variables

int16 c1
int16 c2
int16 c3
int16 c4
int16 c5
int16 c6

Define Documentation

#define MS5540_DELAY_AMOUNT   2

Function Documentation

void ms5540_calc_temp_and_pressure (  ) 

00322                                      {
00323     
00324 int16 d1, d2, ut1, off;
00325 int16 temp, p, dt;
00326 int32 sens, x;
00327 
00328 //  c1 = 23470;
00329 //  c2 = 1324;
00330 //  c3 = 737;
00331 //  c4 = 393;
00332 //  c5 = 628;
00333 //  c6 = 25;
00334 
00335     
00336     d1 = ms5540_get_raw_pressure();
00337 //  d1 = 16460;
00338     
00339     serial_print_str("get pr d1: ");
00340     serial_print_int(d1);
00341     serial_print_nl();
00342 
00343     d2 = ms5540_get_raw_temp();
00344 //  d2 = 27856;
00345     serial_print_str("get temp: ");
00346     serial_print_int(d2);
00347     serial_print_nl();
00348     
00349     ut1 = 8*c5+20224;
00350     
00351     serial_print_str("ut1= ");
00352     serial_print_int(ut1);
00353     serial_print_nl();
00354     
00355     dt = d2 - ut1;
00356     
00357     serial_print_str("dt= ");
00358     serial_print_int(dt);
00359     serial_print_nl();
00360     
00361     temp = 200 + (int32)dt * ((int32)c6 + 50) / 1024;
00362     
00363     serial_print_str("temp= ");
00364     serial_print_int(temp);
00365     serial_print_nl();
00366     
00367     off = c2 * 4 + (((int32)c4-512)*dt) / 4096;
00368 
00369     serial_print_str("off= ");
00370     serial_print_int(off);
00371     serial_print_nl();
00372      
00373     sens = c1 + ((int32)c3*dt)/1024 + 24576;
00374 
00375     serial_print_str("sens= ");
00376     serial_print_int(sens);
00377     serial_print_nl();
00378 
00379     x = ((int32)sens * ((int32)d1-7168))/16384 - (int32)off;
00380     
00381     serial_print_str("x= ");
00382     serial_print_int(x);
00383     serial_print_nl();
00384     
00385     p = x * 10/32 + 250*10;
00386     
00387     serial_print_str("p= ");
00388     serial_print_int(p);
00389     serial_print_nl();
00390 }   

Here is the call graph for this function:

uns16 ms5540_get_config ( uns8  config_word  ) 

00102                                           {
00103 
00104 uns8 request;
00105 uns8 count;
00106 uns16 result;
00107 
00108     switch (config_word) {
00109         case 1:
00110             request = 0b01010100;
00111             break;
00112         case 2:
00113             request = 0b01011000;
00114             break;
00115         case 3:
00116             request = 0b01100100;
00117             break;
00118         case 4:
00119             request = 0b01101000;
00120             break;
00121     }
00122     ms5540_send_start();
00123 
00124     for( count = 0 ; count < 6 ; count++ )  // 1- 17 to get correct bit pattern
00125     {
00126         change_pin(ms5540_din_port, ms5540_din_pin, request.7);
00127         
00128         request = request << 1;
00129         
00130         ms5540_pulse_sclk();
00131     }
00132         
00133     ms5540_send_stop();
00134     
00135     // naked clock pulse
00136     ms5540_pulse_sclk();
00137 
00138     // okay now clock the word out
00139     for(count = 0 ; count < 16 ; count++)
00140     {
00141         ms5540_pulse_sclk();
00142 
00143         result = result << 1;
00144         result.0 = test_pin(ms5540_dout_port, ms5540_dout_pin);
00145     }
00146 
00147     // naked clock pulse
00148     ms5540_pulse_sclk();
00149     
00150     return result;
00151 
00152 }   

Here is the call graph for this function:

Here is the caller graph for this function:

uns16 ms5540_get_raw_pressure (  ) 

00154                                 {
00155 
00156 uns8 setup_word = 0b1010;
00157 uns8 count;
00158 uns16 result;
00159 
00160     ms5540_send_start();
00161     // 1
00162     set_pin(ms5540_din_port, ms5540_din_pin);
00163     ms5540_pulse_sclk();
00164     // 0
00165     clear_pin(ms5540_din_port, ms5540_din_pin);
00166     ms5540_pulse_sclk();
00167     // 1
00168     set_pin(ms5540_din_port, ms5540_din_pin);
00169     ms5540_pulse_sclk();
00170     // 0
00171     clear_pin(ms5540_din_port, ms5540_din_pin);
00172     ms5540_pulse_sclk();
00173     
00174     ms5540_send_stop();
00175     
00176     // two more pulses
00177     ms5540_pulse_sclk();
00178     ms5540_pulse_sclk();
00179     
00180     // now wait for conversion to finish (din goes low)
00181     
00182     while (test_pin(ms5540_dout_port, ms5540_dout_pin) != 0) {
00183     }
00184     
00185     // okay now clock the word out
00186     for(count = 0 ; count < 16 ; count++)
00187     {
00188         ms5540_pulse_sclk();
00189 
00190         result = result << 1;
00191         result.0 = test_pin(ms5540_dout_port, ms5540_dout_pin);
00192     }
00193 
00194     // naked pulse
00195     ms5540_pulse_sclk();
00196     return result;
00197     
00198 }

Here is the call graph for this function:

Here is the caller graph for this function:

uns16 ms5540_get_raw_temp (  ) 

00200                             {
00201 
00202 uns8 setup_word = 0b1010;
00203 uns8 count;
00204 uns16 result;
00205 
00206 
00207     ms5540_send_start();
00208     // 1
00209     set_pin(ms5540_din_port, ms5540_din_pin);
00210     ms5540_pulse_sclk();
00211     // 0
00212     clear_pin(ms5540_din_port, ms5540_din_pin);
00213     ms5540_pulse_sclk();
00214     // 0
00215     ms5540_pulse_sclk();
00216     // 1
00217     set_pin(ms5540_din_port, ms5540_din_pin);
00218     ms5540_pulse_sclk();
00219     
00220     ms5540_send_stop();
00221     
00222     // two more pulses
00223     ms5540_pulse_sclk();
00224     ms5540_pulse_sclk();
00225     
00226     // now wait for conversion to finish (din goes low)
00227     
00228     while (test_pin(ms5540_dout_port, ms5540_dout_pin) != 0) {
00229     }
00230     
00231     // okay now clock the word out
00232     for(count = 0 ; count < 16 ; count++)
00233     {
00234         ms5540_pulse_sclk();
00235 
00236         result = result << 1;
00237         result.0 = test_pin(ms5540_dout_port, ms5540_dout_pin);
00238     }
00239 
00240     // naked pulse
00241     ms5540_pulse_sclk();
00242     
00243     return result;
00244     
00245 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ms5540_init (  ) 

00247                    {
00248 
00249 uns16 word1, word2, word3, word4, x, y;
00250 /*c1=22801
00251 c2=2256
00252 c3=716
00253 c4=692
00254 c5=872
00255 c6=26   
00256 
00257 */
00258     // reset
00259     ms5540_reset();
00260 
00261     // get config
00262     word1 = ms5540_get_config(1);
00263     serial_print_int(word1);
00264     serial_print_spc();
00265     word2 = ms5540_get_config(2);
00266     serial_print_int(word2);
00267     serial_print_spc();
00268     word3 = ms5540_get_config(3);
00269     serial_print_int(word3);
00270     serial_print_spc();
00271     word4 = ms5540_get_config(4);
00272     serial_print_int(word4);
00273     serial_print_nl();
00274 
00275     // parse config words
00276     
00277     c1 = (word1 >> 1) & 0x7fff;
00278     
00279     /*c5 = word2 >> 6;
00280     if (test_bit(word1, 0)) {
00281         set_bit(c5, 10);
00282     }
00283     */
00284     x = (word1 << 10) & 0x0400;
00285     y = (word2 >> 6)  & 0x03ff;
00286     c5 = x | y;
00287     
00288     c6 = word2 & 0b0000000000111111; // grab last 6 bits of word2 as c6
00289     
00290     c4 = (word3 >> 6) & 0x03ff;
00291     
00292     x = (word3 << 6) &  0x0fc0;
00293     y = (word4 & 0b0000000000111111);
00294     c2 = x | y;
00295     
00296     c3 = (word4 >> 6) & 0x03ff;
00297     
00298     serial_print_str("c1=");
00299     serial_print_int(c1);
00300     serial_print_nl();
00301     serial_print_str("c2=");
00302     serial_print_int(c2);
00303     serial_print_nl();
00304     serial_print_str("c3=");
00305     serial_print_int(c3);
00306     serial_print_nl();
00307     serial_print_str("c4=");
00308     serial_print_int(c4);
00309     serial_print_nl();
00310     serial_print_str("c5=");
00311     serial_print_int(c5);
00312     serial_print_nl();
00313     serial_print_str("c6=");
00314     serial_print_int(c6);
00315     serial_print_nl();
00316 
00317     
00318 }

Here is the call graph for this function:

void ms5540_pulse_sclk (  ) 

00054                          {
00055 
00056     set_pin(ms5540_sclk_port, ms5540_sclk_pin);
00057     delay_us(MS5540_DELAY_AMOUNT);
00058     clear_pin(ms5540_sclk_port, ms5540_sclk_pin);
00059     delay_us(MS5540_DELAY_AMOUNT);
00060 
00061 }

Here is the caller graph for this function:

void ms5540_reset (  ) 

00080                     {
00081 
00082 uns16 reset_word = 0b1010101010101010;
00083 uns8 count;
00084 
00085     for( count = 1 ; count < 17 ; count++ ) // 1- 17 to get correct bit pattern
00086     {
00087         change_pin(ms5540_din_port, ms5540_din_pin, count.0);
00088         ms5540_pulse_sclk();
00089     }
00090     // five more pulses
00091     ms5540_pulse_sclk();
00092     ms5540_pulse_sclk();
00093     ms5540_pulse_sclk();
00094     ms5540_pulse_sclk();
00095     ms5540_pulse_sclk();
00096     
00097 
00098 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ms5540_send_start (  ) 

00063                          {
00064     
00065     set_pin(ms5540_din_port, ms5540_din_pin);
00066     ms5540_pulse_sclk();
00067     ms5540_pulse_sclk();
00068     ms5540_pulse_sclk();
00069 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ms5540_send_stop (  ) 

00071                         {
00072     
00073     clear_pin(ms5540_din_port, ms5540_din_pin);
00074     ms5540_pulse_sclk();
00075     ms5540_pulse_sclk();
00076     ms5540_pulse_sclk();
00077 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ms5540_setup_io ( void   ) 

00046                            {
00047     
00048     clear_pin(ms5540_sclk_port, ms5540_sclk_pin);
00049     make_output(ms5540_sclk_port, ms5540_sclk_pin);
00050     make_output(ms5540_din_port, ms5540_din_pin);
00051     make_input(ms5540_dout_port, ms5540_dout_pin);
00052 }


Variable Documentation

int16 c1
int16 c2
int16 c3
int16 c4
int16 c5
int16 c6

Generated on Fri Aug 19 09:07:38 2011 for Pic Pack Library by  doxygen 1.6.1