programming PIC16F628A

Post
suvenier
New Member
2008/03/24 15:19:53
hi again.
 
Thanks for your last feedback in helping me installing my pic programmer.
 
Now I'm using a software chip burning system "MicroPro" which writes .hex files into 16f628a.
 
I came to realize that hex files are not compreensible to me, and that the usual method was to write .asm files and compile them to .hex files.
 
What software does that?
 
is asm sintax diferent from chip to chip?
 
 
ric
Super Member
RE: programming PIC16F628A 2008/03/24 15:38:32
Download the free MPLAB IDE from the Microchip website. That contains all the tools you need to write assembly language, and assemble it into hex files.
Guest
Super Member
RE: programming PIC16F628A 2008/03/25 09:28:56
yes MPLAB can also be used as code editor for generic C and ASM projects (not PIC)- it can highlight hex numbers, binary numbers, and yet only this feature is very helpful.
 
it can generate view of program memory (the hex code), and listing file; if you use other editors, they do not always offer these features.
suvenier
New Member
RE: programming PIC16F628A 2008/03/27 13:40:07
Thank you so much.
 
thats what i needed, MPASMWIN from MPLAB.
 
its done!
 
ok I have another doubt.
 
I got this .asm source file from Nigel´s tutorial page and assembled it into an hex to 16F628A.
 
[code/]
 
 
 
 ;Tutorial 1.1 - Nigel Goodwin 2002
 LIST p=16F628A  ;tell assembler what chip we are using
 include "P16F628A.inc"  ;include the defaults for the chip
 __config 0x3D18   ;sets the configuration settings
     ;(oscillator type etc.)
 org 0x0000   ;org sets the origin, 0x0000 for the 16F628A,
     ;this is where the program starts running
 movlw 0x07
 movwf CMCON   ;turn comparators off (make it like a 16F84)
    bsf  STATUS,  RP0 ;select bank 1
    movlw  b'00000000'  ;set PortB all outputs
    movwf  TRISB
 movwf TRISA   ;set PortA all outputs
 bcf STATUS,  RP0 ;select bank 0
Loop
 movlw 0xff
 movwf PORTA   ;set all bits on
 movwf PORTB
 nop    ;the nop's make up the time taken by the goto
 nop    ;giving a square wave output
 movlw 0x00
 movwf PORTA
 movwf PORTB   ;set all bits off
 goto Loop   ;go back and do it again
 end
 
 
[/code]
 
it makes all outputs high and low very quikly, so I think that if I place a led on the outputs it would be on (blinking far to quikly for the eye to see).
 
ok.
 
So I programmed my chip and placed it on an individual bread board, with a suply of 5.10 volts (6V taken down by diodes). I read that the 16f628A needed from 3.0 to 5.5 V.
 
MY bread board setting is : The chip with 5.1V on pin 14 and ground on pin 5. I'm using alkaline bateries filtred by a diode ( can I ?). than I poke around with my multimeter or a resitor&LED but none of the outputs seems to be HIGH..
 
it didn´t work!
 
Also, I havn't got used to the fuse setings in my programmer software , so maybe thats the problem... can you tell my the setings for this app?

 
DarioG
Scheisse Menschen
RE: programming PIC16F628A 2008/03/27 17:18:21
These would work for a 20MHz Crystal:

    __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON &_PWRTE_ON & _HS_OSC  & _MCLRE_OFF & _LVP_OFF


dchisholm
Super Member
RE: programming PIC16F628A 2008/03/27 23:23:44
In my experience PIC microcontrollers have been more robust, flexible, and forgiving than a lot of people realize.  Even so, there are several places where folks who are unfamiliar with microcontrollers commonly make mistakes.  Let me give you a punch list of things to check, as well as my guesses about what is NOT a problem for you.

ORIGINAL: suvenier

... with a suply of 5.10 volts (6V taken down by diodes). I read that the 16f628A needed from 3.0 to 5.5 V. ... I'm using alkaline bateries filtred by a diode ( can I ?).
This is probably OK for what you're doing but isn't a design to be especially proud of.  Three-terminal regulators are only a few cents more expensive than your diodes, and offer far superior performance.  Until you can get a low-dropout linear regulator, you might get better results using a string of only 3 alkaline cells, leaving off the diodes.  This should give you a supply rail between 3.5V and 5.0V depending on the batteries' state of discharge.

