wakibaki
1000+ Head-Fier
- Joined
- May 26, 2011
- Posts
- 1,088
- Likes
- 68
A little while back I made a passing remark about writing a programming example for Microchip PIC.
Avro_Arrow said at the time that he would be interested if I took it on. I've been a bit remiss in keeping up my discrete amplifier co-operative design effort with him, so I'm going to write this tutorial. With luck, I'll have at least one reader.
The first thing we're going to build is a simple panel (volt) meter with digital readout. This can readily be adapted to show current, volume level, the passage of time or other quantities. It will illustrate an old, widely used, and basic hardware logic concept called BCD, or Binary-Coded Decimal, which dates all the way back to the pre-microprocessor days of early cash-registers and accounting computers.
Then we'll move on and convert the design into a push-button controlled TI PGA23xx based volume control, which is a little bit more demanding on the analog side and also introduces a widely used technique for serial control of peripherals called bit-banging. This opens up a simple way of doing I2C, I2S or SPI control.
We'll avoid the complications of high-speed timing-critical applications, but we will visit the conceptually important areas of interrupts and multiplexing and use visual persistence to create the illusion of a continuous display by repeatedly flashing 7-segment LEDs very fast.
The Microchip PIC and PIC design tools are a no-compromise system. They're not intended for artists or non-technical people to ease them into programming, but this means that if you learn to use them they are a good grounding for moving on to any other professional system. They're not really difficult to understand anyway, as we'll see...
These PIC designs use the most fundamental principles and the ideas contained in them can be extended to apply to virtually any kind of programming, be it applications programming for the PC or webpage programming using HTML and javascript. I regularly code in ladder logic, assembly language, C, C++, VHDL, XHTML, javascript, SQL, VBASIC and other scripting languages and I have used many other programming languages, both linear and object-oriented. Once you learn a few, picking up the threads of another is not difficult
To program a Microchip PIC you need a hardware programmer. I use a PicKit2 USB programmer. It's not the cheapest programmer, but it's not very expensive, and you can buy clones on ebay. The advantage is that it is 100% compatible with MIcrochip's free programming tools, collectively packaged under the name MPLab. A PicKit3 is also compatible.
You can use other toolsuites, build homemade programmers and still probably follow this tutorial. I've built programmers, but it's easier for me not to have to cover all the possible options, so if you use the standard Microchip tools, we'll all be on the same page. If anybody doesn't want to, or can't afford to, I'll try to answer any questions you may have.
The PicKit2 and 3 are ISP programmers. In System Programming. This means that you can build PICs into a device and reprogram them in place. You need to put a 5-pin header on the board to connect the programmer to. If you want to program a chip offboard, the simple thing to do is to build an adapter board with a chip socket on it to use with the PicKit and use a leaded chip which you can put into a socket on the target device.
I use a lot of surface mount components, it's a superior technology.
The first build will require:-
1 PIC 16F690
1 common-anode 3-digit 7-segment LED display
1 0.1u capacitor
1 1u capacitor
8 270R resistors
3 1k resistors
1 7805 regulator
3 GP PNP transistors
1 multi-turn preset potentiometer
11 470R resistors
PIC programmer, leaded and SMT PIC16F690's and a common-anode 3-digit 7-segment LED display:-

We can re-use some of these parts in the second build if we use through-hole parts.
Although I've built devices similar to these before, they're not complete re-hashes of existing designs. I haven't used this particular PIC before, so these circuits will be drawn up from scratch and hopefully I won't miss out any steps in the development. I'll try and break up the text with illustrations and code examples where I can, but unfortunately, given the nature of the subject, there will be some quite dense text to read.
I hope this teaser catches your interest, because there is quite a lot of work for me involved here, and I will need some encouragement if I'm going to plough through it all.
w
Avro_Arrow said at the time that he would be interested if I took it on. I've been a bit remiss in keeping up my discrete amplifier co-operative design effort with him, so I'm going to write this tutorial. With luck, I'll have at least one reader.
The first thing we're going to build is a simple panel (volt) meter with digital readout. This can readily be adapted to show current, volume level, the passage of time or other quantities. It will illustrate an old, widely used, and basic hardware logic concept called BCD, or Binary-Coded Decimal, which dates all the way back to the pre-microprocessor days of early cash-registers and accounting computers.
Then we'll move on and convert the design into a push-button controlled TI PGA23xx based volume control, which is a little bit more demanding on the analog side and also introduces a widely used technique for serial control of peripherals called bit-banging. This opens up a simple way of doing I2C, I2S or SPI control.
We'll avoid the complications of high-speed timing-critical applications, but we will visit the conceptually important areas of interrupts and multiplexing and use visual persistence to create the illusion of a continuous display by repeatedly flashing 7-segment LEDs very fast.
The Microchip PIC and PIC design tools are a no-compromise system. They're not intended for artists or non-technical people to ease them into programming, but this means that if you learn to use them they are a good grounding for moving on to any other professional system. They're not really difficult to understand anyway, as we'll see...
These PIC designs use the most fundamental principles and the ideas contained in them can be extended to apply to virtually any kind of programming, be it applications programming for the PC or webpage programming using HTML and javascript. I regularly code in ladder logic, assembly language, C, C++, VHDL, XHTML, javascript, SQL, VBASIC and other scripting languages and I have used many other programming languages, both linear and object-oriented. Once you learn a few, picking up the threads of another is not difficult
To program a Microchip PIC you need a hardware programmer. I use a PicKit2 USB programmer. It's not the cheapest programmer, but it's not very expensive, and you can buy clones on ebay. The advantage is that it is 100% compatible with MIcrochip's free programming tools, collectively packaged under the name MPLab. A PicKit3 is also compatible.
You can use other toolsuites, build homemade programmers and still probably follow this tutorial. I've built programmers, but it's easier for me not to have to cover all the possible options, so if you use the standard Microchip tools, we'll all be on the same page. If anybody doesn't want to, or can't afford to, I'll try to answer any questions you may have.
The PicKit2 and 3 are ISP programmers. In System Programming. This means that you can build PICs into a device and reprogram them in place. You need to put a 5-pin header on the board to connect the programmer to. If you want to program a chip offboard, the simple thing to do is to build an adapter board with a chip socket on it to use with the PicKit and use a leaded chip which you can put into a socket on the target device.
I use a lot of surface mount components, it's a superior technology.
The first build will require:-
1 PIC 16F690
1 common-anode 3-digit 7-segment LED display
1 0.1u capacitor
1 1u capacitor
1 7805 regulator
3 GP PNP transistors
1 multi-turn preset potentiometer
11 470R resistors
PIC programmer, leaded and SMT PIC16F690's and a common-anode 3-digit 7-segment LED display:-
We can re-use some of these parts in the second build if we use through-hole parts.
Although I've built devices similar to these before, they're not complete re-hashes of existing designs. I haven't used this particular PIC before, so these circuits will be drawn up from scratch and hopefully I won't miss out any steps in the development. I'll try and break up the text with illustrations and code examples where I can, but unfortunately, given the nature of the subject, there will be some quite dense text to read.
I hope this teaser catches your interest, because there is quite a lot of work for me involved here, and I will need some encouragement if I'm going to plough through it all.
w