1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

ECCP Pin do not work sometimes on my PIC microcontroller

Discussion in 'Microcontrollers' started by Pravin Gosavi, Feb 8, 2018.

  1. Pravin Gosavi

    Pravin Gosavi Member

    Joined:
    Nov 30, 2014
    Messages:
    135
    Likes:
    0
    Location:
    India
    Hello I want to generate PWM using ECCP of PIC16F1939 microcontroller. The two pins are supposed to generate waveforms alternately. ( I used pulse steering function of the ECCP module. For sometime the pulses are steered to one pin and for sometime to the other pin. ) The pins sometimes generate the waveform I desire perfectly. But sometimes only one pin generates the waveform and the other shows random noise and a voltage of about 1 to 3 volts.
    The pins used are RE1 (P3B) and RB5 (P3A) of ECCP3 module. I have turned comparators off. I have also used APFCON register. I cannot post whole program. Here is some part of initialisation :
    Code (c):

        OSCCON = 0X7A;    //16MHZ internal

        C1ON_bit = 0;
        C2ON_bit = 0;     // Disable Comparators

        APFCON = 0X50;    // Alternate Pin Function

        PR2 = 249;

        CCP3CON = 12;

        CCPR3L = 0;

        TMR2IF_bit = 0;
        T2CON = 0X04;
        while (TMR2IF_bit == 0);
        TMR2IF_bit = 0;

        LATA = 0X00;
        LATB = 0X00;
        LATC = 0X00;
        LATD = 0X00;
        LATE = 0X00;

        PORTA = 0X00;
        PORTB = 0X00;
        PORTC = 0X00;
        PORTD = 0X00;
        PORTE = 0X00;
     
        TRISA = 0XEF;          
        TRISB = 0X1F;
        TRISC = 0X18;
        TRISD = 0X00;
        TRISE = 1;

        TMR2IE_bit = 1;
        GIE_bit = 1;
        PEIE_bit = 1;
     
    After this I have used microC's internal function ADC_Init();
    and then infinite while loop.
    Any suggestions?
     
    Last edited by a moderator: Feb 8, 2018
  2. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,898
    Likes:
    126
    Location:
    Buenos Aires - Argentina
    ONLINE
    Have you checked the erratas for the micro in question? When I download the manual, immediately after, the erratas follow.

    In all micros I looked at, comparators appear mentioned. Have you also verified what other functions those pins are involved with?

    Make sure you initialize just the minimum necessary to verify how the EECP works. When a new piece of code is added you could eventually detect the offending setting.
     
  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,660
    Likes:
    409
    Location:
    Brisbane Australia
    It's not something silly like the WDT resetting the chip?

    Mike.
     
    • Like Like x 1
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,753
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    PWM reset??? This chip has an auto reset when used in enhanced mode!
     
  6. Pravin Gosavi

    Pravin Gosavi Member

    Joined:
    Nov 30, 2014
    Messages:
    135
    Likes:
    0
    Location:
    India
    My program is large so it will be a very lengthy process. But I will try it lastly.

    All other functions like reading ALL ADC pins working. I think they would not work in such a small time slot.

    What is the fix to it? Which register settings?
     
  7. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,753
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    CCPxAS register..
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  9. Pravin Gosavi

    Pravin Gosavi Member

    Joined:
    Nov 30, 2014
    Messages:
    135
    Likes:
    0
    Location:
    India
    I have configured CCPxAS register too as-
    CCP3AS= 0b01000000
    I have tested this when there's Logic 0 on INT Pin all pwm pins are in shutdown mode.
    In shuddown mode also the "affected" pin shows random voltage.
     
  10. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,753
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
  11. Pravin Gosavi

    Pravin Gosavi Member

    Joined:
    Nov 30, 2014
    Messages:
    135
    Likes:
    0
    Location:
    India
  12. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,753
    Likes:
    954
    Location:
    Rochdale UK
    ONLINE
    I just noticed..
    But P3B is on RE1... so shouldn't it be TRISE = 2...

    EDIT!!! Scratch that, It's me being a numpty.

    STR3B = STR3A = STR3SYNC = 1; seemed to work!!
     
    Last edited: Feb 13, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice