Oscillators, counts, clock cycles, config settings ......& women


Results 1 to 24 of 24

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Oscillators, counts, clock cycles, config settings ......& women

    Ok, so I put in 'women' to shamfully get a few more 'curiousity' hits - lol.

    Women are quite nice - I enjoy some aspects of them very much.

    Ok, that's that bit covered off. To the oscillator related stuff.

    In my cosy little noobesque world, I've until now being running nice copycat config settings with the internal oscillator @4Mhz. But alas, for my needs there wasn't enough resolution so I pushed th boat out & bought a 20Mhz cermaic resonator for the princely so of 20p (30c).

    I'm using a 16f690 - so connected the resonator to pins 2 & 3.

    Fine so what's the problem? Well, counting clock pulses is the problem....there doesn't seem to be enough of them!

    I'm using a 1Khz signal to 'trigger' a comparator internally withing my PIC, this in turn generates a comparator interrupt, which I've setup to start Timer1 running.

    When the next comparator trigger arrives (ie 1ms later for the 1khz signal I'm feeding into the comparator)...I store the timer1 count.

    With me so far?

    Ok, the count I'm getting is 2,500 (it's rock solid - that said if I change the input 'trigger' frequency the timer1 count moves, so this confirms the chain is all working !)

    But with a 20Mhz clock, I should be getting a whole heap more 'clock counts' between the comparator firing off successive interrupts.

    with a 1khz comparator input - by my calculations that should yield an interrupt every 1ms....so I worked out how many clocks there should be during that time (timer1 count). At 20Mhz there should be 20,000 rx'ed in 1ms.

    But I'm only seeing 2,500?!!!

    Now Jerson helpfully queried whether I had a prescaler set (x8 would tie up with what I'm seeing....I'm expecting the clock count to be 20,000, but I'm seeing 2,500) - I don't believe so.

    So how do I get to the bottom of this discrepancy?

    Is it a Osc config setting? (remember this is the first time I've used an External oSicllator - it's highly conceivable I've perhaps configured the PIC wrong). Here's my associated config (I use MPASM)....

    Code:
    @ __CONFIG _FCMEN_OFF & _HS_OSC & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF
    
    DEFINE  OSC 20          ' set Oscillator at 20Mhz
    OSCCON.0 = 0
    Is it a problem with my approach?

    Is it a problem with my maths?



    As an aside, is there a prescribed method for confirming the clock is running at the frequency you want it to run at?!!!

    Many thanks in anticipation!
    Last edited by HankMcSpank; - 13th September 2010 at 12:08.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts