Friday, March 15, 2013

microcontroller

Low-cost programmer for dsPICs and PICs

The dsPIC30F series of microcontrollers are extremely useful, but most older PIC programmers cannot program them. This is due to incompatibilities with the pinouts of the dsPIC family. 

Programming procedure 
Our new programmer is based on the original COM84 style programmer – so named because it was designed to program 16F84 microprocessors from a serial port. There are really three lines which are necessary to program most PICs and microcontrollers in the dsPIC30F family: CLOCK (PGC), DATA (PGD) and VPP (programming voltage).

Incidentally, the dsPIC30F family has two programming modes – enhanced and standard. The enhanced mode is faster and requires a programming executive or ‘bootloader’ to be programmed in first. However, this programmer uses only the slower ICSP mode that is standard across the PIC family (ICSP stands for in-circuit serial programming). 


Programming mode is entered by raising VPP up to around 13V. Data is then programmed into the microcontroller by serially shifting commands and data using the PGC and PGD lines.
 
The PGC line synchronises the exchange of serial bits, while the PGD line contains the data. The PGD line is bidirectional, allowing reading and writing of the microcontroller.
 
For example, there is a command code for ‘Erase’ which will erase the flash memory of the microcontroller. There are also commands for ‘Writing’ and ‘Reading’ pages. As soon as the microcontroller enters programming mode, it starts listening for commands. 

Circuit detail
Fig.1 shows the circuit details. As can be seen, the dsPIC/PIC Programmer has two distinct supply rails (+5V and +13.6V) and these are derived from the DC supply rail using two 3-terminal voltage regulators (REG1 and REG2). Switch S1 is the power on/off switch, LED1 provides power indication and diode D1 provides reverse polarity protection. 

In this case, R1 and R2 have been selected so that REG2 regulates its output to 13.6V in typical conditions. This provides the MCLR/Vpp voltage for the microcontroller, which should ideally be between 12.8V and 13.1V. Basically, on a PIC or dsPIC microcontroller, the MCLR/VPP pin acts either as a Reset (0V) or a programming voltage pin (around 13V for PICs or between 9V and 13V for a dsPIC30F series microcontroller). When MCLR/ VPP is low, the microcontroller is in the Reset state (meaning that all its configurable pins are high impedance inputs). When it is high (around VDD = +5V), the microcontroller runs in program mode, and if it is at Vpp the microcontroller will enter programming mode.
Low-cost programmer for dsPICs and PICs
Control lines
The relevant lines used in the RS-232 serial interface to control the dsPIC/PIC Programmer are derived from pins 3, 4, 5, 7 and 8. Pin 5 is the ground connection, while pins 3, 4 and 7 (respectively Tx, DTR and RTS) are outputs from the serial port. In particular, pins 4 and 7 are digital outputs, while pin 3 is usually the Transmit line of the serial port. These are controlled by the Win- PIC software on the PC as appropriate. 

Finally, pin 8 (CTS) is an input pin, and this is used to read data from the microcontroller, as required to verify or read the state of the memory.

IC1 is a MAX232 RS-232 line driver/receiver. Its job is to translate between the RS-232 voltage levels (ie, ±10V) at the serial port and the TTL levels (0-5V) used by the microcontroller. As mentioned, pins 4 and 7 of the serial port are standard digital outputs and these are connected directly to IC1. 

Two ZIF (zero insertion force) sockets are used to accept the microcontroller to be programmed. ZIF SKT1 is used for dsPIC30F series microcontrollers, and they should always be aligned with their pin 1 going to pin 1 of the ZIF socket. Alternatively, ZIF SKT2 should be used for programming standard PICs like the 16F88. As before, pin 1 of the microcontroller goes to pin 1 of the ZIF socket. 

Note, however, that the 10F and 12F series of PICs are not compatible with the onboard ZIF socket. These must be programmed via an external adaptor board, as described later, or by using CON3 and a breadboard.

External programming 
CON3 is a 6-pin header, and its pinout is arranged as shown in Table 1. It can be used to access the five relevant lines required to program both PICs and dsPICs externally (see the section entitled ‘Programming via CON3’). 
For example, if your PIC is not actually compatible with the pinning of ZIF SKT2 (eg, if you have a PIC10F202), then you may use this connector to access the relevant lines. These lines can be connected to, say, a breadboard, to program your PIC off the PC board. Of course, you can also use this connector to program microcontrollers in circuit as well. 

Jumper settings 
Finally, there is an 8-pin header which accepts jumper shunts JP1 to JP4. However, only two of the four positions should ever be shorted at any one time. Table 2 shows the jumper functions.
If JP1 is shorted, it connects the PGC line to pin 8 of ZIF SKT1. This will cater for some dsPIC30Fxxxx micro-controllers that require the programming clock on pin 8.Alternatively, if JP2 is shorted, it connects pin 8 of ZIF SKT1 to ground, and this caters for the rest of the dsPIC30Fxxxx family that requires a ground connection at pin 8. 