1.  On the microcontroller side of your dropping diodes you need a decent quality electrolytic capacitor.  Any value from about 10 uF to 470 uF should work.  The capacitor voltage rating should be at least 10V; 16V or 25V are OK.  Make sure you get the polarity correct when you install it!

2.  There MUST be a supply bypass capacitor, typically 0.1uF ceramic, connected from the chip's Vdd pin to Vss pin, very close to the chip.  If the chip has multiple supply pins every Vdd pin needs a bypass capacitor.  If you have any doubts whether you've done this correctly, you can carefully tack-solder bypass capacitors directly to the pins of a DIP package.

3.  The MCLR pin must be at a logic HI level unless your Configuration Word specifies the internal power-ON RESET option.  It is not a good idea to connect MCLR directly to Vdd - use a pullup resistor.  This MCLR level can be verified with a voltmeter or oscilloscope. (Using the internal RESET option permits the pin normally assigned to MCLR to be used as a general-purpose logic input pin.)

4.  There must be a clock oscillator signal.  Most PIC's have several options for creating this. An oscilloscope is the quickest and easiest way to identify an oscillator problem, unless you are using the internal oscillator.  Many people who think they have oscillator problems really do NOT have oscillator problems.  Oscillator questions can be easily avoided in many cases by using the internal oscillator.

5.  Unused pins should NOT be left floating (electrically unconnected).  Set them to either logic HI level or logic LO level with pullup or pulldown resistors (instead of direct connections to Vdd or Vss).  Do this even if you intend to program the pins as outputs or use internal pullups - the external terminations are the most fail-safe, idiot resistant approach.  In most cases it doesn't matter whether you choose HI or LO.  One exception is when the level you choose causes a constant INTERRUPT condition; another is that the PGM (low-voltage ICSP enable) pin must be kept LO. These logic levels can be easily verified with a 'scope or voltmeter.

6.  Disable the low-voltage ICSP option in the CONFIGURATION word, unless there is a REAL need for this feature.

7.  Disable the watchdog timer (WDT) in the CONFIGURATION word, at least until you know the system is operating.

8. Other options in the CONFIGURATION word(s) should be carefully chosen and correctly programmed.  This condition cannot be readily verified by direct measurement or observation.  If you have any doubts, get a programmer that can read back the CONFIGURATION word(s) and compare to what you expect the values to be.

I always explicitly enable or disable every CONFIGURATION option in my code.  This helps me keep my feces amalgamated by forcing me to think about what I'm doing and avoids surprises caused by default values that I hadn't thought about.  It looks something like this:
    __config    _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _PGM_CP & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _OSC_SRC
    ; _FCMEN_OFF    Fail-safe clock monitor disabled
    ; _IESO_OFF Clock switchover disabled
    ;       (locked on Internal clock).
    ; _BOR_OFF    Brown-out detection NOT used
    ; _CPD_OFF  Data EEPROM can be written
    ; _PGM_CP   Code protection as specified by the
    ;       '_PGM_CP' variable (defined in Wheel_Ph1Vars.inc)
    ; _MCLRE_OFF Internal MCLR.  RA3 is digital input.
    ; _PWRTE_ON Enable power-up delay timer.  Probably
    ;       not necessary, but it can't hurt.
    ; _WDT_OFF  Watchdog Timer disabled.  Need to come
    ;       come back & add code to support a WDT
    ;       function.
    ; _OSC_SRC  Clock source as specified by the _OSC_SRC
    ;       variable (defined in Wheel_Ph1Vars.inc)


Dale


paulbergsman
Super Member
RE: programming PIC16F628A 2008/03/28 02:49:51

it makes all outputs high and low very quikly, so I think that if I place a led on the outputs it would be on (blinking far to quikly for the eye to see).


If the circuit was working properly, and the LED was blinking quickly, then you would see
"a dim glow" from the LED.


