OLED 20x4 problem on 16mHz

Hendriks

Member
Can someone explain to me why this doesn't work correctly:
Code:
pause 1000

#no_data
#PICAXE 08M2   

setfreq m16

Init:
	symbol LCD=C.1

	serout LCD,N2400_16,(254,1):pause 30;Clear LCD

	serout LCD,N2400_16,(254,128,253,0):pause 30 ; line 1, display msg0
	serout LCD,N2400_16,(254,192,253,1):pause 30 ; line 2, display msg1
	serout LCD,N2400_16,(254,148,253,2):pause 30 ; line 3, display msg2
	serout LCD,N2400_16,(254,212,253,3):pause 30 ; line 4, display msg3
while this works ok:
Code:
pause 1000

#no_data
#PICAXE 08M2   

Init:
	symbol LCD=C.1

	serout LCD,N2400,(254,1):pause 30;Clear LCD

	serout LCD,N2400,(254,128,253,0):pause 30 ; line 1, display msg0
	serout LCD,N2400,(254,192,253,1):pause 30 ; line 2, display msg1
	serout LCD,N2400,(254,148,253,2):pause 30 ; line 3, display msg2
	serout LCD,N2400,(254,212,253,3):pause 30 ; line 4, display msg3
The rest of the display routines work fine at 16mHz, just not the EEPROM messages:
253,0 displays msg2
253,1 displays nothing
253,2 displays msg8
253,3 displays nothing
 
Last edited:

Hendriks

Member
Thanks.

So I tried 'pause 120' but the problem remains.
Not exactly the same because now I get:

253,0 displays msg2
253,1 displays nothing
253,2 displays msg8
253,3 displays msg8
Code:
pause 1000

#no_data
#PICAXE 08M2   

setfreq m16

Init:
	symbol LCD=C.1

	serout LCD,N2400_16,(254,1):pause 120;Clear LCD

	serout LCD,N2400_16,(254,128,253,0):pause 120 ; line 1, display msg0
	serout LCD,N2400_16,(254,192,253,1):pause 120 ; line 2, display msg1
	serout LCD,N2400_16,(254,148,253,2):pause 120 ; line 3, display msg2
	serout LCD,N2400_16,(254,212,253,3):pause 120 ; line 4, display msg3
 
Last edited:

Hendriks

Member
Thanks.

I tried :
Code:
pause 1000

#no_data
#PICAXE 08M2   

setfreq m16

Init:
	symbol LCD=C.1

	serout LCD,N2400_16,(254,1):pause 120;Clear LCD

	serout LCD,N2400_16,(254,128):pause 120 ; line 1
	serout LCD,N2400_16,(253,0):pause 120   ; display msg0

	serout LCD,N2400_16,(254,192):pause 120 ; line 2
	serout LCD,N2400_16,(253,1):pause 120   ;  display msg1

	serout LCD,N2400_16,(254,148):pause 120 ; line 3
	serout LCD,N2400_16,(253,2):pause 120   ; display msg2

	serout LCD,N2400_16,(254,212):pause 120 ; line 4
	serout LCD,N2400_16,(253,3):pause 120   ;  display msg3
but the problems remains the same.

Just to be sure, I tried again without the 'setfreq m16' and it nicely displays message 0 to 3:
Code:
pause 1000

#no_data
#PICAXE 08M2   

Init:
	symbol LCD=C.1

	serout LCD,N2400,(254,1):pause 120;Clear LCD

	serout LCD,N2400,(254,128):pause 120 ; line 1
	serout LCD,N2400,(253,0):pause 120   ; display msg0

	serout LCD,N2400,(254,192):pause 120 ; line 2
	serout LCD,N2400,(253,1):pause 120   ; display msg1

	serout LCD,N2400,(254,148):pause 120 ; line 3
	serout LCD,N2400,(253,2):pause 120   ; display msg2

	serout LCD,N2400,(254,212):pause 120 ; line 4
	serout LCD,N2400,(253,3):pause 120   ; display msg3
 

nick12ab

Senior Member
As you're using a PICAXE-08M2, is there any reason why you cannot just write your code for the PICAXE-18M2 to control the OLED using the parallel interface? :)

Anyway for the serial interface try adding a pause at the beginning of your program.
 

Hendriks

Member
The final project however will be using a 20X2. I need the ports and the memory space.
Otherwise implementing in the AXE133 18M2 would be a good idea.

I already have a 'pause 1000' at the beginning of the program, see posts above. Or do you mean something else?
 