Links JP3 and JP4 select which pin the MCLR/VPP programming line is connected to on ZIF SKT2. If JP3 is shorted, it connects the programming line to pin 4 of ZIF SKT2, and this suits microcontrollers such as the popular 16F88. Alternatively, some microcontrollers require the programming voltage to be applied to pin 1, and this is selected by installing JP4 instead. 

Programming via CON3
The 6-pin header CON3 can be used to program a PIC or dsPIC that’s either mounted in-circuit on a separate board or installed on a breadboard. For example, this is one way of programming a PIC microcontroller that doesn’t have a compatible pin-out with the ZIF sockets – see Table 3. 

The pinouts for connector CON3 are shown in Table 1 and include the GND, +5V, MCLR/VPP, PGC and PGD lines. These are the only lines you need to program your microcontroller.
 
Optional Adaptor Board for 10F and 12F series PICs 
We have also designed an optional adaptor board for 10F and 12F series PICs – see Fig.3. This adaptor plugs directly into ZIF socket SKT2 on the dsPIC/PIC Programmer; the position of the jumper on JP3 or JP4 is irrelevant when using the adaptor. 

As shown in Fig.3, the adaptor has 20-pin and 8-pin IC sockets. The 8-pin socket is for 10F series PICs and the 20-pin socket is for 12F series PICs. As usual, the microcontroller to be programmed should be oriented so that its pin 1 is connected to the socket’s pin 1. In addition, pin 1 of the adaptor board goes to pin 1 of ZIF SKT2. You will need to refer to the microcontroller’s datasheet and ensure that the pinout is compatible with the ZIF socket by referring to the schematic diagram.

Preliminary testing 
Before using this new programmer, it should be given a thorough check. Important: do not insert a microcontroller (PIC or dsPIC) into any ZIF socket before these tests are completed. 

A 16V DC plugpack should be used to power the dsPIC/PIC Programmer, although you can also probably use a 15V DC plugpack (just). Apply power and you should see the red indicator LED light. If it doesn’t, check the supply polarity, and if that’s OK, check the polarity of the LED. 

Assuming that the LED lights, the next step is to check the voltages at the outputs of the two regulators. You should measure +5V at the output of REG1 (anything from 4.8V to 5.1V is
normal), while REG2’s output should be close to 13.6V (13.4V to 13.8V is OK). 

If REG2’s output is lower than 13.4V, increase the value of the 82W resistor (eg, to 120W) to bring it into the 13.4V to 13.8V range. Conversely, if the output is higher than 13.8V, decrease the value of the 82W resistor. 
 
Software installation 
As mentioned earlier, the software to use with this programmer is Win- PIC, available from http://www.qsl. net/dl4yhf. Once it has been downloaded, it’s installed by running the executable file winpicsetup.exe.

Setting up WinPIC 
After installing WinPIC, you should make sure that it is correctly set up to work with the programmer. Here’s how to configure WinPIC:
1) Start WinPIC and click on the ‘Interface’ tab (see Fig.4)
2) Ensure ‘COM84 programmer for serial port’ is selected from the drop down menu
3) Ensure the correct COM port is set
4) Check that both ZIF sockets are empty and that the programmer is connected to the PC via a serial cable
5) Apply power to the programmer and click on ‘Initialize!’
6) In the ‘Options’ tab, select either PortTalk or SMPORT (both are faster than using the Windows API).
Troubleshooting 
If you receive the message ‘WARNING: Could not initialize programmer!’ instead, you can test the interface manually to narrow down the list of possible problems. Here’s what to do:
1) Clicking the ‘VPP(+13V)’ box should toggle pin 1 of CON3 (the external programming header) from 0V (box unticked) to around 12.5V to 13V (box ticked). If this doesn’t happen, check that transistors Q1 and Q2 are the correct types. If they are, trace the signal from pin 3 of the serial port to pin 1 of CON3, checking at each stage that the signal toggles as this box is ‘ticked’ and ‘unticked’ in WinPIC.

2) Clicking on the ‘Clock’ box should toggle pin 2 of CON3 from 0V (unticked) to around 4V to 5V (ticked). If that doesn’t happen, check the MAX232 and its surrounding capacitors. That done, check the signal at pin 7 of the serial port, then at pins 13 and 12 of IC1, pin 1 of IC2, pin 2 of IC2 and finally pin 2 of CON3. Note that the MAX232 (IC1) should level translate the signal level at pin 13 to about +5V at pin 12. 

3) Clicking on the ‘Data (to PIC)’ box should toggle pin 6 of CON3 from 0V to around 3.5V to 5V, and you should see the ‘Data In=’ field change from 0 to 1. The latter should be 0 with the box unticked and 1 otherwise.

If this is not the case, check the signal at various points on the circuit from pin 4 of the serial port to pin 6 of CON3. Check also that pin 8 of the serial port is receiving the correct level (read by WinPIC and displayed in the ‘Data In=’ field).
                                     




                                                                                  ENJOY !!!



By Mesfin Teshome.

No comments:

Post a Comment