doubts about PIC microcontrollers

BobTPH

Joined Jun 5, 2013
8,813
And the reason you would not want to used it as an output, is that the programmer will put about 12V on it, which would wreak havoc with any logic connected to it.

Bob
 

BobTPH

Joined Jun 5, 2013
8,813
Thanks a lot; I was already giving it for impossible and looking for ways to just write the whole word every time.

I set the port to digital and now is working without problems. But why this didn't happen with the other PIC; nor with any other example I saw, since I never saw one using ANSEL first?
Don't imagine it is fixed yet.
If you are running at a high speed and you set a bit on PORTx in adjacent instructions, you still might see it misbehave. The only safe way to write to PORTx on PICs without a LATx is to keep a shadow register that contains all of the output bits set properly and copy that to the PORT.

So, to write a bit to the port you would:

ShadowA |= 1 << BITNUM;
PORTA = ShadowA

Or to clear on:

ShadowA &= ~(1 << BITNUM);
PORTA = ShadowA;


Bob
 

Thread Starter

adam555

Joined Aug 17, 2013
858
See the documentation.
RA5 can be used only as input.
Yes, you're right. Thanks for that.

Don't imagine it is fixed yet.
If you are running at a high speed and you set a bit on PORTx in adjacent instructions, you still might see it misbehave. The only safe way to write to PORTx on PICs without a LATx is to keep a shadow register that contains all of the output bits set properly and copy that to the PORT.

So, to write a bit to the port you would:

ShadowA |= 1 << BITNUM;
PORTA = ShadowA

Or to clear on:

ShadowA &= ~(1 << BITNUM);
PORTA = ShadowA;

Bob
That's what I was planning to do, but then I found about setting the outputs to digital and it worked fine; since I'm changing the values of the outputs at speeds I can see through the LEDs.

Thanks, I'll use that sample code for fast assignment.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Hi again,

I already came across a PIC that will not run with the PICkit2; and it's precisely the one I was going to use for the project. It seems that for some reason the PIC16F1459 is one of the odd few 16F PICs that needs the PICkit3. I was really pissed off yesterday night thinking that I had to buy the PICkit3 so soon. But fortunately I reconsidered this morning and realized that I just need another chip, not another programmer.

Anyway, I have 3 doubts...

1 - Why do some programs get stuck on a power off or brownout and some don't?

2 - Do you need to save the oscilloscope calibration settings before using a PIC for the first time? I'm asking because I read that all chips are calibrated by the manufacturer, and that these settings are lost when you erase the chip... and you erase it every time you program it; don't you?

3 - How do you isolate the PGD and PGC pins when also using them as I/O without disconnecting the programmer? For example: the chip I'm using has the programming data and clock on pins 13 and 12 respectively; but those pins are also the I/O pins RB7 and RB6 from port B, and I have a LED on each for my application. If I don't remove the LEDs, the programmer is unable to even detect the device; and if I add an isolation resistor to each LED (as the manual recommends) then those 2 LEDs get no current or et least less than the other 6 from port B. So, what's the right way to isolate those 2 pins between my application and the programmer? Do I have no choice but to remove the LEDs every time I program it?

Thanks,
 

jpanhalt

Joined Jan 18, 2008
11,087
The 16F1459 is an enhanced mid-range core device. That is, it is one of the newer chips and has an extended instruction set from the older 16Fxxx chips.

The internal oscillator is described in Section 5.0 . Factory tuning is not affected by clearing the chip, as was the case in some of the older mid-range chips like the 12F509.

Capture.PNG

Capture1.PNG

Note that the factory value for the register bit <6-0> is b'0000000'.

John
 

NorthGuy

Joined Jun 28, 2014
611
I already came across a PIC that will not run with the PICkit2; and it's precisely the one I was going to use for the project.
Who would've thought ...

So, what's the right way to isolate those 2 pins between my application and the programmer? Do I have no choice but to remove the LEDs every time I program it?
If you want to drive LEDs with these pins, a good idea is to use a small BJT such as 3904. This way you only need few mA of current. Connect 1-2K resistor to the base, connect emitter to the ground, and connect the LED along with current-limiting resister between collector and Vdd.

Unless you're running out of pins the best idea is to avoid using these pins.
 

BobTPH

Joined Jun 5, 2013
8,813
Did you try the PICKIT 2 stand alone app? It supports a lot of PICs that are not supported in MPLAB. I use the pic12f1840 and the pic16f1507, both of which are enhanced midrange and are supported by the stand-alone app but not by MPLAB.

That said, I just finally broke down and ordered a PICKIT 3 because I am starting a big project that I will want to use in-circuit debug though MPLAB.

Bob
 

Thread Starter

adam555

Joined Aug 17, 2013
858
If you want to drive LEDs with these pins, a good idea is to use a small BJT such as 3904. This way you only need few mA of current. Connect 1-2K resistor to the base, connect emitter to the ground, and connect the LED along with current-limiting resister between collector and Vdd.

Unless you're running out of pins the best idea is to avoid using these pins.
More than running out of pins, I was trying to keep a group of 8 LEDs on the same port; as I can't do it on the other port (A) because it also has some input only pins.

In any case, I was mainly asking just to learn how to isolate the programmer from my app.

Did you try the PICKIT 2 stand alone app? It supports a lot of PICs that are not supported in MPLAB. I use the pic12f1840 and the pic16f1507, both of which are enhanced midrange and are supported by the stand-alone app but not by MPLAB.

That said, I just finally broke down and ordered a PICKIT 3 because I am starting a big project that I will want to use in-circuit debug though MPLAB.

Bob
It doesn't recognize the PIC16F1459. I also tried to select it manually but it was not on the list.

I also had my order ready for the PICkit3 this morning, but then I decided to just get another chip with USB; so I ordered a PIC18F4550 instead -after making sure it's supported by the PICkit2-.
 

NorthGuy

Joined Jun 28, 2014
611
More than running out of pins, I was trying to keep a group of 8 LEDs on the same port; as I can't do it on the other port (A) because it also has some input only pins.
Is there any particular reason you want to keep 8 LEDs on the same port? It shouldn't be a problem to control LEDs from different ports.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Is there any particular reason you want to keep 8 LEDs on the same port? It shouldn't be a problem to control LEDs from different ports.
I just find it faster and simpler to assign the LED patterns to display if they are on the same port; I just assign an unsigned char to the port and that's it. With two ports I would need to assign the patterns twice.
 
Last edited:

NorthGuy

Joined Jun 28, 2014
611
I just find it faster and simpler to assign the LED patterns to display if they are on the same port; I just assign an unsigned char to the port and that's it. With two ports I would need to assign the patterns twice.
Unless you have a need for speed (couldn't be the case with LEDs), assigning twice (or even every bit separately) is easier/cheaper than adding extra circuity to the board.
 

Thread Starter

adam555

Joined Aug 17, 2013
858
Unless you have a need for speed (couldn't be the case with LEDs), assigning twice (or even every bit separately) is easier/cheaper than adding extra circuity to the board.
True, so what I'm doing is to temporarily disconnect the 2 LEDs on the PGD and PGC pins while programming and testing.

I have another doubt regarding this issue...

I need two pins more for digital inputs, but one of the two available is an "open drain" and the other is multiplexing with the "MCLR"; can these be pins be used, and if so, do I have to take any measure or precautions?
 
Top