Browsing Posts tagged electronics

Adding memory? I forgot. 16/04/13

You’d have thought that with all this learning and fun stuff happening here at Wardian Towers, that as I get further and further into this electronic ‘lark’, first with PIC’s, then I2C, then real time clock counters, then I2C input/output devices, then into iButtons and all the wonders they produce; you’d have thought that it would get easier as time went on.

Scientists do say that the brain is in fact like a giant muscle, and that the more you use it, the easier it gets as it becomes more familiar with cramming it with yet more and more knowledge.

Well, I can report that from this end, it most certainly doesn’t seem to.Before...

But then again, I guess I’m not as young as I used to be, and maybe doing this kind of stuff is really for the twenty-somethings.

But then again, if I was twenty-something again, I’d be either playing on my X-Box, or drooling over a new Porsche, or Armani suit.  BUT, I’ve been there.  Got the T-shirt; read the book.  Boring.  Shallow.

Whatever.

To the right here is the board before I fitted the new memory chip.  The chip itself is a Microchip device called a ’24FC512′.  This denotes it’s from the ’24’ series of serial EEPROM (Electrically Erasable Programmable Read Only Memory) chips, and it will store up to 512 K bits of information.  Note the ‘bits’ bit.  In more user-friendly language, it will store up to 64 K Bytes of 8-bit words. (As we all know, there are 8 bits to a byte.)

The datasheet tells me that I can have up to four of these little guys sat on the same I2C lines, each individually addressable, so I could have up to 256K bytes of information storage on just four chips.

Frightening.

Hooking the thing up was ridiculously easy, and took a matter of minutes -I just had to remember to wire the SDA (data) and SCL (clock) lines properly.  Mix them up and all kinds of exciting and unexpected stuff would happen....After

There’s also a pin which you can either wire up, or even have sat on another output pin from the PIC.  This pin is the ‘Write Protect’ pin.  With it sat at 5-volts, you can read the contents of the chip, but it won’t let you write, while tying the pin to ground gives you unfettered access to everything.  This is a pretty useful feature, and I may well use it if I get the opportunity.

And here is the chip in circuit.  As I said, ridiculously easy to wire up, and you can barely notice any other new components.  They’re there, though.

And so to programming it.

And this is where all the ‘fun‘ started.

I set up an entirely new project in the X-IDE program I use from Microchip so as not to contaminate the other stuff I’ve written.  Okay, doing it this way may take longer, but it gives you a ‘fresh canvas’ to work on, and it prevents great lumps of code being sat in the program for other functions that you will never use in this.  It also focuses the mind on just what you really need in there to get the program running.

For this program, I needed the new RS232 program I’d written the other day so I could actually see in a box on the screen what the processor was putting into the RAM and also what was coming off the RAM.  Yes, I could have done it with simple LED’s already sat on the board, but that would have been pratty.

After several hours, many cups of tea, and of course, ‘consultation chats’ with young Alfie (…He’s a bit ropy on I2C, but learning fast…), I finally nailed it when I realised that you never use the ‘Acknowledge’ pulse when you’re writing to the device, but when you read from it, you must acknowledge every byte apart from the last one where you send a ‘NotAcknowledge’ pulse.

Oh, and to be on the safe side, you need plenty of ‘IdleI2C()’s thrown around, just for good measure.

Again, last night was another late one, but I can report total success.

I can now write data to this chip, switch the whole thing off, have a cup of tea, switch it all back on, and the data is still exactly as I wrote it.

Today, I have other, much less fun stuff to do, and of course Wednesday and Thursday are ‘Plotting’ days.

But I shall return soon to this project -hopefully before I forget everything I’ve done.

Unlike the RAM I’ve just fitted and programmed, unfortunately, I do forget stuff when switched ‘off’.

 

The lightest of touches 15/04/13

When I wrote that last piece about the iButtons, yes, I’d got the iButton to display its unique serial number on the PC screen. I did this using an RS232 link to my PC using a free program called PuTTY which emulates the old ‘Hyperterminal’, not found on Windows 7.  This was no mean feat -I’d never programmed a PIC for RS232, so it was new territory all round.

