Lambda sensor display using 28X1

Rob Beck

New Member
Hi All,

I have been working on a display for a lambda sensor to connect to the serial data output from a Tech Edge lambda controller see http://wbo2.com/.

I have a 2J1 model (http://wbo2.com/2j/2j1.htm), the serial data format is common to a number of the different models, the serial data format is explained here http://wbo2.com/sw/logtech.htm (the 2J1 uses the 2.0 data frame format). I want to display lambda http://en.wikipedia.org/wiki/Air_Fuel_Ratio#Lambda so the only information in the data frame I am interested in is the two bytes of lambda16 (the relationship between lambda16 and lambda is explained here... http://wbo2.com/sw/lambda-16.htm)

I am using a 28X1 at 16Mhz to get to the 19200 baud rate of the Tech Edge output. I have a MAX202 for level conversion. The display consists of 3 off 7 segment displays, they are common anode with 3off ULN2803s to sink the LEDs. I am using 3 off CD4026Bs to drive the 7 segs. The PIC controls the decimal points via the 8th channel in the ULN2803s. I have used a LM317T to set the voltage for the 7 segs. The dps have resistors in series to half the voltage. The 28X1, MAX202 and the CD4026Bs are powered from a 7805.

The code is as follows:

Code:
'PICAXE 28X1 with 16MHz resonator
'MAX202 Rx connected to IN7.  Tx unused
'3 off 7 segment displays with CD4026B drivers
'CD4026B 
	'RST common.
	'CLOCKS are driven from separate PIC outputs, the CD4026Bs are not cascaded.
	'CLOCK INHIBITS common.
	'DISPLAY ENABLE daisy chained using DISPLAY ENABLE OUT pins
		'DP0		0
		'DP1		1
		'DP2		2
		'CLKUNI		3
		'CLKTEN		4
		'CLKHUN		5
		'RST		6
		'CLKINHIB	7
		'DISENB	PWM1/portc 1
		
	'To test the program copy and paste "23205,0,0,0,X,Y" into HSERIN dialogue box
	'subsitute X,Y for the MSB and LSB of Lambda16
	'significant lambda values in following table but all values 255,255 to 0,0 accepted
	'lambda	X	Y
	'228	 	255	255
	'100		191	128
	'5		141	0
	'4.5		128	0
	'1.5		32	0
	
setfreq em16				'external 16MHz resonator required to operate 19200 baud rate
hsersetup B19200_16,%01000 'for 28X1
symbol uni = b27
symbol ten = b26
symbol hun = b25
symbol dp = b24
symbol l16 = w0

startupscreen:				'light all the segments and decimal points to check display functions
	high 0,1,2				'light dps first
	pause 8000				
	let uni = 8
	let ten = 8
	let hun = 8
	low 7					'CLKINHIB OFF
	pulsout 6,10			'RST
	gosub unt
	gosub tns
	gosub hns
	high 7				'CLKINHIB
	high portc 1			'this is the CD4026B display enable, it may be possible to PWM this pin to change display brightness
		
	for b0 = 1 to 2				'DISABLE THIS PAUSE WHEN RUNNING SIMULATION!
	pause 40000				'1000= 1sec at 4MHz at 16Mhz = 0.25sec. At 16MHz this is 10sec looped 2 times to 
                                                        'allow lambda sensor to warm up.
	next b0

	gosub blank				'The display will show 0.0.0. until the first data packet is received from the tech edge
	
main: 
	hserin [4000,timeout],0,5,(%0101101010100101)
	get 4,b0
	get 3,b1
	if l16>49023 then goto hundreds
	if l16>37503 then goto tens
	if l16>36863 then goto units
	goto subfive

hundreds:
	let dp = 0				'set decimal point position
		let w1 = l16 / 128	'this and the next line convert to decimal lambda
		let b4 = w1 - 283
		let b10 = b4/10		'drop units
		let b11 = b4/100		'drop tens
	let uni = b4//10			'using //10 can only return a value 0-9
	let ten = b10//10
	let hun = b11//10
	goto display

tens:
	let dp = 1				'set decimal point position
		let w1 = l16 / 128	'this and the next line convert to decimal lambda
		let b4 = w1 - 283
		let b5 = l16//128		'get remainder
		let w3 = b5*10		'multiply to get relevant significant figures
		let b11 = b4/10		'drop tens
	let uni = w3/128			'convert significant figures to decimal lambda
	let ten = b4//10			
	let hun = b11//10
	goto display

units:
	let dp = 2				'set decimal point position
		let w1 = l16 / 128	'this and the next line convert to decimal lambda
		let b4 = w1 - 283
		let b5 = l16//128		'get remainder
		let w3 = b5*100		'multiply to get relevant significant figures
		let b10 = w3/128		'convert significant figures to decimal lambda
		let b11 = b10/10		'drop units
	let uni = b10//10
	let ten = b11//10
	let hun = b4//10
	goto display

subfive:
	let dp = 2				'set decimal point position
		let w1 = l16/16		'discard lsb only need lambda to 0.01
		let b4 = w1/512		'convert to decimal lambda
		let w3 = w1//512		'get remainder
		let w8 = w3*100		'multiply to get relevant significant figures
		let b10 = w8/512		'convert significant figures to decimal lambda
		let b11 = b10+50		'add offset
		let b12 = b11/10		'drop units
		let b13 = b11/100
		let b14 = b4+b13		'in case offset causes tens to spill to hundreds, 
                                                'this should not happen as 5.00 is dealt with by units
	let uni = b11//10
	let ten = b12//10
	let hun = b14//10
	goto display

display:
	low 0,1,2				'Cancel previous DP
	high dp				'set new DP
	low 7					'CLKINHIB OFF
	low portc 1				'low display enable turning on and off stops visible 
                                                'flicker of unused segments when digit doesnt change
	pulsout 6,10			'RST
	gosub unt
	gosub tns
	gosub hns
	high portc 1			'high display enable
	high 7				'CLKINHIB
	let b20 = 0				'HSERIN has received data so zero timeout counter
	pause 400				'this pause is to limit the refresh rate, its too fast without this!
	goto main

timeout: 
	let b20 = b20+1			'timeout counter
	if b20 > 2 then gosub blank	'if timeout occurs 3 times in a row then the screen blanks, 
                                                'until screen blanks it displays last value.
	goto main

blank:
	low 7					'display shows zeros and all dps, signals end of startup pause and timeout.  
	pulsout 6,10			'RST
	high 0,1,2
	high 7
	return
	
unt:	
	if uni = 0 then return endif
	for b15 = 1 to uni		'CLKUNI
	pulsout 3,10
	next b15
	return
	
tns:
	if ten = 0 then return endif
	for b15 = 1 to ten		'CLKTEN
	pulsout 4,10
	next b15
	return
	
hns:
	if hun = 0 then return endif
	for b15 = 1 to hun		'CLKHUN
	pulsout 5,10
	next b15
	return
It took me a while to get the HSERIN working using the two byte qualifier shown at the top of the Tech Edge data frame format. This evening I tried the version above with the two byte qualifier in binary and it works. Does this mean I can put $5AA5 or 23205 instead? Two byte qualifiers are not that clearly explained in the manual (I had an earlier version working with a single byte qualifier which used a logic statement to check for the second byte of the qualifier)

I opted for clocking each of the CD4026s separately rather than cascading so the display refreshes quickly. This was no issue on the 28X1 as there were pins to spare.

The displayed value for lambda can range from 0.50 to 200, to affect this the decimal point moves. I am thinking about changing the code to display .999 - .500 ie 3 significant figures rather than dropping to 2 significant figures below 1.00

Initially the display flickered due to it displaying 0 briefly on resetting the CD4026s, by setting Display Enable low before refreshing the display this has been eliminated. I had to add the 0.1 second pause to limit the refresh rate so the display can be read, without it the refresh rate is too high.

What I have shown above is the tidy version, I have a development version with various SERTXD commands for debugging and various counter bytes for checking the function of the program. Hopefully the comments included will be sufficient for you to follow what going on.

I would appreciate any suggestions for simplifying or improving the code or the hardware, this is my most complicated picaxe project to date by a fair margin. Any suggestions for added functionality? Now this is working I am wondering about a two line LCD display(16x2 would do) with the ability to select some of the other data from the Tech Edge serial data for the second display line. I think the way to do that would be to use an 18M2 to communicate with the Tech Edge (simplest way to run 19200 baud rate?) and LCD firmware chip, that sound about right?



The box is too big but its one out of the scrap pile so will do for now.

At least its working :) The next test is to put it on a vintage car to see if it can cope with the noise from the ignition system :eek: In the car it will run from a separate battery to the rest of the car. The car is 6volt electrics and the lambda sensor needs 12v for the heater coils. The data cable on the Tech Edge includes a battery voltage pin so I will run the display from that and connect the Tech Edge to the battery.

