Hot!dsPIC33EP: Input Capture at Low Frequency..

Author
TS9
Super Member
  • Total Posts : 441
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2018/01/10 23:12:45 (permalink)
0

dsPIC33EP: Input Capture at Low Frequency..

Dear All,
 
I am using dsPIC33EP512MU810 for Input Capture running 60MHz with Timer 3 .
Code working fine above 1KHz. Means Frequency 1KHz shown on 1KHz on LCD.
 
I have unable modify code for 10Hz to 250Hz . Is it possible to modify for such a low frequency for Input Capture ?
Please Check attachment..
 
--
TS9
post edited by TS9 - 2018/01/10 23:13:53
#1

18 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 05:00:57 (permalink)
    0
    • The easy way: use the prescaler to scale the clock down to not more than 600 kHz.
    • The difficult way: stay with 60 MHz and count timer rollovers.

    Most times the bug is in front of the keyboard.
    #2
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 06:03:21 (permalink)
    0
    Thanks for Update..
     

    • The easy way: use the prescaler to scale the clock down to not more than 600 kHz.

    How to slow down and calculate clock (For 600KHz) ? 
     

     
    void Timer3Init(void)
    {
    TMR3 = 0;
    T3CONbits.TON = 0;
    T3CONbits.TCS = 0; // Set Timer freq = Fcy/2
    T3CONbits.TCKPS = 0; // prescale 1:1
    T3CONbits.TGATE = 0;
    T3CONbits.TSIDL = 0;
    T3CONbits.TON = 1; //Timer 3 Enable
    }
     

    #3
    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 06:29:23 (permalink)
    0
    Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.

    Most times the bug is in front of the keyboard.
    #4
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 09:05:39 (permalink)
    0
    du00000001
    Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.

    OK..
    Means TCKPS= 0x11 will solve the issue?
    With Fosc= 60MHz.

    What will be Mathematical Expression Counts/Frequency from cap2 - cap1 in code as attachment in Msg # 1 ?
    #5
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 09:10:20 (permalink)
    0
    du00000001
    Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.

    OK..
    Means TCKPS= 0x11 will solve the issue?
    With Fosc= 60MHz.

    What will be Mathematical Expression Counts/Frequency from cap2 - cap1 in code as attachment in Msg # 1 ?
    #6
    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 09:20:38 (permalink)
    0
    frequency = ((60000000/256)/counts);

    Most times the bug is in front of the keyboard.
    #7
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/11 09:22:07 (permalink)
    0
    Thanks...
    #8
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 04:33:04 (permalink)
    0
    I have tested on Setup. "Count" variable overflow below 100Hz.


    Any Solution for that..?
    post edited by TS9 - 2018/01/12 08:05:04
    #9
    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 11:46:08 (permalink)
    0
    Overflow below 100 Hz ? Impossible if everything is set up accordingly.
    60 MHz / 256 = 234375 Hz count rate. Will overflow @ about 3.6 Hz.
     
    Check where the overflow occurs! The prescaler might be wrong.

    Most times the bug is in front of the keyboard.
    #10
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 16:00:14 (permalink)
    0
    Thanks for update..
     
    1)
    My "Count" variable is unsigned int and 234375 is greater than 65536.
    2)
    Also check my OSCInit().
    3)
    // Period = (1/FREQ) / (1/Fosc/2)
    // FREQ = (Fosc/2)/Period
    // Fosc/2 = 120MHz/2 = 60MHz
     
    Something might be wrong here.

     
    unsigned int cap1; // first capture variable
    unsigned int cap2; // second capture variable
    char results[100];
     
    void Timer3Init(void)
     
    {
    TMR3 = 0;
    T3CONbits.TON = 0;
    T3CONbits.TCS = 0; // Set Timer freq = Fcy/2
    T3CONbits.TCKPS = 0x11; // prescale 1:256
    // T3CONbits.TCKPS = 0; // prescale 1:1
    T3CONbits.TGATE = 0;
    T3CONbits.TSIDL = 0;
    T3CONbits.TON = 1; //Timer 3 Enable
    }
     
     
     
    void __attribute__ ((__interrupt__, no_auto_psv)) _IC1Interrupt(void)
    {
    cap1 = IC1BUF; // Read and save off first capture entry
    cap2 = IC1BUF; // Read and save off second capture entry
    LED2 ^= 1;
    IFS0bits.IC1IF = 0 ; // Reset respective interrupt flag
    }
     
    // To Run Oscillator 120MHz
    void OSCInit(void)
    {
    // Configure PLL prescaler, PLL postscaler, PLL divisor
    // ((8Mhz / N1) x 60) / N2 = 120Mhz
    // FOSC = 120Mhz
    // Fcy = 120Mhz/2 = 60Mhz = 60MIPS

    PLLFBD = 58; // M=60
    CLKDIVbits.PLLPOST=0; // N2=2
    CLKDIVbits.PLLPRE=0; // N1=2

    // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONH(0x03);
    __builtin_write_OSCCONL(OSCCON | 0x01);

    // Wait for Clock switch to occur
    while (OSCCONbits.COSC!= 0b011);

    // Wait for PLL to lock
    while (OSCCONbits.LOCK!= 1);
    }
     

    Will overflow @ about 3.6 Hz.
    How you calculate overflow @3.6Hz ?
    Please See entire code...as attachment ..
    post edited by TS9 - 2018/01/12 16:24:04
    #11
    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 17:10:59 (permalink)
    0
    234375 is the timer/s frequency. Overflow will happen @ 65536/234375 - roundabout 3.6 (Hz).
     
    Or simply derived from your statement that you are able to measure 1 kHz with 60 MHz timer clock.
    Thus 60 MHz/256 clock result in a min. frequency of 1000/256 Hz.
     
    Is that really so difficult to get?

    Most times the bug is in front of the keyboard.
    #12
    NorthGuy
    Super Member
    • Total Posts : 4675
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 18:35:02 (permalink)
    0
    You can also use 32-bit input capture. They call it "cascade mode" in the docs.
    #13
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 21:26:31 (permalink)
    0
    Thanks

    @du00000001..
    Difficult to correlate What I am getting on 1KHz and 100Hz ?

    @NorthGuy..
    Is there any Example program for that.?
    #14
    NorthGuy
    Super Member
    • Total Posts : 4675
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/12 22:52:39 (permalink)
    0
    TS9
    @NorthGuy..
    Is there any Example program for that.?



    There's an FRM chapter on Input Capture:
     
    http://ww1.microchip.com/...eviceDoc/70000352D.pdf
    #15
    du00000001
    Just Some Member
    • Total Posts : 1475
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/13 03:04:42 (permalink)
    0
    @ 100 Hz you'll get a count of 2343, @ 1 kHz one of 234 (give or take on due to signal synchronization).

    Most times the bug is in front of the keyboard.
    #16
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/13 04:55:32 (permalink)
    0
    @du00000001...

    I will check then update to you tomorrow.
    #17
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/13 04:56:02 (permalink)
    0
    Repeated
    post edited by TS9 - 2018/01/13 05:23:23
    #18
    TS9
    Super Member
    • Total Posts : 441
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Input Capture at Low Frequency.. 2018/01/13 04:56:03 (permalink)
    0
    Repeated
    post edited by TS9 - 2018/01/13 05:23:44
    #19
    Jump to:
    © 2018 APG vNext Commercial Version 4.5