Yes, the PC would display the list of numbers, but the problem was, it would only do it occasionally!Before...

By its very nature, 1-wire communications with the iButton is shaky, even at the best of times, so getting the thing to display the proper numbers consistently was something of a challenge.

In the end, I had to read seemingly thousands of pages of dry-as-a-bone documentation, both from Microchip (the makers of the PIC processor) and from Dallas Semiconductors (the makers of the iButton).

A very long and very boring story later, and very late last night, I finally cracked it.

Initially, the PC would read the correct number maybe only once in thirty button touches.  Now, it’ll do it between eight and nine times out of ten.  Okay, still not ‘production’ quality, and I’m sure I can improve it further, but you’ll agree, it’s a Big Lot better.

Up to the right here is my board.  You’ll remember the ‘flying board’ of the I2C real time clock sat there on its piece of card, attached with gaffer tape. The iButton is the red thing at the side, while the iButton reader is to the left of that, joined by its two wires....and after.

To the left here is the same board, but this is after I’d gently touched the iButton to the reader, and you can see the white LED towards the back of the board, lit to show that the button has been recognised.

I’ve also programmed it such that different iButtons will light different LED’s, while tapping an ‘unknown’ iButton illicts no response whatsoever.

So, we can safely say that this is now a ‘Job Done’.  iButtons are now recognised, and more importantly, different iButtons produce different responses, while ‘new’ iButtons, until programmed in, aren’t recognised at all.The result!

To the right here is a pretty poor picture of what the screen says when a valid iButton is touched to the reader.  Pretty neat, eh?  And yes, the black ear behind the box on the screen is that of my cat, Alfie.

And the next job, Wardo?

Aaaaah…

That’ll be the I2C non-volatile RAM I mentioned seemingly weeks ago.

With this in circuit, I’ll be able to record, using the RTCC clock for reference, just when an iButton was touched to the system, and it won’t ‘forget’ once the power is turned off.

And after that?

Ah, Dear Reader, therein lies the ‘challenge’.  After that, I plan to design and build a monitoring circuit that will measure -and record- battery usage as the unit is working.  This board will be a ‘hybrid’ board, combining both digital circuits with an analogue ‘front-end’ that will monitor the currents going both into and out of the battery, but it will also ‘time-slice’ this data into usable ‘chunks’ with an integrator.  It is this integrator that has proved most troublesome, but thanks to the excellent ‘Khan Academy‘, a free Internet maths revision site, I think I’ve got it cracked.

Tie this to iButton usage, and I’ll have a permanent record of just who was using the bike, when they were on it, and most importantly, how much juice they put into the battery.

This data could then be used as the basis for the strict rationing of the ever-popular LEAF chocolate biscuits!

No, seriously, this could have a profound effect on how we might approach possible funders, and on what basis we apply for the ever-shrinking pot of public monies.

But to be honest, I’m not thinking quite that far ahead just yet.

One problem at a time, and the current problem is the non-volatile (NV) RAM.

Then I’ll look at the challenge of power monitoring.

All clean, healthy fun.

iButton madness

For those of you not in the know, an iButton, funnily enough, is not from those wonderful boys and girls who make the phones, computers, and seemingly everything else ‘i…’.

The iButton is actually made by Dallas Semiconductors.  If you’ve ever been in a bar, then odds-on, the barperson would have had one of these little things that they simply touch to the till to identify them as your server.  Yeah?

Right.

Well, Dear Reader, I’ve known about iButtons for years -we used them in the electronics department at Sheffield University for access control into areas that undergraduates are normally not allowed.

They’re dead cute, and can fit on any keyring.

But, the best thing about them is that each one is unique.  They have a laser-imprinted 64-bit serial number that is impossible to fake or hack (…they’ve tried, believe me…), so when you touch your iButton onto the piece of gear, it checks from a list of known users, and as nightclub bouncers are so fond of saying- ‘If your name’s not on the list, you’re not coming in!’

Same kind of thing, but without the badly-fitting suits or tattoos.

Well, to be honest, like the dreaded (no longer!) I2C that I mentioned previously, iButtons were things that I’d kind of been putting off for years.  In reality, they’re pretty difficult to program for, because everything is so dependent on timings and all other kinds of fun stuff.

The thing is, for the electric bikes to move forward, I needed a simple system -like an iButton- that regular riders could simply tap onto the top of the box, and it would instantly know who they were.  iButtons seemed ideal, but as I said, they’re a real drag to get right.

Well no longer!

Just a few minutes ago, with the help of my trusty feline (?!?), I finally cracked it.

As young Alfie so kindly reminded me from his position on my knee, the reason it wasn’t reading was that I hadn’t unset the bloody analogue inputs from PORTA, so it wasn’t reading it properly.

Well, now it is!

Now, the long-suffering Mr Ward Senior will not be around for our regular Sunday brunch tomorrow morning, so I’ve got all day to get the program working as I want.  Little things like the unit sensing when an iButton has been touched, interrupting what it’s doing, then reading the number from it.

Then I can program in the list of my six iButtons, so it will know exactly which one has been touched, and give an appropriate message.

All tremendously good fun, and it keeps me off the streets.

Oh, and there’ll be a ‘regular’ LEAF blog entry up first thing in the morning after I’ve processed all the photos and thought of just what to write.

From flashing LED’s…

No photos tonight, I’m afraid.  The camera battery is flat, and anyway, in this light, they probably wouldn’t have come out.

So you’re going to have to take my word for this…

After long, long hours of head scratching, and moments of seeming madness, I’ve finally cracked this i2c lark.

Saturday’s missive was all about how I’d managed to write data down the i2c bus.

As it turns out, this was the easy part.  Apparently, even my cat could have done it, if he’d been bothered.

Getting i2c to receive coherently and on time is apparently quite a big beef amongst the electronics fraternity, and Microchip -the makers of the PIC’s I’m using, haven’t done themselves many favours. Briefly, the way they’ve implemented it is, well, decidedly pratty.

A very long and boring story shorter, but just suffice to say I’ve now got the little board you saw on Saturday not only flashing the LED’s if I want to, but I’ve whacked on an RTCC (Real Time Clock Counter) onto the i2c bus too.

The input/output chip and the clock are quite happily sat on the same two lines (SCL and SDA if you’re that bothered), because they have different i2c addresses.  Before you talk to a chip, you have to give it the right address, which kind of makes sense.

SO, I’ve now got that same board, and you’ll remember it has those four displays left over on it.  Well, these are now coded up so the display simply reads minutes and seconds from the RTCC.  I haven’t set the clock properly, so the numbers are pretty meaningless, but the fact is that even if I completely unplug the board to switch it off, this little clock keeps on ticking -in much the same way as your PC clocks does when you power it down at night.

So, when I come to switch it on again, not only has the clock advanced, but it’s advanced properly to show the correct minutes and seconds that it was when it was on previously.

I guess I’m not explaining this very well, I guess I’m a little tired, but I’ll get some proper photos tomorrow to explain.

Hells, I may even set the clock properly so it shows the correct time!

The next job will be to work with that little input/output chip to get it to input, rather than simply lighting LED’s.

This shouldn’t be quite as difficult as today’s marathon effort, but I have the added ‘fun factor’ of having to set it up so that a button press will interrupt the processor.  This will then send out a command to find out just which button was pressed.

Why?

Well, this vastly saves on processor time.  Rather than the processor having to ‘poll’ the inputs every few milliseconds, and all the bother that entails, this way, it’ll only do something when it’s interrupted.

There’s even a possibility of being able to ‘wake’ the processor from ‘sleep mode’ with a button press.  This then does away with a whopping great on/off switch -it’ll just be a button press to turn on.  …Maybe, we’ll see…

I guess it all sounds dead simple, but take it from me -it’s not!

This is One Tired Wardo, signing off!