So I programmed my chip and placed it on an individual bread board, with a suply of 5.10 volts (6V taken down by diodes). I read that the 16f628A needed from 3.0 to 5.5 V.

it didn´t work!


The lit LED draws additional circuit current.
As the load [your PIC circuit] gets larger, the voltage drop,  across the series LEDs, increases.
So, the voltage drop across you PIC circuit will decrease.
Result, the cirucit will not work.

you need a constant 5 volt voltage source.
A CMOS 7805 can output 5 volts from a 6 volt source.
Any 7805 can output 5 volts from a 9 volt source.

I prefer to use a calculator-type 5-volt switching power supply (check out Radio Shack, All Electronics, ect.).
Then, if you short the circuit, the power supply cuts off without any dammage (to the Power Supply)
post edited by paulbergsman - 2008/03/28 02:56:42
suvenier
New Member
RE: programming PIC16F628A 2008/03/28 06:31:06
Thank you all.
 
I stoped trying to compile and test random code from de net, and started learning Assembly for the pic my self.
 
I finaly built a working example of a glowing led. 
 
THANK you for that config example to you all.
 
THANK you so much for that check list dchisholm.
 
Now I see I was laking some aditional components:
 
So I understand that I need to apply a capacitor between de Vdd chip pin and the power source (to avoid voltage peaks?)
 
And that it's better to use 3 alkaline bateries or a source droped down by a CMOS chip ( do I need to keep the diodes any way?)
 
But why do I need an clock oscillator signal on my pic? does it need to be external?
 
I dont understand what is the bypass capacitor for.
 
A pullup/pulldown resistor is simply a resitor connected from the pin direcly to de Vdd/Vss? (I dont know Why they have that name)
 
Well, I also see it is best to declare in code the chip settings instead of lowing/highing the respective pins.
 
thank for your patience.
 
I'm feeling a bit more confortable in this theme thanks to you.
 
 
 
paulbergsman
Super Member
RE: programming PIC16F628A 2008/03/29 03:43:54
ORIGINAL: suvenier

 
And that it's better to use 3 alkaline bateries or a source droped down by a CMOS chip ( do I need to keep the diodes any way?)


No, not if you are using a Battery for your supply voltage.
Maybe, if you use a CMOS chip. Depends on what is powering the CMOS chip.

But why do I need an clock oscillator signal on my pic? does it need to be external?


You don't, unless you are doing something that is time sensitive, like using the USART module.

I dont understand what is the bypass capacitor for.


To "short"  noise  to ground


A pullup/pulldown resistor is simply a resitor connected from the pin direcly to de Vdd/Vss?


Yes.  Usually about  4.7K for  TTL  inputs.  And, about 10K for CMOS inputs.

(I dont know Why they have that name)  


"Pull-Up" I/O pin logic level to logic HIGH.
"Pull-Down" I/O pin logic level to logic LOW.
 

post edited by paulbergsman - 2008/03/29 03:51:08
jjmcd
Super Member
RE: programming PIC16F628A 2008/03/29 07:50:36
ORIGINAL: paulbergsman

ORIGINAL: suvenier
But why do I need an clock oscillator signal on my pic? does it need to be external?

You don't, unless you are doing something that is time sensitive, like using the USART module.

A little further qualification.....

You need an oscillator. The easiest thing to do is to use an internal oscillator. You can choose to use an external RC, a ceramic resonator, or a crystal.

The internal oscillator is the easiest thing to do, but not all PICs offer this option and the number of frequencies available is limited.

An RC selection allows you to get almost any frequency you want but it won't be horribly accurate and tends to be temperature and voltage sensitive. In your application, the voltage sensitivity could be an issue.

Crystals and ceramic resonators are a lot more accurate, crystals more so than resonators. Resonators are widely available in only a few frequencies, crystals are available in any frequency, but "standard" frequency crystals cost around fifty cents, while custom frequencies cost around twenty bucks. (But there are dozens of standard frequencies). A crystal also requires a couple of capacitors.

