/////////////////////////////////////////////////////////////////////// // // Simple Altimeter Sensor module // // this model returns a contant 24-bit pressure value // (=993 millibars) // // a more advanced version would check for the expected // SPI command and return a pressure value based on the // value of the pressure variable // // this module might also be the location of assert statements // to help with debugging // // Ports: // SDO (Output) // Serial Data from Slave to Master // // SDI (Input) // Serial Data from Master to Slave // // SCLK (Input) // SPI Clock pin // // CSB (Input - Active Low) // Chip Select // // /////////////////////////////////////////////////////////////////////// module simple_altimeter_sensor ( output SDO, input SDI, input SCLK, input CSB ); timeunit 1ns; timeprecision 100ps; // the integer variables "pressure" and "temperature" represent values // for environmental parameters // // the values can be set from the testbench and, in a more a more // advanced model of the sensor, the pressure value would be consulted // and its value would be returned to the user // // the simplified altimeter sensor does not support consideration // of temperature data but the temperature variable exists below // to maintain compatibility with the more complex MS5803-02BA // altimeter sensor int pressure = 993; // pressure in millibars int temperature = 25; // temperature in Celcius // // serial bus timing data to match that used by the // MS5803-02BA altimeter sensor model // // the values // specified here should be both conservative and // easy to achieve in practice // specify specparam tcy = 60ns; // clock cycle SPI clock // this value is intenionally longer than implied // by the 20 MHz maximum clock frequency quoted // on the datasheet specparam tclk1 = 25ns; // SPI clock pulse width HIGH specparam tclk0 = 25ns; // SPI clock pulse width LOW specparam tsucs = 25ns; // chip select setup time specparam thcs = 25ns; // chip select hold time specparam tsud = 25ns; // SDI data setup time specparam thd = 25ns; // SDI data hold time // Serial clock timings $period(posedge SCLK, tcy); $width(posedge SCLK, tclk1); $width(negedge SCLK, tclk0); // Chip Select timings relative to the clock $setup(CSB, posedge SCLK, tsucs); $hold(CSB, posedge SCLK, thcs); // Serial Data timings relative to the clock $setup(SDI, posedge SCLK, tsud); $hold(SDI, posedge SCLK, thd); endspecify logic data_out = 1; assign SDO = (!CSB) ? data_out : 'z; always @(posedge SCLK) if (!CSB) // note that CSB should remain active for the whole // of this begin-end block but this very simple // code doesn't check CSB again begin data_out = 1; repeat ( 6) @(negedge SCLK) data_out = 1; repeat (15) @(negedge SCLK) data_out = 0; repeat ( 5) @(negedge SCLK) data_out = 1; repeat ( 4) @(negedge SCLK) data_out = 0; repeat ( 1) @(negedge SCLK) data_out = 1; @(negedge SCLK); end endmodule