PIC 12F675 calibrating internal frequency

Discussion in 'Embedded Systems and Microcontrollers' started by peter_morley, Aug 9, 2011.

  1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    I'm attempting to make a VGA controller and I want to improve upon my original shotty attempt at it. At this point I use two 555 timers to run hsync and vsync. Both have about 95% duty cycle. For my pixel clock I just loop in my pic program and toggle one of GPIO ports and that gives me about 100Khz. The display of color seems to be crawling up the screen and I believe it has something to do with my pixel clock speed. I'm quite excited that I have got this far in just displaying color but I want to improve upon it. Ultimately I need to calibrate the internal oscillation of my PIC. I have looked at designs online and they encompass using a 20-27MHz crystal connected to OSCCAL 1 and 2 to calibrate the PIC. I don't really understand how to setup my OSCCAL pins for correct calibration though, any suggestions? I know I want my osccal register to be set to HS so I can attain high frequency.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    At 5V the PIC 12F675 has a max operating frequency of 20MHz, so you best stick to that limit.

    Look at the data sheet for that part. Figure 9-1 shows how to add the crystal. In the config word you select for the HS crystal type per section 9.1
     
  3. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Thanks can I use a 4 pin oscillator that has everything it needs to function or do I need a crystal resonator that has only 2 pins? I'm confused on how to hook up a crystal oscillator that has 4 pins if it possible to do.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Any or all of these would work.

    An oscillator is good as it is a sealed tested working unit, very accurate frequency. It will still need a bypass cap.

    A crystal has just as accurate a frequency, needs two small caps to complete the stage. A PIC has the amp built in to handle these.

    A resonator is actually a different type, not quite as accurate as a crystal but still very good. These are 3 terminal devices as they are similar to crystals but also contain the two small capacitors.

    I have used all 3 methods and will try for using a resonator first. Only the time I needed very tight frequency I used an oscillator type.
     
  5. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Would I hook up my 4 pin oscillator like this? Picture is attached.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Drop that cap, your passing a digital signal (make sure you get an oscillator with a digital output).

    Do add a cap 0.1 or so across the oscillator supply.
     
  7. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    0.1nF or 0.1uF?
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    0.1 uF or 100nF (0.1uF=100nF) will be fine as decoupling capacitor. Use it on both the PIC and the OSC
     
  9. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Ok cool and this change in internal oscillation is directed towards instruction cycles or is this 20MHz output to a certain clock out? In other words are instruction cycles completed quicker in that one instruction cycle takes
    1/(20x10^6) seconds after calibration?
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The oscillator sets the internal heartbeat of the PIC. Instructions take 4 cycles to execute (excpeting those involving jumps which take 8) so the instruction frequency is 20/4 or 5MHz, or 1 instruction every .2 micro second (10-6).
     
  11. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    Hmmm, well thats not what I want because I need drive vga controller with a 20-25Mhz pixel clock. I'm going to have to think about how to do that. I want to generate pixels to the screen at a rate of 20MHz to complete 60 frames per second.
     
  12. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    So basically you need 25*60*(instructions needed for each pixel).
    The pic you are using is way under the specifications you need. Actually the best pics (PIC32) are still not enough for those speeds.
    Maybe with a FPGA you can get those results.
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
  14. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    I'm still having trouble configuring my HS setup. In the data sheet I need to add this word to config but I dont know how. 010 = HS oscillator: High speed crystal/resonator on GP4/OSC2/CLKOUT and GP5/OSC1/CLKIN. I don't know how initialize my FOSC to 010 which is the bit setup for HS. Once I have done this CONFIG adjustment will my program automatically start running cycles at 20MHz if I use a 20 MHz crystal oscillator?
     
Loading...