Internal oscillator and digital input

Discussion in 'Embedded Systems and Microcontrollers' started by trennonix, Jun 30, 2009.

  1. trennonix

    Thread Starter New Member

    Jun 6, 2009

    I'm trying to make 2 pics (12F675) communicate together, for that, i'm using the internal oscillator

    Is the internal oscillator imprecise?
    Because when i run my program, sometimes it works, then a couple of hours later, i run the same exact program on the same exact untouched chips, and it crashes :confused::confused:

    Now, in order to make the switch to an external oscillator (crystal) i need to rearrange my pinouts so that i have room for my crystal. In doing so, i need to take a digital input from an analogue pin, pin0.

    I'm programming in assembly and i don't know anything about ADC, plus, all i need is a simple digital input and i can't figure out how to do just that.

    Thanks alot.
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    What kind of protocol are you using to communicate?
  3. Vaughanabe13

    Active Member

    May 4, 2009

    The internal oscillator can be fast but it is usually not precise. You definitely need a crystal oscillator if you are doing any sort of timing-critical communication between devices. It wont be hard to implement this. Don't forget your load capacitors if you use a crystal or the crystal won't start up correctly (the crystal's datasheet can help with this).

    You can use any general purpose pin as a digital input, so don't worry about having to use GP0 as your input. If you are not using the ADC at all (which I assume you aren't), just clear the ANSEL register at the beginning of your program. This will set all of the analog pins (AN0, AN1, etc.) to digital logic and basically turn the ADC feature off. Then set the TRISIO register to specify which pins are inputs and which are outputs (0 for output, 1 for input). Check your data sheet for more info but that should get you started.

    Also remember to set any pins you are not using as an output. This will lower power consumption if/when you are running from a battery.

    Senior Member

    May 26, 2009
  5. millwood


    doesn't that chip have an external clock pin? no matter what clocks you use, as long as you use two of them, they will drift over long enough periods of time.

    so the only way to make sure that your devices can work reliably is to synchronize the clocks, or make a master / slave configuration.
  6. beenthere

    Retired Moderator

    Apr 20, 2004
    One sure method is to handshake the data across.
  7. n9352527

    AAC Fanatic!

    Oct 14, 2005
    The question is not how accurate the clock is, or whether both PICs can be run and synchronised using one clock source. It is more on what kind of protocol you are using. Like Beenthere said, you need to handshake the data either by using a clock line, or synchronise each packet transfer at the start of each packet (like RS232 start bit).

    No matter how accurate both clocks are, there are cases when those tx and rx process will be out of syncs and cause problems.

    Now, what kind of protocol are you using?