Menu

Automotive Gauges

2022-10-02
2023-10-21
  • David Stephenson

    There are a number of types, but the most common is the X27.168. There are a number of conflicting descriptions online and the full datasheet is hard to find (so I will attach it).
    Basically what you have is very similar to what you would find in an analogue quartz clock. The differences being that the rotor has 3 sectors and the stator has two coils. This allows both forward and backward rotation using a 6 pulse sequence. A full rotation is 1080 steps (1/3° per step) so it almost looks continuous - the full rotation takes about 2 seconds(if you want to go that fast). The unit as supplied will only go through 315°, but removal of a tag makes it full rotation.
    Just as a demonstration I have made a temperature gauge. To increase the degree of difficulty I am reading the outside temperature via a rf link (using a RFM69).
    The gauge can be driven straight from the microprocessor pins (16F18326) no back emf protection is required because of the high resistance of the inductors. It runs quite nicely on 3V (2xAA batteries).
    They are also quite cheap (especially from China).

     
  • David Stephenson

    Here's the code and attached is the datasheet.

    #chip 16F18326,8
    #config RSTOSC=hfint1, MCLRE=Off, WDTE=off, boren=off, FEXTOSC_OFF, CLKOUTEN_OFF, CP_OFF
    unlockpps
      'Module: MSSP1
                RA0PPS = 0x0018    'SCK1 > RA0
                SSP1CLKPPS = 0x0000    'RA0 > SCK1 (bi-directional)
                RA2PPS = 0x0019    'SDO1 > RA2
                SSP1DATPPS = 0x0003    'RA3 > SDI1
      'Module: MSSP2 ***********************only for testing rx*******
                'RC2PPS = 0x001A    'SCK2 > RC2
                'SSP2CLKPPS = 0x0012    'RC2 > SCK2 (bi-directional)
                'RC1PPS = 0x001B    'SDA2 > RC1
                'SSP2DATPPS = 0x0011    'RC1 > SDA2 (bi-directional)
    lockpps
    
    
    trisc=b'00000000' 'pointer pins c.0,c.1,c.2,c.3
    latc=b'00000000'
    k1=3
    inipoint 'get pointer in phase!
    
    dim id8,id9 as word
    dim tt,tt40out,tempword,humword,qt,ttt as word
    
    dim a1,a2,a3,a4,a4old,ttold as WORD
    dim a5,a6,a7 as word
    wait 1 sec
    a4old=0 '20 deg C
    a4=0
    mov=0
    a7=0
    a1=0
    ttt=2338
    ttold=2338 '20 deg set pointer
    
    #define HWSPIMode MasterSSPADDMode 'is this necessary?
    SPIMode Mastersspaddmode,0 'initialize spi
    cpha=0:cpol=0 'dont think this is needed - belt and braces!
    'set SPI pins
    dir porta.1 out 'chip select
    set porta.1 on 'unselect
    dir porta.3 in 'sdi
    dir porta.2 out 'sdo
    dir porta.0 out 'clk
    dir porta.4 in 'clock xtal
    dir porta.5 in 'pins
    intcon.6=1 'enable interrupts
    t0con0=b'10011110' '15:1 post scaler(bits3-0=1110) bit4(=1-->16) 16/8 bit
    'bit7 enabled
    
    't0con1=b'11011011' '1:2048
    't0con1=b'11010011' '1:8 4 minutes
    't0con1=b'11010000' '1:1 30sec
    t0con1=b'11010001' '1 min
    'bits 7-5 110= SOCS,bit4=0 not sync with clk
    'bits 3-0 =0001 2:1 pre-scaler --> 1 min (with 15:1 post-scale)
    't0con1=b'11010010' '1:4 2 mins
    tmr0h=b'00000000'
    tmr0l=b'00000000'
    pie0.5=1 'enable t0 overflow int
    pir0.5=0 'int reset
    
    ini_rfm69
    do
    spiwrite(0x01,0x04) 'stndby
    wait 1 ms
    spiwrite(0x28,0x10) 'clear fifo for data
    'wait 200 ms 'new delay
    rx_rfm69 'start receiving
    wait 1 ms 'new delay
    
    do
    spiread(0x24,rssidat)
    if rssidat<205 then exit do 'check Tx really ready
    wait 10 us
    loop
    pir0.5=0
    do
    spiread(0x28,fifordy)
    if (fifordy and 0x04) = 0x04 then exit do 'fifo data ready?
    wait 50 us
    loop
    wait 100 us
    'wait 1 ms
    'spiread(0x24,rssidat)
    rxpacket_rfm69
    spiwrite(0x01,0x00) 'sleep rfm69
    tmr0h=b'00000000' 'delay so we dont miss the transmission was 00000011
    tmr0l=b'10000000' 'is it long enough??
    'tz1 tz2
    sht40out
    pointer
    
    vregpm=1 'not for LF model
    sleep 'pic16f18326
    vregpm=0
    nop
    pir0.5=0 'reset interrupt flag
    loop
    
    sub pointer
    if ttold=ttt then return
    if ttold<ttt then a4=ttt-ttold:mov=1
    if ttold>ttt then a4=ttold-ttt:mov=0
    ttold=ttt
    if a4=0 then return
    if mov=0 then point_acw
    if mov=1 then point_cw
    
    end sub
    
    sub point_cw
    do
    k1=k1+1
    a4=a4-1
    if k1=7 then k1=1
    readtable pulses,k1,cout
    latc=cout
    wait 2 ms
    if a4=0 then exit do
    loop
    wait 5 ms 'make sure pointer stops
    latc=0
    end sub
    
    sub point_acw
    do
    k1=k1-1
    a4=a4-1
    if k1=0 then k1=6
    readtable pulses,k1,cout
    latc=cout
    wait 2 ms
    if a4=0 then exit do
    loop
    wait 5 ms
    latc=0
    end sub
    
    sub inipoint
    repeat 36
    k1=k1+1 'cw rotation 19-20 deg
    if k1=7 then k1=1
    readtable pulses,k1,cout
    latc=cout
    wait 5 ms
    latc=0
    wait 10 ms
    end repeat
    latc=cout
    wait 10 sec 'hold to mount pointer
    latc=0
    end sub
    
    table pulses '6 pulse sequence for 2 deg rot
    b'00000101' 'each step 1/3 deg (angle - not temperature)
    b'00000001'
    b'00001000'
    b'00001010'
    b'00000010'
    b'00000100'
    end table
    
    sub sht40out
    'sht40 highbyte 1st
    tempword=tz2
    tempword_h=tz1
    tempword=tempword+6 'round up
    tt=tempword/4+tempword/59+tempword/10000 'temp*100
    ttt=tempword/11+tempword/192 'temp*36 for gauge
    qt=tt/10
    if tt<4501 then tt40out=4500-tt:st40out=1
    if tt>4500 then tt40out=tt-4500:st40out=0
    humword=hz2
    humword_h=hz1
    hh40out=(humword/5+humword/107)-600
    'ttt is the value!
    end sub
    
    
    sub ini_rfm69
    spiwrite(0x07,0x6c)      'frequency
    spiwrite(0x08,0x80)      'set
    spiwrite(0x09,0x00)      '//434MHz
    
    'reg value/16384 = f in MHz
    
    spiwrite(0x02,0x00)      '//RegDataModul                     FSK Packet
    spiwrite(0x05,0x02)      '//RegFdevMsb               241*61Hz = 35.2KHz
    spiwrite(0x06,0x41)      '//RegFdevLsb
    
    spiwrite(0x03,0x03)      '//RegBitrateMsb                   32MHz/0x06 10 = 38.4kpbs
    spiwrite(0x04,0x41)      '//RegBitrateLsb
    
    'spiwrite(0x03,0x01)      '//RegBitrateMsb                   32MHz/0x06 10 = 76.8kpbs
    'spiwrite(0x04,0xA1)      '//RegBitrateLsb
    spiwrite(0x13,0x0F)      '//RegOcp                          Disable OCP
    'spiwrite(0x18,0x81)      '//RegLNA - max gain                       200R
    spiwrite(0x18,0x01)      '50 ohms max gain
    
    'spiwrite(0x19,0x52)      '//RegRxBw                           RxBW    83KHz
    spiwrite(0x19,0x4A)      '//RegRxBw        adj this            RxBW    100KHz
    'If these are wide enough it does not seem to matter
    'maybe with near channel interference it should be set as low as possible?
    spiwrite(0x2C,0x00)      '//RegPreambleMsb
    spiwrite(0x2D,0x02)      '//RegPreambleLsb  2Byte Preamble
    spiwrite(0x2E,0x90)      '//enable Sync.Word                  2+1=3bytes
    spiwrite(0x25,0x03)      '// DIO mapping1 DIO3-->PLL lock
    SPIWrite(0x29,0xC8)      '//         RegRssiThresh 200
    spiwrite(0x2F,0xDA)      '//1st byte SyncWord = DA 71 D8
    spiwrite(0x30,0x71)      '//sync word 2nd byte
    spiwrite(0x31,0xD8)      '//sync word 3rd byte
    spiwrite(0x37,0x08)      '//RegPacketConfig1    Disable CRC ,NRZ encode
    spiwrite(0x38,0x04)      '//RegPayloadLength    4 bytes for length & Fixed length
    spiwrite(0x58,0x1B)      '//RegTestLna                Normal sensitivity
    spiwrite(0x58,0x2D)      '// high sens
    spiwrite(0x6F,0x30)      '//RegTestDAGC              Improved DAGC
    spiwrite(0x01,0x04)      '//??Standby
    end sub
    sub spiwrite (addr1,dat1)
    set porta.1 off
    addrw=addr1 or 0x80
    FastHWSPITransfer addrw 'write
    FastHWSPITransfer dat1
    set porta.1 on
    end sub
    
    sub spiread (addr2,dat2)
    set porta.1 off
    fasthwspitransfer addr2 'read reg
    spitransfer 0x00,dat2
    set porta.1 on 'deselect
    end sub
    
    sub rx_rfm69
    'spiwrite(0x11,0x9F)      '//RegPaLevel Fifo In for Rx
    'spiwrite(0x25,0x44)      '//DIO Mapping for Rx
    spiwrite(0x5A,0x55)      '//Normal and TRx
    spiwrite(0x5C,0x70)      '//Normal and TRx
    spiwrite(0x01,0x10)      '//Entry to Rx
    do
    spiread(0x27,rxdat)
    if (rxdat and 0xC0)=0xC0 then exit do 'check for rx ready
    wait 1 ms
    loop
    end sub
    
    sub clrfifo_rfm69 'not needed
    SPIWrite(0x01,0x04)     '//Entry Standby Mode
    SPIWrite(0x01,0x10)     '//Change to Rx Mode
    end sub
    
    sub RxPacket_rfm69
    'spiread(0x24,rssidat)
    SPIRead(0x00,tz1) 'temperature
    spiread(0x00,tz2)
    spiread(0x00,hz1) 'humidity
    spiread(0x00,hz2)
    'spiread(0x24,rssidat)
    end sub
    
     
  • David Stephenson

    I've been doing further experiments. I got some VID29-07 steppers. They seem better constructed than the x21768, but they work in exactly the same way - a 6 pulse sequence for 2 degrees.
    I tried shaped pulses (using PWM) but it did not seem to make any difference to the performance.
    The thing that does make a difference is that the pulses that energize two coils should be half the length of the other pulses (I'm using 1.5 ms and 3 ms for the short and long) seems to be much smoother.
    So I've made a barometer. The detector is a LPS22HB. I have attached a photo the main dial is showing the atmospheric pressure in millibars; the smaller dial is showing the change in pressure (over the last 3 hours) - this is apparently important for weather determinations.
    So the reading is about 1010 mb and the pressure is falling slowly (0.5 mb/3hr).

     
  • David Stephenson

    There are also steppers of this type with two concentric shafts VID28-05 (aka BKA30D-R5).
    I have made a temperature gauge that shows both inside and outside temperatures.
    Attached is a picture of the gauge and that of the double stepper motor (note the large number of cogs - this give rise to lash and some inaccuracy). It would seem I can only load one picture per post so the cogs will have to wait.

     
  • David Stephenson

    Here's a picture with the top removed to reveal the two steppers and a mass of cogs.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.