Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 29, 2024, 12:05:59 00:05


Login with username, password and session length


Pages: [1]
Print
Author Topic: Comparator PIC18F26K22 fro meausure Rise/fall time  (Read 3496 times)
0 Members and 1 Guest are viewing this topic.
Buddace
Inactive

Offline Offline

Posts: 2

Thank You
-Given: 0
-Receive: 5


« on: April 13, 2020, 09:25:40 09:25 »

Hi, my first topic.
I'm trying to measure rise fall time for a signal at 16K. Time measurement is defined between 2V and 5V for rise and vv for fall.
My idea is use comparator to detect level (2V and 5V) and generate interrupt to save TMR2 value. I'm using DAC to provide for  refer....but observed measured value are not dependent from signal (I'm using wave generator to test)..I think there is problem in interrupt management.

Code:
/*measure setup tu execute before every measure*/
void LnMeterTime_Setup(void)
{
    CM1CON0bits.C1CH = LnMeterSts_CONCh;
    Lm_Time_DATA_REDY = Lm_DATA_REDY_Empty;
    
    VREFCON2 = T_High_Th_DACR;
    CM1CON0bits.C1POL = TRUE;
    CM1CON0bits.CON = TRUE; /*Comparatore abilitato*/
    PIR2bits.C1IF = FALSE;
    PIE2bits.C1IE = TRUE;
}

Code:
/*Interrupt code*/
void LnMeterTimeMeasureIsr(void)
{
static BYTE TMR2_Old = 0;
static BYTE TMR2_Current = 0;
static BYTE temp = 0;
static RiseFallTimeSts_t RiseFallTimeSts = RiseFallTimeSts_Idle;

    TMR2_Current = TMR2;
    if(Lm_Time_DATA_REDY == Lm_DATA_REDY_Empty)
    {
        Lm_Time_DATA_REDY = Lm_DATA_REDY_Init;
        RiseFallTimeSts = RiseFallTimeSts_Init;
    }
    switch(RiseFallTimeSts)
    {
        case RiseFallTimeSts_Idle:
            break;

        case RiseFallTimeSts_Init: /*Cerco il fronte di discesa*/
            RiseFallTimeSts = RiseFallTimeSts_FallHigh_Th;
            VREFCON2 = T_High_Th_DACR;
            CM1CON0bits.C1POL = FALSE;
            break;
            
        case RiseFallTimeSts_FallHigh_Th: /*fronte di discesa trovato, cerco la soglia minima*/
            RiseFallTimeSts = RiseFallTimeSts_FallLow_Th;
            VREFCON2 = T_Low_Th_DACR;
            TMR2_Old = TMR2_Current;
            break;

        case RiseFallTimeSts_FallLow_Th: /*soglia minima trovata, cerco fronte di salita*/
            RiseFallTimeSts = RiseFallTimeSts_RiseLow_Th;
            T_Fall = (BYTE)(TMR2_Current - TMR2_Old);
            //lo č gią VREFCON2 = T_Low_Th_DACR;
            CM1CON0bits.C1POL = TRUE;
            
            break;
        case RiseFallTimeSts_RiseLow_Th: /*fronte di salita trovato, cerco soglia massima*/
            RiseFallTimeSts = RiseFallTimeSts_RiseHigh_Th;
            TMR2_Old = TMR2_Current;
            VREFCON2 = T_High_Th_DACR;
            break;
            
        case RiseFallTimeSts_RiseHigh_Th: /*soglia massima trovata*/
            RiseFallTimeSts = RiseFallTimeSts_End;
            T_Rise =(BYTE)(TMR2_Current - TMR2_Old);
            
            CM1CON0bits.CON = FALSE; /*Comparatore disabilitato*/
            PIE2bits.C1IE = FALSE;
            Lm_Time_DATA_REDY = Lm_DATA_REDY_Full;
            break;
            
        case RiseFallTimeSts_End: /*letture disponibili*/
 
            break;
            
        default:
            RiseFallTimeSts = RiseFallTimeSts_Idle;
            break;
    }
    
    temp = CM1CON0; /*clear latch*/
    PIR2bits.C1IF = FALSE;
}
« Last Edit: April 13, 2020, 09:56:39 09:56 by Buddace » Logged
future
Newbie
*
Offline Offline

Posts: 16

Thank You
-Given: 10
-Receive: 7


« Reply #1 on: May 18, 2020, 12:12:39 00:12 »

The rise time is probably too short to measure using interrupts. You should try polling the comparator flags.
Logged
Sideshow Bob
Cracking Team
Hero Member
****
Offline Offline

Posts: 972

Thank You
-Given: 230
-Receive: 959



« Reply #2 on: May 18, 2020, 08:14:23 08:14 »

Have you written a test program to ensure that the level detection is correct
Edit: Rise time is usually defined as the time required to transition between the 10% and 90% And if we asume a supply voltage of 5 volt. The upper limit should be 5*0.9 if you are pedantic
« Last Edit: May 18, 2020, 09:53:21 09:53 by Sideshow Bob » Logged

I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum
comlekciler
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 73
-Receive: 44

Ph.D.


« Reply #3 on: May 18, 2020, 09:51:00 09:51 »

I think, you should definitely use OPAMP instead of DAC to determine the voltage level.
Logged

...none...
Sideshow Bob
Cracking Team
Hero Member
****
Offline Offline

Posts: 972

Thank You
-Given: 230
-Receive: 959



« Reply #4 on: May 18, 2020, 10:29:32 10:29 »

I do not know exactly what you are doing in your system. But these links may provide some help
https://ww1.microchip.com/downloads/en/devicedoc/01146b.pdf
http://ww1.microchip.com/downloads/en/devicedoc/41214a.pdf
Logged

I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum
millegps
Newbie
*
Offline Offline

Posts: 34

Thank You
-Given: 38
-Receive: 3


« Reply #5 on: May 20, 2020, 06:34:26 18:34 »

I agree with comlekciler. With CCP your measurement can be very accurate, since timer update is triggered directly in hardware. Remember to take care about timer overflow.

You can do it in software or also by cascading timers. I'm pretty sure cascading is supported by some PIC, even if it's a bit I don't use them


I do not know exactly what you are doing in your system. But these links may provide some help
https://ww1.microchip.com/downloads/en/devicedoc/01146b.pdf
http://ww1.microchip.com/downloads/en/devicedoc/41214a.pdf

Nice documents with useful tips!
Logged
Catcatcat
Senior Member
****
Offline Offline

Posts: 416

Thank You
-Given: 275
-Receive: 1524



WWW
« Reply #6 on: May 22, 2020, 06:53:56 06:53 »

You have a CHARGE TIME MEASUREMENT UNIT (CTMU) module on the PIC18F26K22 that is designed to change nanosecond intervals, use it.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC