High-resolution di erential-pressure indicator for the low-speed ...330911/report...High-resolution...

13
High-resolution differential-pressure indicator for the low-speed wind tunnel. Mechanical Engineering Technical Report 2013/17 P. A. Jacobs School of Mechanical and Mining Engineering The University of Queensland. December 2013 Contents 1 Hardware 2 2 Firmware 7 Abstract This report describes the hardware and firmware for a differential-pressure indicator for the low-speed wind tunnel. It is essentially a two-channel high-resolution voltmeter attached to a pair of Sensirion pressure sensors but, being built around a microcontroller running FlashForth, it is programmable. 1

Transcript of High-resolution di erential-pressure indicator for the low-speed ...330911/report...High-resolution...

  • High-resolution differential-pressure indicator for the low-speed wind tunnel.

    Mechanical Engineering Technical Report 2013/17P. A. Jacobs

    School of Mechanical and Mining EngineeringThe University of Queensland.

    December 2013

    Contents

    1 Hardware 2

    2 Firmware 7

    Abstract

    This report describes the hardware and firmware for a differential-pressure indicator for the low-speed wind tunnel. It isessentially a two-channel high-resolution voltmeter attached to a pair of Sensirion pressure sensors but, being built around amicrocontroller running FlashForth, it is programmable.

    1

  • 1 Hardware

    Inside the box, the prototype system is built on a single strip board, with a Microchip PIC18F2520 microcontroller [1] talking

    to a 2-channel high-resolution analog-to-digital converter (MCP3422 [2]) and a Modtronix serial-enabled LCD[3]. Photographs

    of the components are shown in Fig. 1 and schematic layouts of the circuit are shown on the following pages.

    Figure 1: The photograph on the left shows the main circuit board with microcontroller (centre), MAX232 serial-port levelconverter (lower right) and the MCP3244 analog-to-digital converter (lower left). The potentiometer in view was used tosimulate a pressure sensor during firmware development. The photograph on the right shows the indicator boxed, sitting on theside of the low-speed wind tunnel, with two Sensirion SDP1108-R pressure sensors [4] mounted on the front panel. The uppersensor is attached to the pair of static-pressure rings on the contraction leading into the test-section of the wind tunnel and thelower sensor is connected to a Pitot-static probe.

    2

  • Although the microcontroller is really quite capable and includes a 10-bit analog-to-digital converter, we really don’t use a lot of

    its capability. Instead, we use its I2C bus to glue together the analog-to-digital converter chip (which we’ve been wanting to try

    for some time) and the LCD display. As seen in the photograph, there are very few pins in use on the microcontroller and this

    is confirmed on sheet 1 of the schematics, where more than half of the MCU pins are labelled as not connected. The principal

    work of the microcontroller is to get the digital values from the MCP3422, do some arithmetic to convert the values from counts

    of voltage into units of Pascals, and display them on the LCD.

    The outputs of the Sensirion SDP1108-R pressure transducers can produce up to 4 V (for 500 Pa) and need to see a fairly

    high input impedance (100kΩ is recommended [4]) at the data converter. The MCP3422 has an input range of ±2.048 V atthe channel input pins. To satisfy both of these requirements, a pair of 56 kΩ resistors is used as a voltage divider for each

    channel (Schematic sheet 3). The 1µF capacitor provides some low-pass filtering for the incoming signal but also provides a low

    impedance for the high-frequency (but small) currents that the switched-capacitor input stage of the MCP3422 requires during

    the conversion process.

    Note that the simple two-resistor voltage divider at the MCP3422 input is serviceable but not ideal. Using signed 16-bit values

    from the MCP3422 means that the least-significant bit corresponds to 2 × 62.5 microvolts at the input to the voltage divider.Even with the input to the divider tied to ground, a leakage current of 25 nA through the protection diodes of the MCP3422

    results in a 16-bit converter count of about 6 rather than (the ideal value of) zero, however, a count of 6 corresponds to about

    0.7 millivolts and is not a problem in this application.

    Communication with the microcontroller is provided by a minimal (3-wire) RS232 serial port. This port was used for the

    development of the Forth firmware and is available for data logging. A suitable computer, with a serial-communications terminal

    program, is needed to make use of this facility.

    The current-limited supply (black box in Fig. 1) shows that, with the back-light on, the LCD draws about 50 mA. In contrast,

    the microcontroller and data converter require only a few milliamps. The photograph shows the LCD backlight on, and this is

    fine when operating from a DC plugpack. If you wish to run the system from a battery, the firmware should be changed to turn

    the backlight off.

    3

  • FILE: REVISION:

    DRAWN BY: PAGE OF

    TITLE

    2

    4

    6

    1

    3

    5

    CONN_ICSP

    +5V

    Vss

    !MCLR

    VDD

    VSS

    DATA

    CLK

    NC

    1N4148

    10k

    15pF

    15pF

    Vss

    4MHz

    Low−speed wind−tunnel −− MCU

    Peter Jacobs

    100n

    470

    Vss

    1 3

    PIC18F2520

    !MCLR/VPP/RE31

    RA0/AN02

    RA1/AN13

    RA2/AN2/VREF−/CVREF4

    RA3/AN3/VREF+5

    RA4/T0CKI/C1OUT6

    RA5/AN4/!SS/HLVDIN/C2OUT7

    VSS8

    OSC1/CLKI/RA79

    OSC2/CLKO/RA610

    RC0/T1OSO/T13CKI11

    RC1/T1OSI/CCP212

    RC2/CCP113

    RC3/SCK/SCL14

    RC4/SDI/SDA15

    RC5/SDO16

    RC6/TX/CK17

    RC7/RX/DT18

    VSS19

    VDD20

    RB0/INT0/FLT0/AN1221

    RB1/INT1/AN1022

    RB2/INT2/AN823

    RB3/AN9/CCP224

    RB4/KBI0/AN1125

    RB5/KBI1/PGM26

    RB6/KBI2/PGC27

    RB7/KBI3/PGD28

    U101

    +5V

    Vss

    Vss

    SCL

    2

    1

    CONN_RESET

    47k

    02−Nov−2013

    MCU_TX

    SDA

    MCU_RX

    Vss

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    NC

    330

    330

    +5

    V

    4

  • FILE: REVISION:

    DRAWN BY: PAGE OF

    TITLE

    Low−speed wind−tunnel −− power and comms

    Peter Jacobs

    ST232CN

    C1+1

    V+2

    C1−3

    C2+4

    C2−5

    V−6

    T2OUT7

    R2IN8

    R2OUT9

    T2IN10

    T1IN11

    R1OUT12

    R1IN13

    T1OUT14

    GND15

    VCC16

    device=MAX232EPE

    U202

    +5V

    2

    1

    3

    CONN_RS232

    Vss

    100uH

    1u

    1u

    1u

    1u

    100n

    Vss

    Vss

    10RMCU_TX

    MCU_RX

    TX

    RX

    GND

    NC

    NC

    NC

    NC

    32

    +5V

    Vss

    2

    1

    CONN_POWER

    1N4004

    1N4004

    1210u

    121u

    IN OUT

    7805

    GND

    1

    2

    3

    U201

    +9 to 12V

    0V

    02−Nov−2013

    3

    2

    4

    1

    CONN_I2C

    2k2

    2k2

    Vss

    +5V

    SDA

    SCL

    +V

    GND

    SDA

    SCL

    5

  • FILE: REVISION:

    DRAWN BY: PAGE OF

    TITLE

    Low−speed wind−tunnel −− 18−bit data converter

    Peter Jacobs33

    02−Nov−2013

    MCP3422

    CH1+1

    CH1−2

    VDD3

    SDA4

    SCL5

    VSS6

    CH2+7

    CH2−8

    U301

    SDA SCL

    Vss

    2

    1

    3

    CONN_CH1

    VDD 5.0V

    GND

    Sensor signal 0.25−4.0V

    CH2+

    CH1+

    Vss

    Vss

    100n

    +5V

    Vss

    Vss

    CH1+

    2

    1

    3

    CONN_CH2

    Vss

    CH2+

    VDD 5.0V

    GND

    Sensor signal 0.25−4.0V

    100uH

    1210u

    Vss

    56k

    56k

    56k

    56k1u

    1u

    Vss

    Vss

    6

  • 2 Firmware

    The firmware running within the microcontroller is written in Forth, with the FlashForth interpreter [5] being previously pro-

    grammed into the MCU. During development, interaction with the microcontroller was through the RS232 serial port and the

    application code was built interactively, in the four stages.

    lswt.txt

    The first stage was to talk to the MC3422, via the I2C bus, and get the converted values as integer counts. These are reported

    via the RS232 serial port.

    1 \ lswt.txt

    2 \ Low -speed wind -tunnel board using a PIC18F2520 and FlashForth

    3 \ with mcp3422 and divide -by two analog input ,

    4 \ ready for Sensirion pressure sensors.

    5 \ PJ, 09-Nov -2013

    6

    7 -lswt

    8 marker -lswt

    9

    10 : mcp3422 -go -1 ( -- )

    11 \ $d0 is default mcp4322 address for writing

    12 \ 16-bit one -shot conversion of ch 1

    13 $d0 i2cws %10001000 i2c! spen

    14 ;

    15

    16 : mcp3422 -go -2 ( -- )

    17 $d0 i2cws %10101000 i2c! spen

    18 ;

    19

    20 : mcp3422@2byte ( -- n f ) \ Read the 16-bit result as 2 bytes

    21 $d1 i2cws i2c@ak $8 lshift \ MSB

    22 i2c@ak or \ LSB into same cell

    23 i2c@nak $80 and 0= \ leave true if result is latest

    24 ;

    25

    26 : report -counts ( n f -- )

    27 if ." new " else ." old " then

    28 . ." counts "

    29 ;

    30

    7

  • 31 : run -with -counts ( -- )

    32 decimal

    33 i2cinit

    34 begin

    35 mcp3422 -go -1 #100 ms mcp3422@2byte

    36 cr ." chan 1 " report -counts

    37 mcp3422 -go -2 #100 ms mcp3422@2byte

    38 cr ." chan 2 " report -counts

    39 #800 ms

    40 key? until

    41 hex

    42 ;

    lcd2s.txt

    The second stage was to talk to the Modtronix LCD, via the same I2C serial bus, and display text.

    1 \ lcd2s.txt

    2 \ Words for the Modtronix LCD2S display

    3 \ Peter J. 26-Oct -2013

    4

    5 \ Assume that i2c_base has been loaded.

    6

    7 -lcd2s

    8 marker -lcd2s

    9

    10 : lcdc! ( c -- ) $50 i2cws i2c! spen ;

    11

    12 : remember ( -- ) $8d lcdc! ;

    13

    14 : blight -off ( -- ) $20 lcdc! ;

    15 : blight -on ( -- ) $28 lcdc! ;

    16

    17 : lcd -clear ( -- ) $8c lcdc! ;

    18

    19 : lcd -curs -pos ( row col -- )

    20 swap \ now have S: col row

    21 $50 i2cws $8a i2c! i2c! i2c! spen

    22 ;

    23

    24 : lcd -go-line -2 ( -- )

    8

  • 25 $2 $1 lcd -curs -pos

    26 ;

    27

    28 : lcd -type ( c-addr n -- ) \ send string to be parsed

    29 $50 i2cws $80 i2c!

    30 for c@+ i2c! next

    31 spen drop

    32 ;

    33

    34 : lcd -hello ( -- )

    35 i2cinit

    36 lcd -clear

    37 s" Hello" lcd -type

    38 lcd -go -line -2

    39 s" World !" lcd -type

    40 ;

    lswt-1.txt

    We now need to convert from integer counts to voltage knowing that the sensitivity is 125µV for the least significant bit of theADC result. Since we would like to do the calculation with integers on the microcontroller, it is convenient to work with scaledunits of tenths of a millivolt and write the conversion as

    Vout

    [mV

    10

    ]= count ∗ 125

    100

    To avoid losing too much precision, this calculation is done with the scale operator for mixed-precision operands, m*/. Once wehave the voltage value in tenths of a millivolt, the output word, (d.1), displays the integer value in a format that puts a decimalpoint in front of the last digit, thus making the displayed result appear as a fractional number.

    1 \ lswt -1. txt

    2 \ Low -speed wind -tunnel board firmware

    3 \ extended to report millivolts to the LCD.

    4 \ Load lswt.txt and lcd2s.txt before this file.

    5 \ PJ, 09-Nov -2013

    6

    7 -lswt -1

    8 marker -lswt -1

    9

  • 9

    10 : mv10 ( n -- d )

    11 \ Convert 16-bit count to tenths of millivolts.

    12 \ With the divide -by-two resistors on the analog input ,

    13 \ the least -significant bit corresponds to 62.5*2 microvolts

    14 s>d #125 #100 m*/

    15 ;

    16

    17 : (d.1) ( d -- )

    18 swap over dabs

    19

    20 ;

    21

    22 : report -mv ( n f -- ) \ Assuming decimal , print millivolt value

    23 if ." new " else ." old " then

    24 mv10 (d.1) type space ." mV "

    25 ;

    26

    27 : report -mv -lcd ( n -- ) \ Display millivolt value to LCD

    28 mv10 (d.1) lcd -type s" mV" lcd -type

    29 ;

    30

    31 : run -with -volts ( -- )

    32 decimal

    33 i2cinit

    34 begin

    35 mcp3422 -go -1 #100 ms mcp3422@2byte 2dup

    36 cr ." chan 1 " report -mv drop \ S: ch1

    37 mcp3422 -go -2 #100 ms mcp3422@2byte 2dup

    38 cr ." chan 2 " report -mv drop \ S: ch1 ch2

    39 swap \ S: ch2 ch1

    40 lcd -clear s" ch1 " lcd -type report -mv -lcd

    41 lcd -go -line -2 s" ch2 " lcd -type report -mv -lcd

    42 #800 ms

    43 key? until

    44 hex

    45 ;

    10

  • lswt-2.txt

    The final stage of the firmware needs to do a bit more arithmetic to convert from voltage to pressure. If we continue to workin tenths of a millivolt

    [mV10

    ]and tenths of a Pascal

    [Pa10

    ], we can write the quadratic voltage-pressure relationship for the

    transducer [4] as

    ∆p[Pa

    10

    ]=

    Vout[mV10

    ]− 2500

    [mV10

    ]37500

    [mV10

    ]2 × 5000 [Pa

    10

    ]In the Forth code below, we do the calculation in two steps:

    dV = V out[mV

    10

    ]− 2500

    [mV

    10

    ]and, using two scale operations,

    ∆p[Pa

    10

    ]= (dV ∗ 5

    375) ∗ dV

    3750

    1 \ lswt -2. txt

    2 \ Low -speed wind -tunnel board firmware , continued ...

    3 \ We really want the pressure sensor values to be

    4 \ reported in Pascals.

    5 \ Builds on lswt -1. txt.

    6 \ PJ, 09-Nov -2013

    7

    8 -lswt -2

    9 marker -lswt -2

    10

    11 : mv10 -to-pa10 ( d1 -- d2 ) \ tenths of mV to tenths of Pa

    12 \ Incoming voltage should be in range 0.25V to 4.0V

    13 \ so d1 should be no bigger than 40000.

    14 #2500. d-

    15 2dup d0 < if 2drop 0. then \ S: d

    16 2dup \ S: d d

    17 #5 #375 m*/ drop \ S: d n1 ( max value is 533 )

    18 #3750 m*/ \ S: d2 ( in tenths of Pa )

    19 ;

    20

    21 : report -pa ( n -- ) \ Assuming decimal , print Pascal value

    22 space mv10 mv10 -to-pa10 (d.1) type ." Pa"

    23 ;

    11

  • 24

    25 : report -pa -lcd ( n -- ) \ Display Pascal value to LCD

    26 mv10 mv10 -to-pa10 (d.1) lcd -type s" Pa" lcd -type

    27 ;

    28

    29 : run -with -pa ( -- )

    30 decimal

    31 i2cinit

    32 begin

    33 mcp3422 -go -1 #100 ms mcp3422@2byte 2dup

    34 cr ." chan 1 " report -mv drop dup \ S: n1 n1

    35 report -pa \ S: n1

    36 mcp3422 -go -2 #100 ms mcp3422@2byte 2dup

    37 cr ." chan 2 " report -mv drop dup \ S: n1 n2 n2

    38 report -pa \ S: n1 n2

    39 swap \ S: n2 n1

    40 lcd -clear s" ch1 " lcd -type report -pa -lcd

    41 lcd -go -line -2 s" ch2 " lcd -type report -pa -lcd

    42 #800 ms

    43 key? until

    44 hex

    45 ;

    12

  • References

    [1] Microchip Technology Inc. PIC18(L)F2420/2520/4420/4520 data sheet: 28/40/44-pin enhanced flash microcontrollers with10-bit A/D and nanowatt technology. Datasheet DS39631E, Microchip Technology Inc., www.microchip.com, 2008.

    [2] Microchip Technology Inc. MCP3422/3/4: 18-bit, multi-channel ∆Σ analog-to-digital converter with I2C interface andon-board reference. Technical Report DS22088C, Microchip Technology Inc., www.microchip.com, 2009.

    [3] Modtronix Engineering. Serial LCD display. Datasheet LCD2S Revision 1, Firmware V1.40, http://www.modtronix.com/,2009.

    [4] Sensirion. SDP1108/SDP2108 low differential pressure sensor with fast response time. Datasheet, http://www.sensirion.com/,2013.

    [5] Mikael Nordman. FLASHFORTH for the Microchip PIC 18, 24, 30, 33 series and Atmel Atmega (Arduino) series. URLhttp://flashforth.sourceforge.net, http://personal.inet.fi/private/oh2aun, 2014.

    13