It also had problems with the way the hex numbers were divided between the lookup commands as the end ones were duplicated causing some problems but that was fixed and your fix also applied and it now takes 0.6 seconds to print the entire character set on-screen.You need to subtract from 'executebyte' rather than add. For example, if it's not < 32 but is < 64 then it holds value 32..63, the LOOKUP index starts at 0, so subtract 32 giving 0 to 31.
if executebyte < 32 then
lookup executebyte,(0,$1020,$4444,$1474,$1D15,$1515,$1516,$1038,$FE83,$2214,$0808,$7F10,$4E71,$0002,$0808,$0000,$0808,$0000,$0000,$0808,$0808,$0808,$0000,$0808,$0808,$FFFF,$3E41,$3E41,$7F7F,$7F41,$7F00,$487E),cw1
lookup executebyte,(0,$7F01,$5F44,$1C17,$1700,$1F00,$7C16,$5410,$8183,$0814,$2A08,$100F,$0171,$0502,$0808,$FF00,$FF08,$F808,$0F08,$0F00,$F800,$FF00,$FF08,$0F08,$F808,$FFFF,$7549,$5D49,$7F7F,$4141,$7F00,$4949),cw2
lookup executebyte,(0,$0100,$4400,$1400,$0000,$0000,$1500,$1F00,$FE00,$2200,$0800,$1000,$4E00,$0000,$0808,$0000,$0808,$0808,$0808,$0000,$0000,$0000,$0808,$0808,$0808,$FFFF,$3E00,$3E00,$7F00,$7F00,$7F00,$4200),cw3
elseif executebyte < 64 then
executebyte = executebyte - 32
lookup executebyte,($0000,$0000,$0003,$147F,$242A,$2313,$3649,$0005,$001C,$0041,$1408,$0808,$0050,$0808,$0060,$2010,$7F41,$0000,$7949,$4149,$0F08,$4F49,$7F49,$0101,$7F49,$0F09,$0036,$0056,$0814,$1414,$0041,$0201),cw1
lookup executebyte,($0000,$4F00,$0003,$147F,$7F2A,$0864,$5522,$0300,$2241,$221C,$3E08,$3E08,$3000,$0808,$6000,$0804,$4141,$0000,$4949,$4949,$0808,$4949,$4949,$0101,$4949,$0909,$3600,$3600,$2241,$1414,$2214,$5109),cw2
lookup executebyte,($0000,$0000,$0000,$1400,$1200,$6200,$5000,$0000,$0000,$0000,$1400,$0800,$0000,$0800,$0000,$0200,$7F00,$7F00,$4F00,$7F00,$7F00,$7900,$7900,$7F00,$7F00,$7F00,$0000,$0000,$0000,$1400,$0800,$0600),cw3
elseif executebyte < 96 then
executebyte = executebyte - 64
lookup executebyte,($3E41,$7C12,$7F49,$3E41,$7F41,$7F49,$7F09,$3E41,$7F08,$0041,$2040,$7F08,$7F40,$7F02,$7F04,$3E41,$7F09,$3E41,$7F09,$4649,$0101,$3F40,$1F20,$3F40,$6314,$0304,$6151,$007F,$0204,$0041,$0402,$4040),cw1
lookup executebyte,($5D55,$1112,$4949,$4141,$4122,$4949,$0909,$4949,$0808,$7F41,$413F,$1422,$4040,$0C02,$0810,$4141,$0909,$5121,$1929,$4949,$7F01,$4040,$4020,$3840,$0814,$7804,$4945,$4141,$0810,$417F,$0102,$4040),cw2
lookup executebyte,($1E00,$7C00,$3600,$2200,$1C00,$4100,$0100,$7A00,$7F00,$0000,$0100,$4100,$4000,$7F00,$7F00,$3E00,$0600,$5E00,$4600,$3100,$0100,$3F00,$1F00,$3F00,$6300,$0300,$4300,$0000,$2000,$0000,$0400,$4000),cw3
else
executebyte = executebyte - 96
lookup executebyte,($0000,$2054,$7F48,$3844,$3844,$3854,$087E,$0C52,$7F08,$0044,$2040,$7F10,$0041,$7C04,$7C08,$3844,$7C14,$0814,$7C08,$4854,$043F,$3C40,$1C20,$3C40,$4428,$0C50,$4464,$081C,$0402,$0808,$0804,$1020),cw1
lookup executebyte,($0305,$5454,$4444,$4444,$4448,$5454,$0901,$5252,$0404,$7D40,$443D,$2844,$7F40,$1804,$0404,$4444,$1414,$1418,$0404,$5454,$4440,$4020,$4020,$3040,$1028,$5050,$544C,$2A08,$7F02,$2A1C,$0810,$7F20),cw2
lookup executebyte,($0000,$7800,$3800,$2000,$7F00,$1800,$0200,$3E00,$7800,$0000,$0000,$0000,$0000,$7800,$7800,$3800,$0800,$7C00,$0800,$2000,$2000,$7C00,$1C00,$3C00,$4400,$3C00,$4400,$0800,$0400,$0800,$0800,$1000),cw3
end if
I triednto play that pdf you attached but i could not play it, either unsupported or the file was corrupt ?I need help for getting text onto a KS1080B 128x64 GLCD as sold by Techsupplies at a decent speed. The trouble is - this controller doesn't seem to have a built-in capability for text. Putting text onto the display takes up much of the PICAXE (40X2) memory just for the numbers to define which pixels need to be set for which letters.
I decided that to overcome this I could use a serial driver chip for the display which is capable of putting text on it. I checked out the FGC thing offered on Techsupplies but it has flaws and is expensive. Its flaws are slow serial, and only allowing 7 lines of text when the display is capable of 8. I started producing my own version on the PICAXE-20X2 which lacks the circle-drawing and other features of the GLIC-K1 but has text on 8 lines, a PWM pin used for controlling the backlight (command: 249, byte for level), and allows direct control of the LCD as well through the high speed serial interface.
Only problem - it is very slow at printing the characters on screen... well not very slow for human standards but slow to computer standards. When the serial connection is disconnected, it continues printing the text which shows that all the data has already been received through hardware serial.
The code is attached as it is too big to show here. I'm thinking I may need to go for a lookup table with the command of the same name but typing that out will take an eternity so I'm looking for advice first. I have also included a video to demonstrate it. Those who own a GLIC-K1 may be able to tell me whether it provides a faster speed or not. Either way, I want this to look more professional.
The latest version of the code can be found at the end of this thread. The video has a PDF extension so that it can be uploaded here but you must change the extension back to 3gp to watch it.
Have you changed the file extension to 3gp ? PICAXE Forum does not support video uploads so I changed the extension to pdf so that I could upload it here.I triednto play that pdf you attached but i could not play it, either unsupported or the file was corrupt ?
You might eek out an extra microsecond per instruction performance but it probably wouldn't be noticeable.Also, would using the 'disconnect' command increase the speed or does whatever scanning for the download does not have enough overhead for it to slow down the program whatsoever?
Using seperate inverted and non-inverted character sets probably wouldn't fit into program memory and the IF statement to determine which to use would probably take longer to execute. Couldn't find a bintoascii anywhere in the code. Do you mean bintobcd?You'd gain more by optimising out the ^invertbyte when not required; two sets of code for when invertbyte is zero and when it isn't, turning some of the LOOKUP into READ and READTABLE. You've still got a BINTOASCII and a divide by 20 which will will slow things down.
For your code example to work, multiple IF statements would have to be used on the short LOOKUPs as there is only one remaining word that can have its bits accessed with bit#. The time taken for those extra IF statements would probably exceed the time gained by removing a line from each enable sequence as microcontrollers are best at doing simple maths and an IF statement would probably use a lot more instructions than a let something equal something else statement.The suggestions are the things I personally would consider if I were doing it. There seems plenty of space left and, while TABLE and EEPROM can only hold bytes, the gains in shortening the LOOKUP is probably greater than any overhead.
It's a good question of is the IF faster than all the ^invertByte; best way to tell is to try it.
One thing I forgot to mention is moving the 'cw' and 'cb' variables into w0, w1, b0-b3, as that could shave some more time off the case without ^invertbyte, for example ...
LookUp .... , cw1
:
let lcddata = cb1
let pinsB = lcddata
let pinC.1 = bit30
pulsout enablepin,1
let lcddata = cb2
let pinsB = lcddata
let pinC.1 = bit30
pulsout enablepin,1
Could then become ...
Symbol cw1 = w0
Symbol cb1 = b0
Symbol cb2 = b1
:
LookUp .... , cw1
:
let pinsB = cb1
let pinC.1 = bit6
pulsout enablepin,1
let pinsB = cb2
let pinC.1 = bit14
pulsout enablepin,1
That's two assignments which become redundant and have been removed, plus the LOOKUP into cw1 can be replaced in the fast case by
Read ... , cb1
ReadTable ... , cb2
So you get the same result and no additional assignments needed no matter which way it's done.
Of course the real question is; is it fast enough already ? If so it's not worth struggling to save a few microseconds or milliseconds.
, I actually meant to say "Using disconnect caused some commands to run a little bit faster but also caused others to run slower." so I will edit that in, but why would using Disconnect have strange effects like that?nick12ab said:Using disconnect caused some commands to run a little bit faster but also caused others to run faster.
Sometimes code optimisation means having to move things around, reassigning variables and dealing with the consequences of that. It's not uncommon to develop in stages, create a prototype which works, analyse how it could be better, rip it up entirely and restart with a blank canvas using knowledge gained.For your code example to work, multiple IF statements would have to be used on the short LOOKUPs as there is only one remaining word that can have its bits accessed with bit#.
The check for download mainly occurs between commands ( and, for a few, within them ) so I would not have expected there to have been any appreciable increase or decrease in any commands you are using. Can you give examples of those commands which slow down ?I actually meant to say "Using disconnect caused some commands to run a little bit faster but also caused others to run slower." so I will edit that in, but why would using Disconnect have strange effects like that?
I'm not sure who the others are and what you are comparing with, is it truly like for like ?Also, I don't understand how others have managed to get theirs much faster than mine.
If invertByte = 0 Then
PinsB = b0
PinC.1 = bit6
PinsB = b1
PinC.1 = bit14
Else
b0 = b0 ^ invertByte
PinsB = b0
PinC.1 = bit6
b1 = b1 ^ invertByte
PinsB = b1
PinC.1 = bit14
End If
If invertByte = 0 Then
LookUp ... , b0
LookUp ... , b1
Else
LookUp ... , b0
LookUp ... , b1
End If
PinsB = b0
PinC.1 = bit6
PinsB = b1
PinC.1 = bit14
If invertByte = 0 Then
If index < 128 Then
Read index, b0
ReadTable index, b1
Else
index = index - 128
LookUp ... , b0
LookUp ... , b1
End If
Else
If index < 128 Then
Read index, b0
ReadTable index, b1
b0 = b0 ^ invertByte
b1 = b1 ^ invertByte
Else
index = index - 128
LookUp ... , b0
LookUp ... , b1
End If
End If
PinsB = b0
PinC.1 = bit6
PinsB = b1
PinC.1 = bit14
Posts 32 and 34 show Dippy's GLCD and he says that it only took 200ms. For the amount of characters, it is about the same as mine is now for the amount of text but as he's using variable-width, fixed-width should be faster. His GLCD is completely identical to mine.I'm not sure who the others are and what you are comparing with, is it truly like for like ?
They may not have used the same hardware, nor be controlling the same display or doing exactly what you are doing, and probably not using the same techniques.
I will re-test them soon and post results.Hippy said:The check for download mainly occurs between commands ( and, for a few, within them ) so I would not have expected there to have been any appreciable increase or decrease in any commands you are using. Can you give examples of those commands which slow down ?
I think you'll find that Dippy's controller was related to, but not a PICAXE (and was probably written using a BASIC compiler as opposed to running as interpreted basic)Posts 32 and 34 show Dippy's GLCD and he says that it only took 200ms.
Thanks for the praise, but it would have been impossible without the help of all the forum members who have posted stuff here.Ha, yes you are nearly right Martin, I was having a practice run
I think Nick has done a great job doing the text at the speed he has achieved.
The main part that slows mine down is the coding technique I used to work as a general purpose drop of code which could work on many PICs.
E.G. Drawing a line. The accepted GP technique is to read a byte from the GLCD memory then logical bitwise add your dot and then rewrite. You do this because there may be already a dot occupying that byte. If you didn't then you would overwrite the byte and obliterate anything already there.
The other method (which I used for an OLED) is to store the GLCD memory 'mapped' on the PIC.
You then do your bitwise in PIC RAM and send the whole screen (or the relevant section of screen). This is much faster as there is only one-way traffic and RAM operations are many times faster than I/O.
My tests with an OLED (modern driver) shows a 20x speed improvement even sending the whole screen.
In my code the character (text) write is a simple write (no logical ops) and that takes around 100mS. I store my Font data as literal in Flash (programme space).
Notes.
One of the main issues with GLCDs is the pixel reresh speed.
They simply cannot keep up with there own drive electronics.
I have tried animation and even at the equiv of 6 frames per second they just look a messy blurr.
And, with a compiler, their drive elctronics can't keep up with compiled code, in fact I have to put pauses in the pin-twiddling routine.
With an OLED animations are very possible. I'm experimenting with a high-speed link from (my own) SD controller to (hopefully) get > 10fps. Albeit in mono 1-bit.
In summary Nick, you should be really pleased with what you've done but I'm afraid you'll probably never get it going much faster. I think what you have achieved is really good.
Dippy said that Martin was nearly right so was Dippy's code compiled rather than interpreted?MartinM57 said:I think you'll find that Dippy's controller was related to, but not a PICAXE (and was probably written using a BASIC compiler as opposed to running as interpreted basic)
Interesting with the BINTOBCD. At 64K loops that 80ms difference works out at 1us per command. I would guess that's an instruction cycle delay which depends on whether a skip is taken or not, or more compound code behaving in a similar way. It does demonstrate though how even a very small difference can add up over a long enough time.Here's the results for the experimentation on using DISCONNECT.
One thing that vaguely makes up for the awful contrast is that you can safely remove the LCD panel from the PCB and put it back in upside down to change the viewing angle. It works with any LCD, character or graphic, which has connectors at both the top and the bottom of the panel. Rev-Ed's GLCD comes designed to be viewed from below making it unsuitable for any application which is viewed from above without modification as above.GLCD contrast quality varies quite a lot but none that I have seen are as good as modern cellphone etc. display quality. Your only safe 'controls' are supply voltage and the 'contrast' voltage setting.
Yes, it is compiled.
setfreq [B][I]em40[/I][/B] 'Use [B][I]64MHz[/I][/B] as operating speed
pwmout backlightpin,64,backlight 'Set backlight to saved value
invert = 1 'Set default inversion setting: Not Inverted
x000: hsersetup B38400_[B][I]64[/I][/B],%00111 'Initialise hardware serial input
Oops! Failed to change that to B38400_40 for the 40MHz permitted by the 40X2-5v which I'm using.What's the rationale for the inconsistency?Code:setfreq [B][I]em40[/I][/B] 'Use [B][I]64MHz[/I][/B] as operating speed pwmout backlightpin,64,backlight 'Set backlight to saved value invert = 1 'Set default inversion setting: Not Inverted x000: hsersetup B38400_[B][I]64[/I][/B],%00111 'Initialise hardware serial input
I have tried to use Svejk's implementation to see if I can learn any code enhancements from that. It doesn't seem to work very well, unless I'm missing something that makes it dead-important that it runs on a 28X2 and not a 40X2, and the mammoth-themed software from his website won't download the data (I have downloaded both programs onto the chip) and the sample code which runs on the 08M gets it to fill the screen with whiteness and then does some other things until it gets to this:A complete 28x2 implementation for driving GLCD may be found at glcd.svejklabs.cz.cc.
The application includes dot, line, box, circle, image and customizable fonts. Have a look.
Sounds likely.It doesn't seem to work very well, unless I'm missing something ...
Good luck, I'm sure you'll get there...I better just go back to making development on my own.
Has anybody apart from Svejk managed to get his GLCD driver to work? That'll confirm whether I've built it correctly. I cannot see how it would do that due to an electrical error and is probably because the software doesn't work. I have no idea how to convert the bitmap into anything else using Visual Studio like Svejk does so the software could possibly be used if I decide to add an EEPROM to mine, so hopefully it's a problem with the PICAXE program he wrote....Sounds likely.nick12ab said:It doesn't seem to work very well, unless I'm missing something
I do have an EEPROM and it was attached but the software from your website won't see the PICAXE. It is still the normal programming pins used by the software, right?
A different 40X2 made no difference at 40MHz. But as this other 40X2 was the universal voltage version, I could safely use a 16MHz resonator instead of 10MHz and change the hsersetup command in the code accordingly and it now works without any corruption.Until then, I'll remove a good 40X2 from a working project to check whether it's a bad 40X2 causing the serial problem.
#picaxe 40x2
#terminal 9600
w0 = B19200_40
sertxd (w0,13,10)
reset
Will the phase of moon really affect it or is that just a joke?, in some situations (temperature, external circuitry, length of wires, bodgit wiring/decent wiring, non-common grounds, phase of moon etc), after some time (straight away, after 30 mins, after 2 days) don't do perfect serial comms...
...and neither will most (all?) 8-bit PICs or AVRs operating on their internal oscillators.
If you want reliable comms use a crystal plus two caps (preferred if you want ultimate accuracy - a few tens of parts per million frequency accuracy) or a resonator (maybe around 0.5% frequency accuracy).
The EEPROM test program is one that I made myself. It isn't very good for testing EEPROMs as although it clears and sets all bits for each byte before restoring the original value, it doesn't check inbetween, so stuck bits would pass undetected and the EEPROM would have to fail during the test for it to be detected. It is still ideal as a test for sending lots of data to the GLCD. I'll upload the 20X2 and 18M2 versions.I can't explain why a resonator based PICAXE drifts sufficiently to corrupt serial comms though - it's certainly not normal and there is probably some external effect. I doubt you've uncovered a fundamental error in any PICAXE firmware. What EEPROM test program?
//
Sub PlotPictureNeg() ' Plots the image inverse (ie negative)
XPos = 0
YPos = 7
GWord = 2
GCommand = DByte(1)
For I = 7 To 0 Step -1 ' 64 lines = 8 charcater lines
For X2 = 0 To 15 ' Loop to get 8x8 cell . 15 is a linesworth.
For X1 = 0 To 7 ' Generate cell byte (a vertical byte)
CellByte.7 = GByte(GWord) <<X1 >>7 ' Pick out bit 7,6,5,4,3,2,1,0
CellByte.6 = GByte(GWord+16) <<X1 >>7
CellByte.5 = GByte(GWord+32) <<X1 >>7
CellByte.4 = GByte(GWord+48) <<X1 >>7
CellByte.3 = GByte(GWord+64) <<X1 >>7
CellByte.2 = GByte(GWord+80) <<X1 >>7
CellByte.1 = GByte(GWord+96) <<X1 >>7
CellByte.0 = GByte(GWord+112) <<X1 >>7
Pos.x = XPos // GLCD x pos
Pos.y = YPos // GLCD y pos
Inc(XPos)
Next 'Vertical byte
Inc(GWord) ' Next group of image bytes
Next 'X2
Dec(YPos)
XPos = 0 ' Set X back to start of line
Inc(GWord,112) ' Next block up
Next
End Sub
//
Which sort of BASIC? For the PICAXE or computer? If computer, is it Visual Basic, Visual BAsic .NET or something else?Here is something I've knocked up for you in BASIC.
I have started an experiment with the microcontroller sending lots of data to the PC instead of the GLCD. To make the test fair, I'm using the same EEPROM testing program so I'll report back when it's finished.Remember both ends of the comms link must be running at an accurate frequency - so if you have both ends running on inaccurate timing mechanisms you have double the trouble. What happens if you get your PICAXE to send everything to your PC for hours on end instead of the GLCD?
Phase of the moon affecting serial comms - what do you think?
Hmm?Phase of moon doesn't affect serial comms as otherwise PICAXE programs will only be downloadable on certain days of the month.
So far the test is running fine so it would appear the moon has no effect. I put location as x because I'm not giving away where I live unless I have to, but it's in the UK.Hmm?
Look at what happened between your posts 61 and 62.
There was a full Moon in the UK. (15 06)
Mind though, you live in x
so perhaps the Moon doesn't reach you?
exits making Milligany "wwooo " noises.
e
So why be obscurantist?So far the test is running fine so it would appear the moon has no effect. I put location as x because I'm not giving away where I live unless I have to, but it's in the UK.
Excellent idea. I'll do that now.So why be obscurantist?
Just put
UK
in your profile.
e