PDA

View Full Version : Q: using MCLR for Input on 12F683



picster
- 30th December 2008, 19:06
When configuring MCLR'/VPP as GP3 for input on the 12F683, do you program it afterwards via the same protocol - i.e.- does the programming function of the MCLR'/VPP pin change, or will I still be able to program via ICSP as normal?

LinkMTech
- 30th December 2008, 20:05
You can set it up for an input from the beginning of the program then still use it later for programming. Just make sure your circuit will still allow the Vpp signal to control it during programming otherwise it will boop at you and report an error.

mackrackit
- 30th December 2008, 20:16
And make sure you circuit will handle the programming voltage.

I like to use some method of isolation when programming. The simplest is a two pin header with a jumper clip.

picster
- 30th December 2008, 21:01
Makes sense, thanks guys - I had planned on input circuit isolation at the pin, but wasn't sure if there was some other issue that I'd run into during subsequent programming...

Thanks again, and happy new year all!

johnnylynx
- 2nd January 2009, 03:57
Hi, new to this forum and to PIC's in general. I fly RC and have used a 12F683 to act as failsafe system for 3 servos.

I've tried the pulsout command but the output just goes HI?? (I have scope to check).

Here is the code:

pos var byte ' Define our storage location for the servo position information.
servo var byte ' Define our storage location for the servo number to move.
cont var byte ' Define a variable to hold the count.

' 4 mhz clock internal
' 500 = 1 ms
' 1000 = 2 ms
' 1250 = 2.5 ms


pos = 1250

start:


for cont = 0 to 50
pulsout portb.4,pos ' Send servo# ? to position ?.
pause 20 ' Wait 20 ms.
next cont ' Next pulse.


goto start ' Return to get more serial input.


Can anyone help??

mackrackit
- 2nd January 2009, 04:14
Try changing pos to a WORD size var and see if that helps

johnnylynx
- 2nd January 2009, 23:42
Try changing pos to a WORD size var and see if that helps

Thanks! it worked on the 16F84A chip.

I'm still having difficulty with the 12F683 though. The pulsout doesn't seem to work. I wonder if the chip supports that command?

I've also tried running the servo by setting the pin high and low timing the high between 1 to 2 ms and the low to 20ms. It works, but it won't accept a decimal number:mad:.

at 4 mHz, I need to pause for between .5ms and 2.5ms but it only accepts 1 and 2 !!!

suggestions??

John.

p.s., here's the code:



posit var word

cont var word
cont2 var word
Q var word


let posit = 3/2

Let Q = 25

start:

for cont = 1 to 50
high 0
pause posit
low 0
pause 20
next cont



goto start

LinkMTech
- 3rd January 2009, 03:46
It doesn't show in your code so I will assume that the device has not been configured to what you want to do with it since it has other features.
Start by setting the oscillator then the ports with the TRISIO command, found on page 35 of the data sheet, shut OFF the comparators and the A/D feature:


OSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data

Then use the PAUSES command instead of PAUSE for a better resolution of the timming you need:
PAUSE 1 gives you 1ms where PAUSES 1000 will do the same but now you can get your 1.5ms with PAUSES 1500.

LinkMTech
- 3rd January 2009, 03:54
Didn't know how to edit last post so:

Use GPIO.# instead of PORTB.# per pg. 35 of data sheet.

eggman
- 3rd January 2009, 11:07
That should be PAUSEUS not PAUSES.
PAUSEUS will pause microseconds, not milliseconds.
If you let PBP devide 3 by 2 then you will always get 1 as an answer.
So if you want to pause 1.5 milliseconds use PAUSEUS 1500 instead.

happy new year

johnnylynx
- 3rd January 2009, 16:41
Thanks LinkMtech and eggman (sounds like a TV show in the making!). I'll try your comments today.

Happy new year to both of you.

John.

johnnylynx
- 3rd January 2009, 18:56
Thanks gents, both option worked like a charm.

Cheers!:D

johnnylynx
- 12th January 2009, 05:03
OK, anthor problem...

I'm trying to run an RC servo from a PIC12F683. I'm using pin 0 as output and pin 1 as input (from receiver)

As long as there is a signal from pin 1, the PULSOUT will output the PULSIN value. When no signal is present (PULSIN=0) then PULSOUT should go to a failsafe value.

