external clock input to RC0/T1CKI on pic18f252 troubles


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2014
    Posts
    2

    Default external clock input to RC0/T1CKI on pic18f252 troubles

    hi all

    been having some ups and down with a frequency counter. i had it working taking an audio signal through a NPN pre-amp and then to a 741 config as a comparator. the op amp was powered by +/-4.5v from a 9v cell tapped with a gnu at the middle. this created a nice square wave output. when connected to the pic my code counted the frequency perfectly, using TMR1 as an asynchronous counter and TMR0 to create a 1 second delay in which i count the number of tmr1 overflows.

    basically, i wanted to make the fixtures a little more permanent and so replaced the 9v cell with a 7660S CPAZ to give my -ve rail and then integrated a dual op amp, config as a 20 gain amp and comparator. result - a nice -5v/+5v swing square wave. however the pic now does not recognise this as an external clock. and i scoped it before when it was connected. i can see a square wave at the RC0/T1CKI pin on the pic, the correct frequency, but it only runs from -0.6v to +4v now. i don't know if this is the problem. is there a certain format the ext clk is required to be for the input? I've even tried a ttl from a function generator but it doesn't like that either.

    i checked code in the xc8 sim and worked every time.

    below is code extract:
    #include <pic18f252.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <xc.h>
    #include <htc.h>
    #include <delays.h>
    #include <math.h>
    #pragma config WDT = OFF


    unsigned int tmr1_ovflow;
    unsignedint freq;


    /*****************************Timer1 overflow count**********************************/


    void high_ISR (void)
    {
    PIR1bits.TMR1IF = 0; //checks for Timer 1 rollover interrupt flag
    tmr1_ovflow=tmr1_ovflow + 1;
    }
    /*****************************1 Second Delay**********************************/
    void delay (void)
    {
    int i;
    i=0;
    do{


    T0CON = 0x87;
    // configure Timer 0 - select 16-bit mode,
    // internal clock source, enable 1:256 prescaler
    TMR0H = 0xA4;
    // load Timer 0 registers for 1 second delay
    TMR0L = 0x6D;
    INTCONbits.TMR0IF = 0;
    // make sure interrupt flag is reset
    while(!(INTCONbits.TMR0IF)); // wait until TMR0 rolls over
    i=i+1;
    }while(i<1);
    }
    /*****************************Frequency Counter**********************************/


    void freqcount ()
    {
    tmr1_ovflow = 0;
    freq = 0;
    TMR1H =0;// force Timer1 to count from 0
    TMR1L =0;
    PIR1bits.TMR1IF = 0;// clear Timer1 interrupt flag
    RCONbits.IPEN = 1;// enable priority interrupt scheme
    IPR1bits.TMR1IP = 1;// set Timer1 interrupt to high priority
    PIE1bits.TMR1IE = 1;// enable Timer1 roll-over interrupt
    T1CON = 0x87;// enable Timer1 with external clock, prescaler 1
    INTCON = 0xC0;// enable global and peripheral interrupts
    delay ();// start one-second delay and wait for interrupts
    INTCONbits.GIE = 0;// disable global interrupt
    freq = tmr1_ovflow * 65536 + TMR1H * 256 + TMR1L;
    // get the total Timer 1 count, i.e. calculate the frequency
    }

    any ideas? its driving me up the wall haha!

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: external clock input to RC0/T1CKI on pic18f252 troubles

    Hi,
    This forum isn't really about discussing issues with compilers/languages other than PBP but a quick glance at your code shows
    Code:
    T0CON = 0x87;
    // configure Timer 0 - select 16-bit mode,
    // internal clock source, enable 1:256 prescaler
    The value of 0x87 seems to correspond with the comment which probably isn't what you want to do if using an external clock source connected to T0CKI.

    /Henrik.

  3. #3
    Join Date
    Mar 2014
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: external clock input to RC0/T1CKI on pic18f252 troubles

    oh is it i didn't know the forum wasn't a generic one.

    oh thats fine its timer1 that is configured for ext clk. timer 0 still needs internal to give my 1 second delay. thanks for the reply though!

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: external clock input to RC0/T1CKI on pic18f252 troubles

    Argh, I read the thread title several times and STILL T0CKI.... Must have made a mixup with RC0....
    Sorry about the confusion, good luck!

    /Henrik.

Similar Threads

  1. Shiftin with external Clock howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st September 2011, 17:45
  2. Shiftin with external Clock howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th February 2011, 10:40
  3. Data Out From External Clock
    By Quin in forum Serial
    Replies: 2
    Last Post: - 25th October 2008, 10:11
  4. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 18:44
  5. External clock
    By Firegod in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2007, 01:53

Members who have read this thread : 1

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