Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reading a 4x4 switch matrix

Status
Not open for further replies.
Dan,
Good comparison of Swordfish to C. Any idea on the compiled code sizes?

Mike.
 
The pc board s basically designed with an added transistor and resistors as needed if they are needed.
Plan to purchase the LCD in quantity of 10, test on a perfboard then compare the component patterns before ordering boards.
The boards will have two patterns for the two resistors (base and collector-LCD backlight. The transistor to be included IF needed.
pic of schematic2.jpg
 
Good comparison of Swordfish to C. Any idea on the compiled code sizes?
I cannot tell without recreating my project in SwordfishSE BASIC, but using a hacked version of MrDEB's code it may build a HEX file smaller than the free version of XC8 does.

Perhaps you would like to translate my C project in to a SwordfishSE BASIC project?
 
It's my understanding that Swordfish creates pretty tight, efficient code. It does work well for some large scsle projects for me. Don't let MrDEB's ineptitude with Swordfish serve as a reflection on its quality and functionality.

MrDEB, your schematics are at least legible now, but they are utterly indecipherable. A bus isn't really meant to collect every signal, power, ground and anything else and lump everything together.
 
Unfortunately Dan, I don't possess Swordfish but did dabble with it in the past. It is very impressive.

Mike.
 
Let's try to add some worthwhile content for those playing along at home. Powerstream has tested AA batteries under various loads and has come up with this plot for AA cells discharged with a 100mA load.

AA-100mA.png

With a 100mA load, the tested cells provide a little over 2000mAH of energy. These cells would provide about 20 hours of service with a 100mA load:

2000mAH / 100mA = 20 hours.

Battery capacity isn't a constant. If we drain the battery more slowly, ot will deliver more total energy; if we drain the battery at a higher rate, it will deliver less total energy. At the above link, they shows batteries drained at 500mA will deliver only about 1200mAH instead of the 2000mAH when the drain is 100mA.

So the bigger the drain, our run time suffers in two ways: there's less total energy available to start with and we're using what energy there is more quickly. If we drain the batteries more slowly, we get the double bonus of more energy available from the battery to start with and we're using it more slowly. There are similar battery discharge curves at Digital-DIY by yours truly. There may be some at even lower current draw than 100mA.

Power Budget

So what's this mean for MrDEB? We need to look at all the loads in his circuit to estimate how long it may run. Let me continue in another post shortly. Stay tuned for part 2!
 
Continuing with the power budget, How much current does the 18F25k20 draw? The short answer is, it depends.

If MrDEB saves his pennies on a crystal and uses the internal oscillator, table 26-3 from the data sheet says the maximum current draw when operating at 16MHz is 4.4mA. Dropping the clock speed to 1MHz drops the current draw to 0.8mA.

But if he doesn't save his pennies and uses a crystal, those numbers drop to 2mA and 0.4mA according to table 26.4.

It is possible to reduce the microcontroller current draw to micro amps by operating it at 32kHz, but I don't think such heroics are necessary here.

So let's call it 4.4mA for the micro.


Next in the circuit are 5 pullup resistors and the pot for LCD contrast control. Lets say they are 10k each.

V = IR --> I = V/R = 3.3/10k = 0.33mA each or 2mA total pullup resistors.


Next, something we can control - the LED current. Let's say we want them fairly bright so a current of 10mA each and an average of 2 on at a time. That's 20mA total.

Let's see where we're at so far.

  • micro: 4,4mA
  • pullups: 2mA
  • LEDs: 20mA
Total current draw, not considering the LCD: 26.4mA

The batteries provide about 2000mAH of energy, so

2000mAH / 26.4mA = 75 hours of run time. It will actually be a bit longer than this because of the increased cell capacity at a lower current drain. Is that long enough? The LEDs are the most controllable load so balance visibility vs time.

What happens when you add the LCD? Figure it out in the same way.


And by the way, before you say "but I have 3 batteries, so it's 3x longer", no, it's not. The cells are in series. They all experience the same current drain and energy usage.
 
Perhaps you would like to translate my C project in to a SwordfishSE BASIC project?
Here's a rough version that should compile with SwordfishSE... didn't do much other than compile it, so it likely needs some tweaks here and there to run.

For an 18F2520 it compiles to 1553 bytes program, 52 bytes ram.

When you look at all of the code, Swordfish BASIC has more than twice the number of lines of code
FWIW, the port of the C code has the following SLOC:
Code:
main.bas    116
lcd.bas     373
keypad.bas  268
tick.bas     25  
bitdefs.bas  31
total       813 lines
If you ask me, counting lines of source code is an almost meaningless statistic.
 

Attachments

  • 18F2520_LCD_4x4keypad.zip
    8.6 KB · Views: 238
Last edited:
Very interesting and concise Jon
A crystal would be a nice addition but I am not putting in an enclosure BUT!! will include a crystal on the schematic so a crystal could be added at a later date if I put project in an enclosure and use a smaller footprint pic. maybe. Thanks for the info.
 
.....A crystal would be a nice addition but I am not putting in an enclosure BUT!! will include a crystal on the schematic so a crystal could be added at a later date if I put project in an enclosure and use a smaller footprint pic. maybe.....


The sun is shining so bacon Ford comma.

I sure you had something in mind when you typed the above, but my sentence mskes just as much sense. Want to try again without the word salad?
 
Jon he means those crystals pic up the radio waves the Gov send out to control you!! unless you put the project in a box then they have control of your mind!!

or he is on about the copper earth ring people less lazy than me use on boards with crystals, OR maybe he is on about a healing crystal:stop:.

Mr Deb are you going to sell these? Why buy 10 Lcd's.....
Only page 5 we got loads to go yet!
 
this is a protptype, contemplating addingin where up to ten players can enter their score so only one calculator is needed for up to ten players.
be nice to sell these?
 
So does each person get a LCD when they play? If not then why 10 LCD's?

I cant see much of a market for them TBH, only you can answer that. What has been your best selling board so far? Maybe half the number of that to get an idea.
 
I have sold 8 of my Mexican Train boards to date.
The calculator is to make it easier to count up ones score. If I have the calculator with the ability to keep track of 10 players then only one board is needed BUT with only one calculator it makes it time consuming to enter every ones score.
If you have never played Mexican Train then maybe you should play it some time. NOTE it takes about 4 hours to play one full game using the double 12 dominoes.
My next game board which Elecrow has shipped has two similar games Mexican Train and a version I came up with called Bullet Train which is a faster version of Mexican Train. We play Mexican Train 2x a month here in town (a 55+ community).
 
Here's a rough version that should compile with SwordfishSE... didn't do much other than compile it, so it likely needs some tweaks here and there to run.
tumbleweed,
You did an execlent job porting my code and after fixing a couple of thing you could not know abouit it runs in my prototype.

The Swordfish BASIC project compiles to 1555 program bytes and 51 variable bytes.
The Swordfish BASIC project compiles to 1649 program bytes and 86 variable bytes.
The Microchip free XC8 project compiles to 1849 program bytes and 71 variable bytes.

Remember that the XC8 compiler is not doing any code optimization.

<EDIT>
I needed to revise the Swordfish BASIC numbers because the port did not allocate a 17 character buffer or invoke the LCD_WriteString() function that the XC8 project does.
 
Last edited:
Remember that the XC8 compiler is not doing any code optimization.
It's worse than that. It adds bloat code to try to sell it's compilers. Try looking at a disassembly and it's fairly obvious. Storing inter operation results in memory for no reason at all.

Mike.
 
Swordfish is still king on 18 f chips I'm going to use the xc8 pay as go thing figure I'd try it out. But just a led blinky on xc8 is way bigger then swordfish on the same chip 18f1220
 
Swordfish is still king on 18 f chips I'm going to use the xc8 pay as go thing figure I'd try it out. But just a led blinky on xc8 is way bigger then swordfish on the same chip 18f1220
I have the HI-TECH PICC18 compiler in PRO mode. It can build the same projects as XC8.
The HI-TECH PICC18 PRO project compiles to 1495 program bytes and 52 variable bytes.

Now that tumbleweed did a port to Swordfish BASIC what do you think the chances are that MrDEB will try this code?

Admittedly the chances are low in that the code supports a circuit diagram other than his.
 
Last edited:
Thats great I liked HI-TECH better then xc8 it had more to start with. But I think xc8 is good tho just i'm not that good with C I have a full copy of swordfish its
really good with the 18f chips mainly cause it's basic and i'm better at using basic.
 
Thats great I liked HI-TECH better then xc8 it had more to start with. But I think xc8 is good tho just i'm not that good with C I have a full copy of swordfish its
really good with the 18f chips mainly cause it's basic and i'm better at using basic.
I'm not sure whats going on here.... XC8 is hitech.. Just rebadged.

XC.h just calls HTC.h
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top