Situation: When the signal is present, the PULSOUT sends the PULSIN value, but when PULSIN = 0, the PULSOUT does send the proper value, but in 1/2 second intervals (it pulses the value about every 0.5 sec). I can't figure out why!!!

here's the code:


oSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data


cont var word
failsafe var word
posoutput var word
posinput var word
usefailsafe var byte
pausetime var word



low gpio.0
low gpio.1
low gpio.2
low gpio.3

failsafe=80
pausetime=10

START:

;pulsout portb.4, failsafe
;pause 50
;goto start


GETSIGNAL:

pulsin gpio.1,1,posoutput

if posoutput=0 then goto runfailsafe
goto runnormal

runfailsafe:
pulsout gpio.0, failsafe
pause pausetime
goto getsignal

runnormal:
pulsout gpio.0, posoutput
pause pausetime

goto getsignal

johnnylynx
- 12th January 2009, 05:32
I have one more...

I want to write the PULSIN value to the memory on the 12F683 (and have it stored even when the power is off) and recall it in the event there is no PULSIN signal.

What are the proper commands to do this?

(I assume write and read)

I.e.

WRITE 5, failsafe

READ 5, failsafe

...but first I have to get the servo thing working!!

mackrackit
- 12th January 2009, 09:22
This may help with your data storage.
The below code is for a counter, sort of like an odometer. It saves the value to EEPROM at each hit of a switch. When the device is turned on the EEPROM is read and the values placed back into a variable for continued use. Also has the ability to reset the stored values back to zero at start up.

Pick through it and see if it helps.


'* Notes :16F877A
'* SAVE TO EEPROM
'************************************************* ***************
'_config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF &_BODEN_OFF

DEFINE OSC 20

DEFINE LCD_DREG PORTB
define LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

TRISA = %00000000
ADCON1=14

Asm
ERRORLEVEL -306
Endasm
include "modedefs.bas"


'TOTAL VARS
O VAR BYTE 'ONES
T VAR BYTE 'TENS
H VAR BYTE 'HUNDREDS
TH VAR BYTE 'THOUSANDS
TTH VAR BYTE 'TEN THOUSANDS
HTH VAR BYTE 'HUNDRED THOUSANDS
M VAR BYTE 'MILLIONS

OD VAR BYTE 'ONES
TD VAR BYTE 'TENS
HD VAR BYTE 'HUNDREDS
THD VAR BYTE 'THOUSANDS
TTHD VAR BYTE 'TEN THOUSANDS
HTHD VAR BYTE 'HUNDRED THOUSANDS
MD VAR BYTE 'MILLIONS

'TOTAL LOGS
O_LOG VAR BYTE 'ONES
T_LOG VAR BYTE 'TENS
H_LOG VAR BYTE 'HUNDREDS
TH_LOG VAR BYTE 'THOUSANDS
TTH_LOG VAR BYTE 'TEN THOUSANDS
HTH_LOG VAR BYTE 'HUNDRED THOUSANDS
M_LOG VAR BYTE 'MILLIONS

'READ LOGS
READ O_LOG, OD
READ T_LOG, TD
READ H_LOG, HD
READ TH_LOG, THD
READ TTH_LOG, TTHD
READ HTH_LOG, HTHD
READ M_LOG, MD


NUM VAR BYTE
NUM = 0
pause 1000

CHECK:
IF PORTE.2 = 1 THEN GOSUB CL_LOG 'FOR RESET AT START UP
IF PORTE.2 = 0 THEN START
GOTO CHECK

START:
HIGH PORTD.2 'LED
PAUSE 5
IF PORTD.3 = 1 THEN GOSUB C_P_T 'SWITCH FOR PARTS
LOW PORTD.2
PAUSE 5
GOTO START

C_P_T:
LCDOUT $FE,1,"C TEST"
LCDOUT $FE,$C0,DEC MD,DEC HTHD,DEC TTHD,DEC THD,DEC HD,DEC TD,DEC OD
O = O + 1
IF O = 10 THEN
O = 1
T = T + 1
IF T = 10 THEN
T = 0
H = H + 1
IF H = 10 THEN
H = 0
TH = TH + 1
IF TH = 10 THEN
TH = 0
TTH = TTH + 1
IF TTH = 10 THEN
TTH = 0
HTH = HTH +1
IF HTH = 10 THEN
HTH = 0
M = M +1
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF

WRITE O_LOG, O
WRITE T_LOG, T
WRITE H_LOG, H
WRITE TH_LOG, TH
WRITE TTH_LOG, TTH
WRITE HTH_LOG, HTH
WRITE M_LOG, M

READ O_LOG, OD
READ T_LOG, TD
READ H_LOG, HD
READ TH_LOG, THD
READ TTH_LOG, TTHD
READ HTH_LOG, HTHD
READ M_LOG, MD

RETURN

CL_LOG:

HIGH PORTD.2
PAUSE 100
LOW PORTD.2
PAUSE 100

O = $0
T = $0
H = $0
TH = $0
TTH = $0
HTH = $0
M = $0

WRITE O_LOG, O
READ O_LOG, OD
WRITE T_LOG, T
READ T_LOG, TD
WRITE H_LOG, H
READ H_LOG, HD
WRITE TH_LOG, TH
READ TH_LOG, THD
WRITE TTH_LOG, TTH
READ TTH_LOG, TTHD
WRITE HTH_LOG, HTH
READ HTH_LOG, HTHD
WRITE M_LOG, M
READ M_LOG, MD
RETURN

END

LinkMTech
- 12th January 2009, 18:51
I found that PULSIN will time out while you're waiting for something to happen then was clued in on WHILE:WEND.
So try this command set with something like:


WHILE GPIO.1 = 0 ' Repeat this loop while there is no signal
pulsout gpio.0, failsafe
pause pausetime
WEND


It comes in handy for something like this.

johnnylynx
- 15th January 2009, 05:55
Thanks LinkMTech and Mackrackit:

Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).

I have a couple more questions hopefully you can help me with.

1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???

2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.

Thanks again gents.

John.

BrianT
- 15th January 2009, 06:04
I crashed my RC aircraft using the PULSOUT command.

PULSOUT is a 'toggle'. Whatever state the pin was in, it will flip for the duration specified in the PULSOUT command. That is bad news if your servo pin gets clobbered and you were expecting it to be low when you called the PULSOUT routine.

To be safe, you MUST predefine the pin state before calling PULSOUT.

e.g.

LOW ServoPin
PULSOUT ServoPin, 500

will work every time.

HTH
Brian

mackrackit
- 15th January 2009, 07:23
Thanks LinkMTech and Mackrackit:

Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).

I have a couple more questions hopefully you can help me with.

1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???

2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.

Thanks again gents.

John.

Can you post your code?

johnnylynx
- 16th January 2009, 01:49
Whoops, sorry about that!

here's the code:


oSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
input gpio.4

inpulse VAR Word
memory var word
low gpio.4
low gpio.3


start:


SEROUT 0, 2, [12]
start2:
PULSIN 1, 1, inpulse

if inpulse<50 then
read 5, memory
serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
goto start2
else
endif

if gpio.4=1 then
write 5, inpulse
serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
high gpio.3
low gpio.4
else
low gpio.3
endif