Second Box? Collected!

Yesterday, Phil from Trade Base came over to pick up his shiny new Electric Bike Box from us.

Okay, so it’s only months late, but as he himself admitted, they didn’t have anywhere secure to store it until a few days ago.

In the meantime, I’m working on the mkII version of ‘The Box’.

This version does away with all the confusing 7-segment displays, and makes do with a single larger LCD display.  At the touch of a button, this will show what the rider needs to know, but more importantly, because the display unit is almost self-contained, it relieves the main processor of all the work of updating all 20 7-segment displays.  All this unit needs are four wires to connect it to the processor -all the communications are handled serially via I2C.

I’ve also got a ‘Real Time Clock Counter’ on order from eBay as well.  This will mean the unit knows what time it is, and even what day of the year it is.  Again, this communicates via I2C.

If, like me, you’re of the ‘Propellor Head’ persuasion, you’ll find this pretty exciting.

More news as it happens…

Second Box? Done! 02/02/13

Yes, yes, yes, I know, Dear Reader.  You’re about to faint.

But it is true.  The second box for TradeBase is actually finished.  What isn’t finished is the A-frame bit that the bike sits in.

But I will finish it, come Hell or high water.  It only needs the wheel sensor whacking on, and if I get a clear run at it (HA!), it’ll only take me a morning or an afternoon.

This second box now has much brighter LED’s than the original ‘demo’ box -bright enough to be easily visible even in direct sunshine.  And it only took another 16 transistors and 30 resistors on one board to achieve this.  Piece of cake!

Other news is that since Ian (no relation) gave me that little TV with the HDMI input socket, I’ve been ‘playing’ with the Raspberry Pi, and having a Big Lot of fun in the process.

I ordered a tiny little ‘wireless dongle’ for it -so I can use it on the Internet at home running wirelessly from my router. This really was a little swine to get going, and it took me a full half-day to get there, but it’s now working fine and very fast when you consider it’s a full computer the size of a credit card for less than £30.00.

“So what?” you quite rightly shout.

Ah, I actually plan to have a Pi down on The Plots in the top shed.  Because it’s so small, I can easily hide it away -probably behind somewhere or even under something, so any potential thieves won’t be able to find it.

I may take an old, empty PC case, and put that in there, complete with a couple of bricks in the bottom.  A scabby old 14″ CRT monitor (…which won’t work…), and a knackered keyboard and mouse will finish off my ‘stage set’.  If any thieves do break in, they see these, and take them.

I can imagine them picking up the empty PC case (…plus two bricks), and saying to each other;-

“Eh, Wayne!  Feel the weight of this!  Must cost a fortune, one of these!”

Ha!  Wait ’til they get it all home and try to plug it in.

Okay, an idle, but very fun thought…

The parts have arrived! 17/12/11

FINALLY!

This morning my smiling postman delivered four more PIC16F876A’s and two opto-sensors.

The PIC’s are for the circuit boards (…I only had one, so making two talk with each other was more than a little difficult…), and the opto-sensors are for the generator.

I plan to have a disc with a couple of holes in connected to the main generator drive wheel that the back wheel of the bike runs on.

These sensors will provide interrupts to the PIC to show that the wheels are moving.  By doing it this way, it means there’s no need to modify a bike to fit an infra red sensor and it will mean that unlike the bike computers you fit to your own bike, there’ll be no need to input the wheel diameter.  Instead, it will measure the speed of the generator and therefore the ‘speed of travel’ of the bike.

Confused?

Don’t worry, it’s all been properly thought through.

SO, that means I can get changed into my ‘outdoor gear’ and go straight over to The Plots, hopefully for a hard day’s digging.

Being sat at a bench all day writing code and building circuits while eating the Co-Op’s finest donuts is great for the mind (…though not for the waistline, unfortunately…), but digging is good for the soul.

Of course, the promise of Mitzi to cuddle, gallons of Plot Tea to drink in the weak winter sunshine kind of helps too.

Another PIC board built. 16/12/11

