Cant seem to get the internal osc to work 12f683

takao21203

Joined Apr 28, 2012
3,702
I thought I had remembered that this was the reset value. Double checking makes me realize it isn't.

OP: make sure you configure the pins as digital output pins through setting the ANSEL as takao suggested.
I looked the datasheet and there is the CLRF ANSEL clearly printed.

No pun intended- I know how it is simply not to notice some detail. One particular PIC bugged me a lot- I had the hardware debugger fuse ON and spent some hours without a clue (I never use hardware debugger).
 

Thread Starter

guitchess

Joined Dec 28, 2013
15
I haven't unchecked the Cal Osc. I am trying that as I type.

I have tried several times to clear ANSEL, but it has never had an effect. I assumed that was because I've set all available GPIO as output.

I have caps of all kinds. Where are you suggesting I put it? Rail to Rail?

Currently, I am burning the chip in a programmer then moving to the breadboard. I am not confident enough to start with ICSP.


#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown Out Detect (BOR enabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
 

takao21203

Joined Apr 28, 2012
3,702
PWRTE=ON // this is only for stabilization. Leaving it off should not cause osc failure.

BOREN=OFF // this can cause interrupts but power supply going down would be weird in normal daily life.

IESO=OFF // not needed

FCMEN=OFF // internal osc. is not so much supposed to fail, more designed for some distributed master clock which may fail.

But this should not make a difference for normal conditions.

PWRTE can't hurt and it's only a small delay.

Yes PIC boards should have a small cap rail to rail, especially with long wires. If you directly plug a FLASH writer it has a cap onboard.

I tried without cap. and sometimes it actually did not work.

For this purpose I keep a lot of very tiny 1uF caps. Sometimes a 100uF cap from a bag- they costed one or two cents, also very small.
 

Markd77

Joined Sep 7, 2009
2,806
Try setting CMCON0 to b'00000111'. I can't remember if the comparator needs turning off to use digital I/O on this chip but it can't hurt to try. Usually if the pin can power an LED then it has been set to output, which means code is being executed, but if some settings are wrong you might not have control of the pin.
 

Thread Starter

guitchess

Joined Dec 28, 2013
15
First of all, thank all of you for your time and help. I now have a successful blinking led. I haven't figured out exactly why yet, but the issue was my circuit.

I would appreciate any input you have on this. I was trying to feed voltage from the chip to the led to resistor to ground, which had no issues for a solid lit led. It didn't want to work if I set it to flash. Now I have voltage going to resistor to led to chip which turns the led on when I clear the pin. I'm not sure if that has something to do with pull up resisters or what.

Thanks for your input.
 

tshuck

Joined Oct 18, 2012
3,534
That is odd. If a rearrangement of parts fixes things, I'd bet on a wiring error.

However, there is merit in what Mark suggested, did you try that?
 
Last edited:

Thread Starter

guitchess

Joined Dec 28, 2013
15
I tried several methods of turning the comparators off, but they made no difference so I wasn't positive that I did it right. The data sheet Does say that that both the CMCON and ANSEL must be initiated if the pin is an input, but it doesn't seem to matter if an output.
 
Last edited:

Thread Starter

guitchess

Joined Dec 28, 2013
15
next step is to see if you can reproduce the issue.
I may be misunderstanding what you mean but after as many variations as I have tried over the last 24 hours, I'm quite sure that I can.

What I'm wondering is if the chip would drive an LED via transistor without this issue.

I just can't imagine why it had issues positively feeding the LED unless it has to do with the impedance. The resistor I am using is a 220 ohm with a 3 mm red LED
 

tshuck

Joined Oct 18, 2012
3,534
The problem with just trying combinations is that you never know if changing a bit changes the way another configuration works.

Try this code:
Rich (BB code):
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)

#define _XTAL_FREQ 4000000

#include <xc.h>

void Initialize();

void main(void) {
    OSCCON = 0b01100001;
    CMCON0 = 0b00000111;
    ANSEL = 0x00;
    TRISIO = 0x00;
 
    long count = 0;

    while(1){
        if (count > 50000)
            GP0 = 1;
        else
            GP0 = 0;

        count ++;
         if(count >= 100000){
            count = 0;
        }    
    }
}
As your code was before, you may have been reading from an analog pin (always reading 0), and inverting it to always output a high voltage.
 

Thread Starter

guitchess

Joined Dec 28, 2013
15
The problem with just trying combinations is that you never know if changing a bit changes the way another configuration works.
How right you are. After my success, a resurgence of enthusiasm kept me experimenting and I finally found the issue. It was my programming (and the fact that datasheets are far from noob friendly).

It turns out that my issue was two fold. First, both the ANSEL and CMCON0 registers have to be set to digital/turned off, even if the TRISIO is cleared. The only reference to this I found was describing input states. Apparently, I had either not tried both of these at the same time or set one of them improperly. In fact, I know that one of the methods I used for CMCON0 was incorrect.

Secondly, the code works in the MPLAB X sim without either of these registers being cleared, giving me a false sense of correctness.

Thanks again for every one's assistance.
 

tshuck

Joined Oct 18, 2012
3,534
Many simulators don't capture these odd points very well, eventually, you should debug the hardware (via ICSP), and not rely on software models.

So, does this mean it is working?
 

takao21203

Joined Apr 28, 2012
3,702
led's without impedanc resis are OK.
But shorts between pins or to power rails can cause heating, or port NOT TO FUNTION PROPERLY.

Over the years, I did observe a few latched chips- one bit cccorroding after some yearss. After making shorts or heating the chips too muh from desoldering, after some months a bit would latch.

