PIC ATMEL ZILOG EXPERIMENTORS BOARD PROJECTS

In this section you'll find lots (I hope lots) of interesting things to do with electronics (my primary interest).

I've spent a good portion of my life working as an electronic design engineer and a good portion as an electrical
design engineer (control systems). I even worked on one of Canada's major projects: The Hibernia oil drilling platform.
Fortunately it was on the pier at the time so I didn't have to go to sea. I spent a total of eight weeks in Newfoundland
working on matching the generator control program I wrote with the rig's PLC systems. Damn fun.

Still, I digress. On to the electronics!

I don't normally like the PIC microcontroller as it has some quirks that I'm not overly fond of and have
bit me in the backside before now. However, I've used quite a few of them now and every rear-end-bite
is sorely remembered for the next time. Here are some programmers available.
I don't have a PICSTART+ at home. I would like one, though, but I can't justify the cost
given that I do so little at home (not surprising given I do it for my job).

Velleman

Ah, the good ol' Velleman kit. Available direct from Velleman or Maplin Electronics. This kit uses an RS232 interface to program PIC microcontrollers. It's a bit limited in that it will only program PICs up to 28-pin. Still, more than enough for most people.

It does have some buttons and leds for you to play with - should you feel so inclined. Great for people starting out with PICs.

This is Microchip's own little programmer. Another great one for getting started with. Has some leds, wired a little strangely so not overly useful, a little potentiometer so you can play around with analogue to digital conversion and a dinky little pushbutton, too.

This one runs from USB and is also powered by the USB bus. Pretty cool! Can program 8, 14 and 28-pin devices. 12F's and 16F's but not the 18F's. Still great for messing with.

PICKIT

From a programming point of view I always used to use MPLAB, Microchip's own IDE and assembler. I'd thought about 'C' but the compilers were always so expensive... until... I bumped into a downloadable demo of SourceBoost C. What a fantastic program! It even has a bit data type for flags and the like. I found it very impressive. I've got the commercial version at work and it was less then £90. At home I have the non-commercial version which is available from Maplin (retail outlet) or Farnell. Maplin sell the Standard edition for £19.99 and the Full edition for £46.94, both non-commercial. Farnell sells the full commercial version. Trust me, it's excellent. Grab the demo and see for yourself. I love programming PIC's in 'C', makes life a lot easier, especially if it's the design you enjoy more. Oh, debugging, a dream in 'C'.

How about an example or two?

The ubiquitous #include statement. No need to tell it the PIC used as you do that in the Project settings.

#include <system.h>

Configuration bit settings for the PIC. For configuration bits you really need to look in the include file for the appropriate PIC as the spelling is not always the same between chips (or available).

#pragma DATA 0x2007, _CP_OFF & _WDT_OFF & _BODEN_ON &
_PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF


Set the clock frequency so SourceBoost knows how to work the delay functions.

#pragma CLOCK_FREQ 4000000

Ahhh, the juicy BIT data type, very handy. Why the bigger compiler companies shy away from this I don't know. They say it is no longer portable between manufacturers but let's face it, how handy is this. They need to remember that this is for a microcontroller and microcontrollers deal with the world on a bit basis over and over again, soooo, give us the BIT data type.

What follows is a description of the 'volatile bit'. This is used for I/O pins. Because the I/O pin can change state independently of the program, the program needs to know this, to know that what it set a minute ago is not necessarily what is set now.

Note that writing to PORTC is normally as straight forward as portc = 0; But notice that below PORTC is in capitals. There's a reason for this and you need to take my word for it. Well, discuss this in the next code group below this one as it's easier to do. But, before I forget where I was, note that LowVoltInd@PORTC.0; actually gives bit address of PORTC.0. Soooo, you can now say:
LowVoltInd = 1; This will turn the output RC0 on. LowVoltInd = 0; will turn it off.
Same if it's an input: if(SomeInput == 1) DoSomething;

The long winded way is: set_bit(portc,LowVoltInd); and for reading if(test_bit(portc,SomeInput)) etc.

// Ports.

volatile bit LowVoltInd@PORTC.0;
volatile bit MainsFailInd@PORTC.1;
volatile bit SysOkInd@PORTC.2;
volatile bit BMS_Down@PORTC.3;
volatile bit mul@PORTC.4;
volatile bit mur@PORTC.5;
volatile bit mll@PORTC.6;
volatile bit mlr@PORTC.7;