Unless the frequency requirement is really rigid, professional designers tend to prefer resonators because they are more rugged and cheaper. A resonator costs around a quarter, the crystal half a buck plus a couple of caps at a dime apiece (very rough numbers). Hobbyists tend to prefer crystals since the cost of either is practically invisible in a one-off project, and crystals are more easily obtainable from hobbyist sources.

You can also use an external oscillator but this is generally not needed except in special cases.

The 16F628A does offer an internal oscillator, so I would peruse section 14 of the datasheet and select the internal oscillator option you prefer, unless you have need of some specific clock speed. The 4 MHz internal oscillator of the 628A should work for many applications, however, the current consumption of the PIC is a function of oscillator frequency, so if the rest of your circuit draws very little current, you might get a bump in battery life by selecting a lower frequency. However, a few LEDs that are on most of the time will swamp the current consumption of the PIC, so in your application, it might not make much difference.
suvenier
New Member
RE: programming PIC16F628A 2008/03/29 09:08:00
thank you. i'll now try to configure the PIC's internal osc.
suvenier
New Member
RE: programming PIC16F628A 2008/03/29 12:47:29
SOrry to bother you so frequently but I'm lost.
 
I can't seem to find a decent ASM tutorial directed to the 16F628A specificly. Also I need a sketch With the complete circuit ( the most simple ).
 
I need a solid base to rely on, to be certain it is correct.
 
May you post a simple basic asm file to flash a LED?
 
and describe the external circuit please?
paulbergsman
Super Member
RE: programming PIC16F628A 2008/03/29 14:57:02
The PIC16F628A is a mid-range device.

Look up the PICkit2 In-Circuit-Serial-Programer.
It comes with an assembled and tested daughter board.
You can download the sample programs that come with the PICkit2 from this web site.
That will give you the source code for about 10 programs to get started.


dchisholm
Super Member
RE: programming PIC16F628A 2008/03/29 22:50:19
ORIGINAL: suvenier

. . . and describe the external circuit please?
Here is a simple circuit for the 16F628A.  It has one LED controlled by PORTA, bit0 (RA0) and one user switch sensed at PORTB, bit7 (RB7).  You may either modify your program to use these pin assignments, or modify these pin assignments to be compatible with your program.

Dale

Edit:  It is probably best to download the image file and open it in an image viewer, such as Microsoft Photo Editor or Picasa.  That allows you to magnify the image as needed to improve its readability.
Edit2: Corrected Note 2 in dwg
Edit3: Updated dwg to show additional supply filtering
post edited by dchisholm - 2008/04/16 17:45:27

Attached Image(s)

paulbergsman
Super Member
RE: programming PIC16F628A 2008/03/30 04:00:54
Hello;

Why are you using 20K pull-up, and pull-down, resistors?

I thought 10K were best for CMOS inputs.
DarioG
Scheisse Menschen
RE: programming PIC16F628A 2008/03/30 04:04:47
Yeah, or even less...

Funny is, PortB would already have pull-ups... and they're pulling them down Smile I'd just reverse them all.
Stefan Uhlemayr
Super Member
RE: programming PIC16F628A 2008/03/30 12:18:54
ORIGINAL: paulbergsman

Why are you using 20K pull-up, and pull-down, resistors?

I thought 10K were best for CMOS inputs.

ORIGINAL: DarioG

Funny is, PortB would already have pull-ups... and they're pulling them down  I'd just reverse them all.

The key-input has only a pull-up-resistor - it will work pretty fine. The pull-down-resistors are only to put the unused pins of portb to ground (which is recommend, when they are configured as inputs). It would be easier to configure them as outputs, but in this case Dale has decided to do it this way...

The inbuild weak "pull-up"s have a typical value of 25k (typ. current = 0.2mA @ 5V), and they are working very well, too. So I can't see a problem in using external 20k-resistors... I'm usually using 100k-pull-up-resistors (for jumpers having short pcb-tracks) without any problems, too.

Greetings,
Stefan
paulbergsman
Super Member
RE: programming PIC16F628A 2008/03/30 15:09:26
ORIGINAL: Stefan Uhlemayr

The inbuild weak "pull-up"s have a typical value of 25k (typ. current = 0.2mA @ 5V), and they are working very well, too. So I can't see a problem in using external 20k-resistors... I'm usually using 100k-pull-up-resistors (for jumpers having short pcb-tracks) without any problems, too.
Greetings,
Stefan


I thought the internal Port-B pull-up resisters were more like 200k.

So 10K, or even 20K, external resistors will easily override the internal weak pull-up resistors.

However, 20K pull-up or pull-down resistors, may increase the RC responce time, and/or shorten usable trace lengths.
post edited by paulbergsman - 2008/03/30 15:11:50
ric
Super Member
RE: programming PIC16F628A 2008/03/30 15:38:46
The pullups are a current source, not a resistance.
Typical current for a 16F628A is 200 microamps, so for a 20k pulldown, 20k * 200µ = 4V, so you would NOT want to have the internal pullups enabled at the same time!
You DO require a pulldown on RB4/PGM to program in-circuit, or to allow a chip to run with LVP enabled. I guess the designer just thought it neater to pull all the RB pins low.
DarioG
Scheisse Menschen
RE: programming PIC16F628A 2008/03/30 17:52:57
Thank you Ric and all the other who replied - I merely wanted to point out some possible issues.

As for "recommended values", I know that 10K or 200K work all the same to keep a input pin high or low and steady enough, but the point is that 4K7 can help also when some 20cm of wire is connected to that pin, and goes to a push button, and is close to whatever other piece of wire or antenna or mains or... Smile
dchisholm
Super Member
RE: programming PIC16F628A 2008/03/30 22:47:48
"I love it when a plan comes together!"

Paul, Dario, ric, and Stefan hit almost all the discussion points I wanted to see here.  Lesson summary:
  1. This design is a classroom tutorial exercise, not a production design.  Several features are incorporated to avoid situations that trap the inexperienced, rather than presenting an efficient design for a mass-produced product.
  2. The original (circa 1960) TTL gate design drew significantly less supply current if an unused input was pulled to logic HI rather than logic LO.  Hence pullups were almost always preferred over pulldowns.  This habit persists with CMOS logic devices, even though most of them have no inherent reason to favor pullups over pulldowns on unused inputs.  The circuit presents both pullup and pulldown terminations for unused pins.
  3. The resistance value of a pullup (or pulldown) on an original TTL gate was limited by the input pin's bias current and threshold voltage.  Using the same criteria for a CMOS input implies that pullup/pulldown resistances of 100's of kilohms or even megohms are practical . . .
  4. . . . but high-value pullups provide less ESD protection . . .
  5. . . . and a longer time constant on the input pin.  A longer time constant actually provides some filtering against corruption carried on the power rail, but slows down the rate at which the pin's logic state can change (when driven by, e.g., an open drain device).
  6. 20K ohm is roughly the midrange of the internal pullups' effective value.  (Even though the internal pullups are more accurately modeled as current sources rather than linear resistors.)
  7. An unused PIC input pin and connecting trace has an input capacitance on the order of 10 pF or a bit less.  In conjunction with a 20K pullup this makes a 200 nSec time constant - which is the duration of one instruction cycle for a PIC processor clocked at 20 MHz.
  8. On the 16F628A the internal pullups, only available on PortB under any circumstances, are disabled at RESET.  They will not be a factor in the selection of pullup/pulldown values as long as they are disabled . . .
  9. . . . but if the PortB internal pullups are enabled, a pullDOWN resistor can be no larger than 2K ohms to guarantee a logic-LO on the input.
  10. To avoid the mysterious ways the LVP feature can fornicate you if you're not alert, pull the PGM pin LO.
  11. To provide additional insurance against accidentally entering the Programming mode, pull the PGC and PGD pins HI.
  12. The LED is driven on its low side.  (You light it by completing the circuit to ground, or "sinking" its operating current.)  The early TTL gates had MUCH greater ability to sink current than to source it, so loads like LED's were always driven this way.  Even though PIC output stages are rated to either source or sink currents up to 25 mA, they still sink current more efficiently than they source it - so the circuit as shown is still the most common way to drive an LED.  Some inexperienced designers can't comprehend that writing a logic LO to a pin can turn an LED "ON".
  13. Sometimes, electromechanical considerations control design decisions.  In the circuit I posted, all of the pulldown resistors attach to pins on one end of the IC and all of the pullup resistors attach to pins on the other end!  (Nobody caught that!  Gotcha!)  This may make life easier for the PWB layout guy.  (Every once in a while a good PWB layout guy will tell a circuit designer something like, "Ya know - I can eliminate 7 vias and about a foot-and-a-half of trace if you can swap a couple of pins.".)