hippy

Technical Support
Staff member
It could be that at 16MHz the bytes are sent too close together for the OLED display to keep up with. If so then sending each byte separately as nick12ab suggests should resolve that. Also; what happens at 8MHz ?

The pragmatic solution is to drop the speed to 4MHz or 8MHz while the SEROUT's are executed and return to the higher desired speed after that. The time taken for the SEROUT commands is mostly fixed by the baud rate so there should be no noticeable performance hit in dropping speed, and it may actually improve performance if PAUSE statements can be removed ( though not applicable here ).

Doing it this way will allow you to use 32MHz in the rest of the code if that is desired. You won't have to worry that N2400_32 is not available.
 

Hendriks

Member
The strange thing is that all other LCD command work fine at 16MHz.
In another part of my program I use:
Code:
			serout LCD,N2400_16,(254,129,"AUTOMATISCH")
			serout LCD,N2400_16,(254,193,"Isttemperatur")
			serout LCD,N2400_16,(254,149,"Tages Solltemp")
			serout LCD,N2400_16,(254,213,"Nacht Solltemp")
and this works fine.
ONLY the EEPROM messages don't work.

I have no problem to work around by dropping the speed to 4MHz every time I update the display. It is just that I can't figure why only the EEPROM messages don't work.
 

nick12ab

Senior Member
The strange thing is that all other LCD command work fine at 16MHz.
This only happens with the predefined EEPROM messages because the slow PICAXE interpreter in the receiving PICAXE causes the time difference it takes between exection of the 'if b1 = 254' and 'if b1 = 253' condition testing statements causes the start of the byte that indicates the message number to get missed by the receiving PICAXE. This is because of the order of the elseif statements below:
Code:
	if b1 < 253 then
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		goto main			; quickly loop back to top
	else if b1 = 254 then
		low rs 	     		; change to command mode for next character
		serin RX,baud,b1		; wait for the command byte
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		high rs			; back to character mode
		goto main			; quickly loop back to top
	else if b1 = 253 then
		serin RX,baud,b1		; wait for the next byte
		gosub msg			; do the 16 character message
		goto main			; back to top
	else ; must be 255
		serin RX,baud,b1		; wait for the next byte
		let pinsC = b1 & %00000111 | %10000000
						; output the data on C.0 to C.1, keep RS high
		goto main			; back to top
	end if
 

srnet

Senior Member
The strange thing is that all other LCD command work fine at 16MHz.
In another part of my program I use:
As Nick says, its not really that odd, and I suspect there may be other commands that malfunction when the bytes are coming in too fast for the 18M2 display driver to handle.
 

hippy

Technical Support
Staff member
It is just that I can't figure why only the EEPROM messages don't work.
Looking at "AXE133 Serial OLED.bas"; there is a little more to do before getting the byte after a 253 or a 255 than after a 254 and that could be making the difference.

If you split the code that may overcome the problem, for example -

serout LCD,N2400,(253) : serout LCD,N2400,(0) ...
 

westaust55

Moderator
As mentioned by hippy, it may well be a timing issue.

For non-command situations each byte received is accepted and passed on after only one IF&#8230;THEN test.
A 254 command takes two IF..THEN tests and then the second byte is read and passed on
Whereas for a 253 command there are in effect three IF&#8230;THEN tests to be performed and be ready for the next byte to indicate the message.

The time taken to receive the first byte and get ready for the second byte could be roughly of the order of 2 ms with the AXE133 PICAXE at 16MHz.
When sending a series of bytes from another PICAXE running at 16 MHz the fetch next byte and start to send period may be too tight for the AXE133 with the 253 control commands.
The AXE133 delay for a 254 command may be just a fraction of a milli second faster and for other characters a fraction faster again but that may be enough that that the other SEROUT strings work okay.

Have you tried at 8MHz as suggested.


EDIT: obviously slow on the typing tonight - last few posts are all on the same wavelength :)
 

Hendriks

Member
At 8MHz the problem is still the same.

Now I understand the 253 commands need more time to get processed, I tried:
Code:
serout LCD,N2400_16,(254,128):pause 120 ; line 1
serout LCD,N2400_16,(253)
serout LCD,N2400_16,(0):pause 120       ; display msg0
and that worked fine.
No pause needed after the 253 command. Splitting the line up in two 'serout' commands was enough.

The 'pause 120' was still needed between displaying the four messages. In fact, the smallest pause accepted was 'pause 80'.

Thanks.
 
Top