SEROUT 0, 2, [17,22,#inpulse*10]
PAUSE 20


GOTO start

END

johnnylynx
- 16th January 2009, 01:54
I crashed my RC aircraft using the PULSOUT command.

PULSOUT is a 'toggle'. Whatever state the pin was in, it will flip for the duration specified in the PULSOUT command. That is bad news if your servo pin gets clobbered and you were expecting it to be low when you called the PULSOUT routine.

To be safe, you MUST predefine the pin state before calling PULSOUT.

e.g.

LOW ServoPin
PULSOUT ServoPin, 500

will work every time.

HTH
Brian


Thanks Brian, I've got the pulsout working...actual pretty good now. Just some issues with getting gpio.2 and gpio.3 to simply operate LED's!

My code is posted above.

Cheers,

John.

Archangel
- 16th January 2009, 03:20
OSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
input gpio.4 '<font color=red> make input</font color>

inpulse VAR Word
memory var word
low gpio.4 <font color = red> ' Now you make it an output</font color>
low gpio.3


start:


SEROUT 0, 2, [12]
start2:
PULSIN 1, 1, inpulse

if inpulse<50 then
read 5, memory
serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
goto start2
else
endif

if gpio.4=1 then '<font color=red> still an output, are you wanting an input?</font color>
write 5, inpulse
serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
high gpio.3
low gpio.4 '<font color=red> is and should be an output</font color>
else
low gpio.3
endif

SEROUT 0, 2, [17,22,#inpulse*10]
PAUSE 20


GOTO start

END

johnnylynx
- 17th January 2009, 18:09
Thanks Joe,

I didn't catch that, I'll make changes and see if that fixes the input problem.

I still have the output issue though with GPIO.3, it doesn't want to run the LED.

Any thoughts?

John.

mackrackit
- 17th January 2009, 18:43
Not sure but I think that pin is input only.

Archangel
- 17th January 2009, 19:08
I dunno John, I never use the High / Low convention, preferring to specify TRISIO AND GPIO instead because as I understand it , High/Low reads modify's and writes the whole port ( all the I/Os ) when you do.

johnnylynx
- 19th January 2009, 04:05
Thanks guys,

I think I've got it working OK now...but by copy of the picbasic compiler (with microcode studio) only limits me to 31 code lines:mad:

As much as I like Microcode Studio...is there something out there a guy can use that is much cheaper than picbasic pro AND is downloadable from the NET?

John.

rmteo
- 19th January 2009, 04:43
http://www.oshonsoft.com/pic.html
About US$70, Unlimited demo, FREE for 30 days.

http://www.mikroe.com/en/compilers/mikrobasic/pic/
US$149, FREE demo limit 2K code (with the PIC12F683, you fill the entire program memory with the demo).

johnnylynx
- 20th January 2009, 05:30
http://www.oshonsoft.com/pic.html
About US$70, Unlimited demo, FREE for 30 days.

http://www.mikroe.com/en/compilers/mikrobasic/pic/
US$149, FREE demo limit 2K code (with the PIC12F683, you fill the entire program memory with the demo).

Thanks, how do these compilers compare to picbasic pro?

John.

rmteo
- 20th January 2009, 15:44
Thanks, how do these compilers compare to picbasic pro?

John.
I suggest that you download the demos (and relevant user manuals) and judge for yourself. I think you will be pleasantly surprised.

rmteo
- 20th January 2009, 20:20
Oops, left out my favorite (only for PIC18's though) - US$149, Demo limited to 256 bytes of RAM, no restrictions on code size:
http://www.sfcompiler.co.uk/swordfish/

johnnylynx
- 21st January 2009, 04:33
Oops, left out my favorite (only for PIC18's though) - US$149, Demo limited to 256 bytes of RAM, no restrictions on code size:
http://www.sfcompiler.co.uk/swordfish/

I tried mikrostudio...I like the picbasic code better (maybe because I'm learning on that platform). I also have MPLAB that came with my pickit2...but it works on asm. I appears if I get the picbasic compiler that I could program in MPLAB using picbasic???

Is that right?

JOhn.

mackrackit
- 21st January 2009, 04:37
MPLAB and PBP work very well together. I normally use MPLAB over MCS.
http://www.melabs.com/support/mplab.htm

tenaja
- 21st January 2009, 11:50
I was looking in to C compilers last year, and got some great feedback from a guy whose job requires him to be familiar with just about every pic compiler. (His feedback was offline, because he could not post his opinions public for the same reason he knows about all of the compilers. I am going to respect his anonymity.) Anyway, his advice regarding Mikroe and their compilers was to avoid them, for a variety of reasons. (Which mostly boiled down to "you get what you pay for.")

I own PBP, and find it a great compiler for people wanting to step up from Stamps. I mostly use Proton Basic (PDS), however, because it compiles much more compactly (about 20%) and runs faster. It's only $165, and even comes with a simulator that allows you to step through your code and debug much faster. The sim is limited to a couple chips and a couple development board models, but that allows you to test routines without messing with hardware. (I purchased the full sim so I can create just about any circuit I can think of--but that is not cheap.)

For the most part, you get what you pay for in compilers. Comparing PBP to PDS, they are very similar (they both used BS2 as a base), but PDS is more powerful. The same guy mentioned above said PDS "is as close to coding in asm as it gets for any pic compiler." The biggest difference is that PBP is a little more oriented (better oriented?) towards beginners because it has fewer features to trip you up. PDS has a larger command set, and built in interrupt context saving. The parser is better with PBP, so you can string together many math equations on one line with lots of parentheses to make it readable...but if you separate them out and use PDS, your code will be a LOT smaller.

rmteo
- 21st January 2009, 18:45
Would you care to share the reasons why your guy said to avoid mikroE?

tenaja
- 21st January 2009, 19:05
This is what he said that I can share: "mikroC has a good support of internal libraries but the binary code is not that optimized". Like I said, the rest boiled down to "you get what you pay for." If you want cheap, you get cheap... either minimal features, buggy or bloated code. Nobody makes a compiler that is bug-free, optimized, and feature-full.

And, more importantly for me, I use the Proteus PIC/Spice simulator for debugging my code, and the Mikro compilers put out a proprietary format (not a standardized format), so it is only useful for use with their own debugger.

You can always use PicBasic (instead of PicBasic Pro), which is a lot cheaper, and almost certainly bug-free... but it has minimal features and no optimization. There's also the free Pascal-like compiler, JAL: http://www.voti.nl/jal/

mister_e
- 21st January 2009, 22:31
while cheaper is not always better, even if you pay a single full license for Hi-Tech C (more than 2K) but cover ALL PIC familly (from 10F to Dspic, PIC32), you won't have the peace of mind. Most of those I know of, have now moved on Microchip ones. OK they're still expensive, but they seems to be better with years than Hi-Tech (That's what i've heard and experimented myself awhile back).

However, the only single language that cover EVERY PIC familly and which is free is ASM. That's great, but a real pain to program in, and it's syntax change from a familly to another, more noticeable on DsPIC/PIC32. Good news is, the only person you will be abe to blame when a bug will appear one day or another is you.

Depending where you are located in the product food-chain, ASM is great or bad.

For every compiler on the market, we heard good and bad comments... same things goes for all device programmers, IDE, etc etc etc. What I hate is to learn 3,4,5,6,7...10 different compiler to do a single job.

Knowing your compiler is great, knowing your own limit is great, ASM cover everything, but you must know and admit your personal limit/time.

It's a full piece of crap to say that ASM is faster... it's really up to the pepper back of the keyboard.... hence why performance of each and eavery compiler differ for the same single task.

Time wasting... is this a real waste, or knowledge improvement... who knows? On the other side, who care of a developer knowledge if another do it WAY faster... once it's burned in a black pinned box, and do the job as per the customer requirement, no one will care of the tool you used.

Same bull**** happen with PC... C is better than Basic... euh NO SIR your $%!$%^#@ wrong C#... Delphi... Python....Java is better... crap crap crap... unfortunately, actual market is... faster is better... crap crap crap...

johnnylynx
- 24th January 2009, 23:18
Wow, seems I opened up a can of worms there;)

I was looking over ASM earlier (from a beginners perspective) and learned how to convert binary to hex (amazingly simple...after a 3-finger scotch!)

Still, ASM, as you all have essentially indicated, is ... a pain.

I'm checking out PDS...and don't see if it supports pickit2 and a programmer (anyone know?).

I think i'll end up purchasing either PDS or PBP...both look great!

Thanks for all you're input!

John.

mackrackit
- 24th January 2009, 23:26
The PICKIT2 will load the generated hex, does not matter who or what created it.

Can of worms?
What did you expect, I like Fords, are they better :)

rmteo
- 24th January 2009, 23:56
I agree with with Dave, that is why I suggested that you try them out and judge for yourself rather than relying on the opinion of third parties. I did indicate my favorite though - just like Dave did. :D

johnnylynx
- 26th January 2009, 03:17
I agree with with Dave, that is why I suggested that you try them out and judge for yourself rather than relying on the opinion of third parties. I did indicate my favorite though - just like Dave did. :D

I was going to try PDS...but the trial version doesn't support the 12F683. I will have to pick up some 12F675's or the 16F628A to try PDS out.

John.

johnnylynx
- 30th January 2009, 05:46
OK, I have PBP now...i've loaded it up and want to try programming in MPLAB IDE but using PBP.

I used the wizard to create the project, imported a pbp file...but the screen is blank.

Am I missing something? Can one create PBP files in MPLAB??

John.

mackrackit
- 30th January 2009, 05:51
Follow the instructions here.
http://www.melabs.com/support/mplab.htm

Works very well.
Just do not download the latest MPLAB. Use the one that came on the PBP disk.

g-hoot
- 31st January 2009, 13:11
You can set it up for an input from the beginning of the program then still use it later for programming. Just make sure your circuit will still allow the Vpp signal to control it during programming otherwise it will boop at you and report an error.

As a newbie, I was under the impression that the MCLR had to be pulled high when the circuit is powered up, but after reading a little more, I'm not sure. My circuit will have a switch that is either off or on at power up. I'm planning to pull a pin to ground if the switch is on and then I would use internal pull-ups on the pin when it is off. Since I don't program the chips on board, can I use the MCLR pin for the switch, or does it need to be high when the circuit is powered up? That would be awesome if I could free that pin up for use.
Gary

Melanie
- 31st January 2009, 13:24
On the 12F683, MCLR can be handled internally by the PIC (see CONFIG options in the PICs Datasheet), thereby freeing that pin for your use. (equally applies to 12F675 and 16F628 since they were mentioned earlier in this thread).

g-hoot
- 31st January 2009, 14:07
On the 12F683, MCLR can be handled internally by the PIC (see CONFIG options in the PICs Datasheet), thereby freeing that pin for your use. (equally applies to 12F675 and 16F628 since they were mentioned earlier in this thread).

Thank you Melanie,
I looked at the data sheet and see what you are saying. The one thing I'm still not sure about is if the MCLR pin has to be high when the circuit is powered up? If so, then my switch won't work since it may be pulling the pin to ground. This blurb from the PIC Basic Pro manual is what has me confused:


Make sure the /MCLR pin is connected to 5 volts either through some kind of voltage protected reset circuit or simply with a 4.7K resistor. If you leave the pin unconnected, its level floats around and sometimes the PICmicro MCU will work but usually it won=t. The PICmicro MCU has an on-chip power-on-reset circuit so in general just an external pull-up resistor is adequate.

Gary

Melanie
- 31st January 2009, 15:15
If you set the CONFIG for the PIC to handle MCLR internally, then FORGET about MCLR being high or low... it's all handled for you behind the scenes.

Thereafter the pin (that was formally the MCLR pin) is treated as a regular I/O (except that on some PICs it's INPUT ONLY - check with your PICs Datasheet).

If you need the pin to be normally HIGH and it's pulled down by your switch, then you need a PULL-UP Resistor (usually connected between the PIC pin concerned and +5V). Some PICs have internal Pull-Ups you can enable either on a pin-by-pin basis, or globally for an enitire Port. Again check with your Datasheet if the pin you want to use has Pull-Up's available on it - not all pins have them.

If you need the pin to be normally LOW and pulled-up by your switch (not a recommended way of connection - but it will work), then you need a PULL-DOWN Resistor (usually connected between the PIC pin concerned and 0v). You will have to provide one of those yourself externally as the PIC will not provide one internally. Any value between 4K7 and 22K would probably suffice.

g-hoot
- 31st January 2009, 15:25
If you set the CONFIG for the PIC to handle MCLR internally, then FORGET about MCLR being high or low... it's all handled for you behind the scenes.

Thereafter the pin (that was formally the MCLR pin) is treated as a regular I/O (except that on some PICs it's INPUT ONLY - check with your PICs Datasheet).

If you need the pin to be normally HIGH and it's pulled down by your switch, then you need a PULL-UP Resistor (usually connected between the PIC pin concerned and +5V). Some PICs have internal Pull-Ups you can enable either on a pin-by-pin basis, or globally for an enitire Port. Again check with your Datasheet if the pin you want to use has Pull-Up's available on it - not all pins have them.

If you need the pin to be normally LOW and pulled-up by your switch (not a recommended way of connection - but it will work), then you need a PULL-DOWN Resistor (usually connected between the PIC pin concerned and 0v). You will have to provide one of those yourself externally as the PIC will not provide one internally. Any value between 4K7 and 22K would probably suffice.

This is great news! Thank you for explaining it so well.
Gary