Dale
DarioG
Scheisse Menschen
RE: programming PIC16F628A 2008/03/31 04:12:11
Agreed on point 13) Smile

That's true, on 16F627-8-48 all of PORTA is at its left while PORTB is at its right: I don't usually rely on this, but, as you say, PCB needs can come into the play.
Stefan Uhlemayr
Super Member
RE: programming PIC16F628A 2008/03/31 14:00:48
ORIGINAL: dchisholm

Lesson summary:
  1. This design is a classroom tutorial exercise, not a production design.  Several features are incorporated to avoid situations that trap the inexperienced, rather than presenting an efficient design for a mass-produced product.
  2. The original (circa 1960) TTL gate design drew significantly less supply current if an unused input was pulled to logic HI rather than logic LO.  Hence pullups were almost always preferred over pulldowns.  This habit persists with CMOS logic devices, even though most of them have no inherent reason to favor pullups over pulldowns on unused inputs.  The circuit presents both pullup and pulldown terminations for unused pins.
  3. The resistance value of a pullup (or pulldown) on an original TTL gate was limited by the input pin's bias current and threshold voltage.  Using the same criteria for a CMOS input implies that pullup/pulldown resistances of 100's of kilohms or even megohms are practical . . .
  4. . . . but high-value pullups provide less ESD protection . . .
  5. . . . and a longer time constant on the input pin.  A longer time constant actually provides some filtering against corruption carried on the power rail, but slows down the rate at which the pin's logic state can change (when driven by, e.g., an open drain device).
  6. 20K ohm is roughly the midrange of the internal pullups' effective value.  (Even though the internal pullups are more accurately modeled as current sources rather than linear resistors.)
  7. An unused PIC input pin and connecting trace has an input capacitance on the order of 10 pF or a bit less.  In conjunction with a 20K pullup this makes a 200 nSec time constant - which is the duration of one instruction cycle for a PIC processor clocked at 20 MHz.
  8. On the 16F628A the internal pullups, only available on PortB under any circumstances, are disabled at RESET.  They will not be a factor in the selection of pullup/pulldown values as long as they are disabled . . .
  9. . . . but if the PortB internal pullups are enabled, a pullDOWN resistor can be no larger than 2K ohms to guarantee a logic-LO on the input.
  10. To avoid the mysterious ways the LVP feature can fornicate you if you're not alert, pull the PGM pin LO.
  11. To provide additional insurance against accidentally entering the Programming mode, pull the PGC and PGD pins HI.
  12. The LED is driven on its low side.  (You light it by completing the circuit to ground, or "sinking" its operating current.)  The early TTL gates had MUCH greater ability to sink current than to source it, so loads like LED's were always driven this way.  Even though PIC output stages are rated to either source or sink currents up to 25 mA, they still sink current more efficiently than they source it - so the circuit as shown is still the most common way to drive an LED.  Some inexperienced designers can't comprehend that writing a logic LO to a pin can turn an LED "ON".
Big thanks, Dale, for this very detailled description. I would suggest to place it into the FAQ-section (question: What things I have to consider on digital inputs?).

ORIGINAL: dchisholm

Sometimes, electromechanical considerations control design decisions.  In the circuit I posted, all of the pulldown resistors attach to pins on one end of the IC and all of the pullup resistors attach to pins on the other end!  (Nobody caught that!  Gotcha!)  This may make life easier for the PWB layout guy.  (Every once in a while a good PWB layout guy will tell a circuit designer something like, "Ya know - I can eliminate 7 vias and about a foot-and-a-half of trace if you can swap a couple of pins.".)
I think, most of us have had made this experience, too.wink

I've tried to make this problem as small as possible: I say to the layout-guy, which pins are fix (I2C-bus for example), which may be swapped within a specific range (analog-inputs for example) and which may be placed how pcb likes (digital i/o-lines). But of course, this is always depending on the application and the used PIC.[8|]

Greetings,
Stefan
dchisholm
Super Member
RE: programming PIC16F628A 2008/03/31 16:07:16
Thanks for the good words!  I hope that "suvenier" (the thread starter) appreciates that he's received at least a man-day of engineering work for free on this thread.

There are several check-lists of this sort scattered around the Forum, posted by various people about various topics.  Variations of the questions "How do I get started?", "How do I blink a light?", "Which PIC should I use?", and "My simple circuit doesn't work - what's wrong?" seem to be common and have received many good replies over the years. 

I don't know how to nominate something as an FAQ, or get it placed in the top-posting section of the display.  Then we could start responding "RTFFAQ" as well as "RTFM"! grin

ORIGINAL: Stefan Uhlemayr

. . . I say to the layout-guy, which pins are fix (I2C-bus for example), which may be swapped within a specific range (analog-inputs for example) and which may be placed how pcb likes (digital i/o-lines). But of course, this is always depending on the application and the used PIC.[8|]
You probably know that the good (and expensive!) PWB layout programs let you indicate pin interchangeability in their parts databases.  It works well for simple parts like resistor packages, OK for things like a package of interchangeable gates, and almost useless for complex parts like microcontrollers.  As you pointed out the identity of which pins can be interchanged varies from project to project, as the pins are used for different functions.

Dale

p.s. - Lest we perpetuate stereotypes and chauvinist attitudes, perhaps the best PWB layout "guy" I ever worked with was a beautiful, brainy, brunette, female girl-person of the feminine gender.
post edited by dchisholm - 2008/03/31 16:14:30
TerryN
New Member
RE: programming PIC16F628A 2008/06/29 07:25:05
[I hope that "suvenier" (the thread starter) appreciates that he's received at least a man-day of engineering work for free on this thread.]
I suspect he does: I know >>I<< do.  You guys are great!
There's something terribly daunting about that first Blinking LED...the patient hand-holding all you guys to is greatly appreciated!
DSchabel
Super Member
RE: programming PIC16F628A 2008/11/26 07:39:12
ORIGINAL: dchisholm

"I love it when a plan comes together!"

Great summary, Dale!

The original (circa 1960) TTL gate design drew significantly less supply current if an unused input was pulled to logic HI rather than logic LO.  Hence pullups were almost always preferred over pulldowns.  This habit persists with CMOS logic devices, even though most of them have no inherent reason to favor pullups over pulldowns on unused inputs. 

Pretty much true, BUT there is a reason to slightly favor pull-ups on CMOS inputs with non-symmetric thresholds, such as are found on PICs and, say, 74ACTxx as opposed to 74ACxx parts:  greater noise immunity. 
For instance, if you're powered at 5V and your threshold is between 0.8 and 2.0V as is the case for PICs TTL level inputs, you will have greater noise margin (at least 3V) if you pull UP to 5V than you would if you pull DOWN (0.8V worst case). 
 

The resistance value of a pullup (or pulldown) on an original TTL gate was limited by the input pin's bias current and threshold voltage.  Using the same criteria for a CMOS input implies that pullup/pulldown resistances of 100's of kilohms or even megohms are practical . . .

While I wouldn't recommend it because it's much easier to couple noise into a circuit with high input impedance than something somewhat "stiffer," I can say that 100s of kohms would work.  ONE Mohm for a pull UP might work; for a pull DOWN it isn't guaranteed to work (at least on a TTL-level input pin). 
PIC18 (for example) IO pins can "leak" (sink OR source) 1uA, meaning that it would generate 1V across 1Mohm.  This means that a pull-down with 1Mohm could be 1V, while you must keep the input to <0.8V to guarantee it's read as a low.  Even for pull-ups, a high resistance (high 100s of kohms or 1Mohm) really, really eats into your noise margin.  Only do this if you know what you're doing. 
dchisholm
Super Member
RE: programming PIC16F628A 2008/11/26 11:33:12
ORIGINAL: DSchabel

Great summary, Dale!
Thanks for the kind words . . .

. . . And a good quantitative discussion about noise margins.  Considering where the thread had started, I weasel-worded the comment about how lower resistance terminations were less susceptible to noise and omitted the analysis.  My personal prejudice is to use 20K ohm terminations unless there's a good reason for a different value.  Since this thread has become one of our "vademecum" references it's a good idea to have the additional information here.  Thanks for providing it!

I wonder why Microchip has stuck with the assymmetrical TTL thresholds.  My (unsubstantiated) impression is that most devices built with CMOS processes have approximately symmetrical logic thresholds  - typically (0.4*Vdd)/(0.6*Vdd).  Just for curiosity's sake I'll start a thread with that question and see what information shows up.

Dale

p.s. - In case you missed Dario's efforts to increase our cultural IQ: vademecum.

And thanks to Stefan and "Neiwiertz" for maintaining the bibliography at "Flying with HardWare Gallery List"!
stefanopod
Super Member
RE: programming PIC16F628A 2008/11/26 15:04:42
I suppose I know the reasons why fixing the voltage of an unused input is recommended.
 
As far as I know:
 
1)avoiding an unwanted current drain from an input switching in an unwanted and useless way;
 