Regards

Rob
 

Attachments

Last edited:

Rob Beck

New Member
The circuit diagram as described above....

Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'                                                                                        '
'+5V---.---------------------------------------------.                                   '
'     .|.                                            |				         '
'  4k7[ ]                                            |                                   '
'     [_]          PICAXE-28X1                       |                                   '
'      |           .----.----.                       |                                   '
'      }-----------| 1    28 |-----.                 |                                   '
'      |         *-| 2    27 |-----|---------.       |                                   '
'     ]O         *-| 3    26 |-----|------.  |       |                                   '
' RST-]          *-| 4    25 |-----|----. |  |       |                                   '
'     ]O         *-| 5    24 |-----|--. | |  |       |                                   '
'      | SERRXD>---| 6    23 |-----|--|-|-|--|-------|----.                              '
'      | SERTXD>---| 7    22 |-----|--|-|-|--|-------|----|-.                            '
'      }-----------| 8    21 |-----|--|-|-|--|-------|----|-|-.                          '
'      |    RES>---| 9    20 |-----|--|-|-|--|-------{    | | |                          '
'      |    RES>---| 10   19 |-----|--|-|-|--|-------|-.  | | |                          '
'      |         *-| 11   18 |-----|--|-|-|--|--.    | |  | | |                          '
'      | .---------| 12   17 |-----|--|-|-|--|--|-.  | |  | | |                          '
'      | |       *-| 13   16 |-*   |  | | |  |  | |  | |  | | |                          '
'      | |       *-| 14   15 |-*   |  | | |  |  | |  | |  | | |                          '
'      | |         `---------'     |  | | |  |  | |  | |  | | |                          '
'      | |                         |  | | |  |  | |  | |  | | |                          '
'      | | .-----------------------'  | | |  |  | |  | |  | | |                          '
'      | | |    .------](------.      | | |  |  | |  | |  | | |                          '
'      | | |    |              |      | | |  |  | |  | |  | | |                          '
'      | | |    |    MAX202    }-](-. | | |  |  | |  | |  | | |                          '
'      | | |    |  .----.----. |    | | | |  |  | |  | |  | | |                          '
'      | | | .--|--|C1+   VCC|-^----|-|-|-|--|--|-|--{ |  | | |                          '
'      | | | |  `--|V+    GND|------^-|-|-|--|--|-|--|-{  | | |                          '
'      | | | `-](--|C1-   T1O|--------|-|-|--|--|-|--|-|--|-|-|-----------------<RS232TX '
'      | | | .-----|C2+   R1I|--------|-|-|--|--|-|--|-|--|-|-|-----------------<RS232RX '
'      | | | `-](--|C2-   R1O|--------|-|-|--|--' |  | |  | | |                          '
'      }-|-|---](--|V-    T1I|--------|-|-|--|----'  | |  | | |                          '
'      | | |    NC-|T2O   T2I|-NC     | | |  |       | |  | | |                          '
'      | | |    NC-|R2I   R2O|-NC     | | |  |       | |  | | |                          '
'      | | |       `---------'        | | |  |       | |  | | |                          '
'      | | |                          | | |  |       | |  | | |                          '
'      | | |         .----------------' | |  |       | |  | | |                          '
'      | | |         |                  | |  |       | |  | | |                          '
'      | | |         |    CD4026B-0     | |  |       | |  | | |   ULN2803-0              '
'      | | |         |   .----.----.    | |  |       | |  | | |  .----.----.             '
'      | | |         `---|CLK   VDD|----|-|--|-------{ |  | | `--|B7     C7|----<DP0#    '
'      | | }-------------|CIN   RST|----|-|--{  .----|-|--|-|----|B6     C6|----<F0      '
'      | `-|-------------|ENI   UGC|-NC | |  |  | .--|-|--|-|----|B5     C5|----<G0      '
'      | .-|-------------|ENO     C|----|-|--|--|-|--|-|--|-|----|B4     C4|----<C0      '
'      | | |          NC-|CAR     B|----|-|--|--|-|--|-|--|-|----|B3     C3|----<B0      '
'      | | |       .-----|F       E|----|-|--|--|-|--|-|--|-|----|B2     C2|----<E0      '
'      | | |       | .---|G       A|----|-|--|--|-|--|-|--|-|----|B1     C1|----<A0      '
'      }-|-|-------|-|---|VSS     D|----|-|--|--|-|--|-|--|-|----|B0     C0|----<D0      '
'      | | |       | |   `---------'    | |  |  | |  | }--|-|----|VSS   VL+|----<VCA+    '
'      | | |       | `------------------|-|--|--|-'  | |  | |    `---------'             '
'      | | |       `--------------------|-|--|--'    | |  | |                            '
'      | | |                            | |  |       | |  | |                            '
'      | | |         .------------------' |  |       | |  | |                            '
'      | | |         |                    |  |       | |  | |                            '
'      | | |         |    CD4026B-1       |  |       | |  | |     ULN2803-1              '
'      | | |         |   .----.----.      |  |       | |  | |     .----.----.            '
'      | | |         `---|CLK   VDD|------|--|-------{ |  | `----|B7     C7|----<DP1#    '
'      | | }-------------|CIN   RST|------|--{  .----|-|--|------|B6     C6|----<F1      '
'      | `-|-------------|ENI   UGC|-NC   |  |  | .--|-|--|------|B5     C5|----<G1      '
'      | .-|-------------|ENO     C|------|--|--|-|--|-|--|------|B4     C4|----<C1      '
'      | | |          NC-|CAR     B|------|--|--|-|--|-|--|------|B3     C3|----<B1      '
'      | | |       .-----|F       E|------|--|--|-|--|-|--|------|B2     C2|----<E1      '
'      | | |       | .---|G       A|------|--|--|-|--|-|--|------|B1     C1|----<A1      '
'      }-|-|-------|-|---|VSS     D|------|--|--|-|--|-|--|------|B0     C0|----<D1      '
'      | | |       | |   `---------'      |  |  | |  | }--|------|VSS   VL+|----<VCA+    '
'      | | |       | `--------------------|--|--|-'  | |  |      `---------'             '
'      | | |       `----------------------|--|--'    | |  |                              '
'      | | |                              |  |       | |  |                              '
'      | | |         .--------------------'  |       | |  |                              '
'      | | |         |                       |       | |  |                              '
'      | | |         |    CD4026B-2          |       | |  |       ULN2803-2              '
'      | | |         |   .----.----.         |       | |  |      .----.----.             '
'      | | |         `---|CLK   VDD|---------|-------' |  `------|B7     C7|----<DP2#    '
'      | | `-------------|CIN   RST|---------'  .------|---------|B6     C6|----<F2      '
'      | `---------------|ENI   UGC|-NC         | .----|---------|B5     C5|----<G2      '
'      |              NC-|ENO     C|------------|-|----|---------|B4     C4|----<C2      '
'      |              NC-|CAR     B|------------|-|----|---------|B3     C3|----<B2      '
'      |           .-----|F       E|------------|-|----|---------|B2     C2|----<E2      '
'      |           | .---|G       A|------------|-|----|---------|B1     C1|----<A2      '
'      }-----------|-|---|VSS     D|------------|-|----|---------|B0     C0|----<D2      '
'      |           | |   `---------'            | |    }---------|VSS   VL+|----<VCA+    '
'      |           | `--------------------------|-'    |         `---------'             '
'      |           `----------------------------'      |                                 '
'      |                                               |                                 '
'0v ---^-----------------------------------------------'                                 '
'                                                                                        '
'            *All unused pins on 28X1 connected to ground via 10K resistors              '
'  #Connected to DP pins of 7segs via pseudo resistor array made using 8pin DIL socket   '
'          and 150R resistors (easy to change res value to adjust brightness)            '
'                               +5V supply from LM7805                                   '
'                VCA+ (Voltage Common Anode) supplied by LM317T set to +4V               '
'                7 segs used are Kingbright SA10-11EWA high efficiency red               '
'                                                                                        '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I have been looking more into creating an LCD version with a 16X2 display. I have ruled out the 18M2 as I may need to implement a serial connection to another device at 57600 baud, this means I will have to use the HSER commands / pins which according to the manual appear to be rather limited on the M2 parts compared to the 28X1 / X2. Reading the manual I can't see that its possible to do 57600 baud on an 18M2 using SERIN / SEROUT