Wednesday afternoon then yesterday, I built another little PIC board based on the PIC16F876A with just two display units on -this gives four digits of 0-9.

The difference with this board is that as I want to use it for I2C communications, I couldn’t use PORTC3 or PORTC4 because they are used by the I2C for SDA and SCL -that’s serial data and clock.

I therefore had to use two separate pins to power the ‘d’ and ‘e’ segments of the displays.

This wasn’t quite as easy as it sounds, but after a couple of hours re-learning about bit-shifts and the like, I got it fully working -it would count from 0 to 9 quite happily.

Then, I went back to my original board and modified that so I could free up those two lines.

Anyway, long story short and all that; now both boards are wired in the new configuration and both working well.

Now, I’m hoping that Farnell will deliver me some parts today.  I ordered some more 16F876A’s and a couple of infrared sensors on Wednesday and expected them yesterday, but as I had to go out to pick up some ink cartridges for Diane yesterday morning, I think I missed the delivery guy.  I need the 16F876A’s because I’ve only got one.  Trying to make two processors chat when you’ve only got one of them is somewhat difficult!

Anyway, as soon as the new 16F876A’s arrive, I’ll be able to put one in the other board, wire up for I2C then the fun will really begin as I get the two of them talking.

I know.  I haven’t explained this at all well, but please bear with me.

Its still early!

Soaking it up. 14/12/11

I left the board plugged in and switched on last night to give it a few hours soak testing.

And it all passed with flying colours.And counting.

To the right you can see it this morning, and it shows its been on for 10 hours, 39 minutes and 52 seconds.

What you can’t see is the dot between the ‘9’ and the ‘5’ which flashes briefly every second as the seconds count up.

Up at the top right, you can see the ’00’ of the speed indicators, which obviously is zero because I’m not on the bike pedaling!

Actually, I need to change a little of the code for doing the speed because it tends to ‘bounce’ as your speed varies, but a little tweak and it will be perfectly readable.

“So, Wardo,” someone shouts. “What’s the plan for today?”

Today I have to go down to good old Maplin’s to pick up yet more bits, and as I ordered them online last night after they’d shut, I expect a call very soon after 9.00.  And yes, now they’re starting to get their stock under control, I checked online, and they have everything in stock.

And talking of stock, yesterday I became the first person in Sheffield to buy Maplin’s entire stock of two different parts from both their Sheffield stores.  I pity anyone else who wanted BC547’s or those cute little 7-segment displays!

Today will be for some 32.768KHz crystals for the embedded RTC’s (Real Time Clock), some little 22pf and 33pf capacitors for running the main PIC clocks and some 330R resistors that drive the anodes of the display LED’s.  I may well see if they have any off-cuts of veroboard because I’m running a little low on that as well.

In other news, I spoke with Sheffield’s Best Electronic Engineer the other day -when I was waiting for that Farnell order to see what time they were likely to tip up (…just after I’d put down the phone!), and due to a mix up, he has a spare soldering iron he had to buy in an emergency because he couldn’t get a part for his Weller iron.

He said I could have it for Christmas!

Okay, its not a Weller, but it’ll be a whole lot better than the little Antex I’m using, and I’m going round to pick it up early next week, so HUGE thanks are in order to him for this.

Anyway, I’d better get in gear.  Much to do today.

14 seconds. 13/12/11

That’s how much the timing circuit gains in one hour.

Now, the purists out there would say I have to correct this, but at this time I really want to crack on with other, more exciting stuff -like getting two PIC’s to chat to each other via the I2C communications I’ve been talking about for the last few days.

Anyway, I’ve now got the bottom six digits showing seconds, minutes and hours as it should. And yes, its showing it in the right format -the seconds and minutes roll over at sixty as they should.

This only took a matter of minutes in ‘C’!  If I’d tried to do this in assembler, it would have taken forever to write and debug.

So, its down to Maplin’s to buy their entire stock of FA02C green segment displays (7) along with their entire stock of BC547C’s (…Er. One…)

More pictures later.


SEO Powered By SEOPressor