But if you have spare bits on a nother port you only need to patch the firmware.

I have done it on my big matrix PCB, because I had no more blank chips of that type. Changed one IO bit

This is why I want to use external EEPROM with tables.

They control parts of the program, such as which IO bits to access for an external component.

II

Device descriptor table

This is a randomly sequence of pins, but later it is used ascending.

So, the PIC, even a 16F, gets additional external memory. Therefore the internal flash program space used ccan be less.

I successfully reduced my 16f57 matrix to only 66%, but the board broke...

Fried the cchips as it looks, one heats up, changed the SOIC28 IC but the serial RAM was fried too by a kead battery.

Just to show you, no resistors are OK.
 

Attachments

takao21203

Joined Apr 28, 2012
3,702
Yes I was worried about that too.

I researched for years what is the truth.

and I can present some hard facts about PICs:

I

The MOSFET resistance is about 40 Ohms equiv.

II

The max. current in the datasheet is voltage gap dependent.
It is for full short from H pin to GND.

II.1

A LED however has upto 20 Ohms resistance, and in addition, the gradient goes up with lower than nominal voltage.

Some work with less then 1mA and are still bright.

They are only on each for some milliseconds. Then they can cool a little.

III.

The power supply Vcc is near the nominal LED flux voltage. For instance 2.4 Volts batteries.

LED matrix works weeks with that.

I cut down unnecssary work steps in making proto circuits. Each time, less work.
 

JohnInTX

Joined Jun 26, 2012
4,787
NO! How many times must we tell you this is not okay!?
While some chips cannot provide enough current to fry a LED, this is not a hard-and-fast rule!
@takao21023: tshuck is absolutely correct here. Some CMOS logic can be used without LED resistors but not PICs. A few jabs at the 'Lil Professor confirms this using even your own questionable numbers. At Ron=40ohms, LED bulk resistance of 20ohms and Vf=1.5V, you ask better than 2X the 25ma Absolute Maximum Rating from the pin.

Setting that aside, you will run into r-m-w issues without solid logic levels on the output pins in midrange/baseline PICs. Always. Driving LEDs directly will not return solid levels during r-m-w.

I enjoy reading descriptions of your cool projects but I wonder if you've made the connection yet between ignoring documented limits of the parts you use and your detailed reports of their failures.
 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
@takao21023: tshuck is absolutely correct here. Some CMOS logic can be used without LED resistors but not PICs. A few jabs at the 'Lil Professor confirms this using even your own questionable numbers. At Ron=40ohms, LED bulk resistance of 20ohms and Vf=1.5V, you ask better than 2X the 25ma Absolute Maximum Rating from the pin.

Setting that aside, you will run into r-m-w issues without solid logic levels on the output pins in midrange/baseline PICs. Always. Driving LEDs directly will not return solid levels during r-m-w.

I enjoy reading descriptions of your cool projects but I wonder if you've made the connection yet between ignoring documented limits of the parts you use and your detailed reports of their failures.
I have run PICs for months even at 5 volts with LEDs.

My big 768 LED matrix is using 8 PICs to drive all the LEDs.

I understand the 20mA limit as such as this is what the PIC can provide with logic levels still within specifications.
 

JohnInTX

Joined Jun 26, 2012
4,787
I understand the 20mA limit as such as this is what the PIC can provide with logic levels still within specifications.
If you'll take a moment to read the gray box on the ratings image that tshuck so kindly provided, you'll see that its more than that. Just because the PIC doesn't burst into flames and run screaming off the PCB doesn't mean its not being degraded over time. It also doesn't mean that it everything inside will operate correctly. If you are doing one-off hobby-grade stuff, have at it but its unfair to counsel a newbie that its a good way to do things.

Plus, its the OP's thread.. I'm out
 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
If you'll take a moment to read the gray box on the ratings image that tshuck so kindly provided, you'll see that its more than that. Just because the PIC doesn't burst into flames and run screaming off the PCB doesn't mean its not being degraded over time. It also doesn't mean that it everything inside will operate correctly. If you are doing one-off hobby-grade stuff, have at it but its unfair to counsel a newbie that its a good way to do things.

Plus, its the OP's thread.. I'm out
I have used resistors + transistors for driving some years ago. It can be a lot of effort.

Especially when it is only a prototype or a circuit which runs sometimes for some hours, I don't see a reason why not.

Degrading over time, might be, as said, I have run tests over months.

If the circuit runs weeks from small batteries, the currents cant be that high. The average total current is 20mA maybe, not the current through one pin.
 

tshuck

Joined Oct 18, 2012
3,534
I have used resistors + transistors for driving some years ago. It can be a lot of effort.

Especially when it is only a prototype or a circuit which runs sometimes for some hours, I don't see a reason why not.

Degrading over time, might be, as said, I have run tests over months.

If the circuit runs weeks from small batteries, the currents cant be that high. The average total current is 20mA maybe, not the current through one pin.
Just because it works sometimes for a few months is not sufficient to say that it won't combust after 13 months.

The manufacturer has done stress tests with these chips - many, many of these chips - and noticed degredation/improper operation/bursting into flames and torching a house/stop working in a significant majority of them when operating above these maximum limits. That majority defines these maximum ratings.

In engineering(science) we do not design at the threshold of failure, but incorporate a decent margin of error, considering all of the variables involved with proper IC operation (temperature, operating voltage, etc.) and their effect on the quantum operations the ICs rely on. Exceeding these specifications without knowing what you are doing is gambling with the difference between proper operation and a flaming building.
 
Top