For various reasons I am looking at driving the LCD directly from the 28X1 without a separate serial to parallel converter.

I would appreciate any suggestions / tips / questions.

Regards

Rob
 
Last edited:

hippy

Technical Support
Staff member
I think the way to do that would be to use an 18M2 to communicate with the Tech Edge (simplest way to run 19200 baud rate?) and LCD firmware chip, that sound about right?
If you mean replacing / duplicating the 28X1 with an 18M2 then the HSERIN commands for the M2 is very different to the HSERIN for X1 and X2.

You might get it working with an M2 but I'd anticipate problems and would stick with an X1 or X2 because of that.
 

Rob Beck

New Member
Hippy,

Since my original post I have read about the 2 byte limit on the 18M2 HSERIN. I believe the above could be made to run on a 18M2 using SERIN instead. I have now got a version of the code working on the 28X1 using SERIN instead of HSERIN. I was sticking to HSERIN on the 28X1 version in case I needed to use the HSEROUT so I could keep all the serial comms on port C and not take up a portB pin for SEROUT. Now I have it all working I don't think I will be needing the HSEROUT / SEROUT so the next version of the 7 seg display (if there ever needs to be one) will be on the 18M2.

Is there any way to use an 18M2 for 57600 baud serial comms without the 2 byte limit? If not the LCD version will have to be on a 28X1 or X2.

Thanks

Rob

PS I have been out in the machine shop making up the manifold adapters to fit lambda sensors to my vintage car exhaust systems. The idea is to have the sensor on a bolt on part so that it can be removed without trace.
View attachment Lambda manifolds.pdf
 
Last edited:

hippy

Technical Support
Staff member
Good point about using SERIN rather than HSERIN ! 19200 baud is supported by SERIN on the PICAXE M2 so that should work, but 57600 baud isn't supported except when using HSERIN.

You could do 19200 baud input and 57600 output by mixing SERIN and HSEROUT but for 57600 input X1/X2 HSERIN would probably be best.
 
Top