The following code is where SourceBoost makes it interesting. You want a flag register? Then stick in the line below. There's a reason for this, by the way. If you have a lot of flags you don't want to waste a line of code clearing each individual flag. If you only have a few flags I'll show you the less cumbersome way a little later.
By using the @0x20 you fix 'flags' at address 20h (bottom of user ram.

char flag1@0x20;

Now, if you wish to use the kind of addressing above, you need to lock your flags down to where you want them. However, SourceBoost will NOT accept bit CurtainUp@flag1.0; it just won't, it refuses, it chucks it out as an error. I don't fully understand why but I do know that you have to define the flag1 register and make it separate, capitalising it will do, as the line below.

#define FLAG1 0x20

Now you can do the thing below. You can deal with your bits and know where they are and you can clear the flag1 register as easily as flag1 = 0; That saves you having to clear every individual little flag at the start of your program. This lets you do things like CurtainUp = 1; and MainsFlag = 0; etc.

bit CurtainUp@FLAG1.0;
bit CurtainDown@FLAG1.1;
bit Override@FLAG1.2;
bit Blink@FLAG1.3;
bit BlinkX2@FLAG1.4;
bit MainsFlag@FLAG1.5;
bit ClosingCurtain@FLAG1.6;
bit ObTimeout@FLAG1.7;

The other way, if you just have a couple of flags is:

bit CurtainUp;
bit CurtainDown;
bit TimeOut;

This is a cool way of doing things if you don't mind clearing each flag line by line. However, with this method you don't actually know where the compiler has stuffed your bits. But then, you don't need to, the compiler knows and that's all that's needed. Now to the next bit.

The bits of code below just set up prototypes for any functions you are going to create later. Nothing to sweat about.

// Prototypes.

void MotorUp(void);
void MotorDown(void);
void RetractUp(void);
void GetADC(void);

I'm not going to explain the next bit but you can have a look at how SourceBoost C makes coding a lot easier. Oh, I should point out that the code generated is not much longer, if at all, than code you would do in assembler. Here's the snippet:

// MAIN PROGRAM.

void main()
{

// Register set-up.

intcon = 0;
adcon1 = 6;
option_reg = 0b10000111;
clear_bit(adcon0,ADON);

// Set up ports.

porta = 0;
portb = 0;
portc = 0;

trisa = 0b00110000;
trisb = 0b11111111;
trisc = 0b00000000;

flag1 = 0; // Clear flags.
flag2 = 0;
PSUFail = 0;
Timer = 0;
MFTimer = 0;
ObTimer = 0;

mlr = 1;

// Set up timer and interrupt.

tmr0 = 215; // Set for 10ms.
set_bit(intcon,T0IE);
set_bit(intcon,GIE);

Obviously the program continues but I'm not out to teach you 'C' programming on the PIC, nor am I out to sell SourceBoost, but it's so darn good I just had to tell you all about it.

ATMEL. I'm quite partial to Atmel chips but I've not used any in quite a while so it was a pleasant surprise to look back over the Atmel range and see that they've got some very nice chips indeed. Programmers are easily available for them that are of the ISP (In System Programming) type. The only problem I have with them, as opposed to the PIC, is that the pin count on the various packages isn't as flexible as the PICs. 8, 20, 28 seems the bottom end pin count on Atmels. However, I do like the way that things work consistently between the models, unlike PIC where peripherals change the way they are configured as you go up the ladder (the ADC being a notable peripheral). Atmel programmers are available from Farnell and RS. I think I got my latest starter kit from Farnell. My first one, many years ago, was from Equinox and was a parallel/serial programmer but it was limited in the range of Atmels it would program. Atmel seem to have sorted that with the new range.

Atmel

The new Atmel programmer is much slinkier than the one above and Atmel will feature in some of my upcoming designs as the hardware they have on board is very sophisticated and the chips are generally feature rich.

ZILOG. I like the Zilog Z8 Encore! But I'm gutted by it being 3.3V only. OK, the inputs are 5V tolerant but I think they could have made a 5V version. The programmer, like the Atmel, is a slinky ISP type device that also allows on-chip debugging. Now, there is a God send, on-chip debugging. You plug it in, program it, run it... and monitor its innards as it works, excellent.

EXPERIMENTORS BOARD. Just got to love 'plugbloc'. I have a nice one that I put together many years ago. Modified a little but not by much, simply because it's almost perfect as it is. Take a look:

xboard

This has a meter (0-100mA), a switch for easy on and off without reaching
for the Power Supply and a small microcontroller on board.

meter

The meter has little sockets on it to accept a multimeter (DVM).
Switches allow you to bypass the meter altogehter or shunt the output
to the sockets for using a higher current meter.

mcu

This little bit is a Zilog Z8Encore! microcontroller. ISP programmed, its own switch,
its own 3.3V power rail (which extends down to one of the 'plugblocs'.
In general, a useful thing that lets you experiment.

BACK