2)avoiding potential cross talks between used and unused inputs- in connection with a bad supply decoupling.
 
I have seen in maybe 25 years an awful lot of breadboards and PCBs forgetting this rule.
 
Of course the way I could test the behaviour of any of these circuits was rather primitive, being the circuits  rather simple and the environment not really demanding.
 
But I never found a single example of a circuit presenting a malfunctioning whose culprit was the forgetting of this rule.
 
It would be of great interest for me to hear about  real world examples of this malfunctioning.
 
stefanopod
Super Member
RE: programming PIC16F628A 2008/11/28 12:05:55
Strange enough, no answer.
One could think that the problem of unused inputs in more esthetical, philosophical, than a true engineering problem (absolutely not sure of that).
I could add that I have seen sometimes problems arising from a silly handling of this problem.
An example : setting TRISE=0, to set PORTE, unused, as output, and messing awfully with parallel streaming port which in some pics is affected from TRISE setting.
dchisholm
Super Member
RE: programming PIC16F628A 2008/11/28 20:36:43
ORIGINAL: stefanopod

I suppose I know the reasons why fixing the voltage of an unused input is recommended . . .
I believe you are correct that it is a larger problem on breadboards and prototypes than in production units.

On an IC built with CMOS technlogy, an unterminated input can cause excessive current drain, perhaps even damaging the IC.  On a finished product it is OK to prevent this by setting unused pins as outputs.  In a prototype or development unit, before the software has been fully proven to be good, the hardware termination (resistor) provides extra insurance in case the software is faulty.

I recall troubleshooting one instance where an unterminated input broke into oscillation.  It actually was not intentionally unterminated - the SMT pulldown resistor was not soldered on one end.  This input was used to sense a switch contact.  When the switch opened, indicating a fault, the equipment went into random resets and displayed meaningless information, instead of reporting the fault condition.  At first this was believed to be a software fault, because a voltmeter - when placed on the pin - showed the expected readings of 5V (normal operation) and 0V (fault).  When we started using a 'scope on the RESET circuit we noticed a strong oscillation, and eventually traced it to the pin with a faulty pulldown resistor.

Dale
stefanopod
Super Member
RE: programming PIC16F628A 2008/11/29 04:29:51
Very interesting. Thanks a lot.
My idea is that sometimes one learns more from a  not working circuit than from a working one.
Knowing the reasons of a rule is important, but it's important also to know its "weight".
Good decoupling of power supply, for example, has a "weight" that a beginner often can't understand.
The same for the correct routing of ground tracks in analog circuits and for a lot of other rules.