Continue to Site

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.

  • 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.

ECCP Pin do not work sometimes on my PIC microcontroller

Status
Not open for further replies.
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 :
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:
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.
 
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.
My program is large so it will be a very lengthy process. But I will try it lastly.

It's not something silly like the WDT resetting the chip?

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

PWM reset??? This chip has an auto reset when used in enhanced mode!
What is the fix to it? Which register settings?
 
What is the fix to it? Which register settings?
CCPxAS register..
datasheet page234 said:
bit 7 CCPxASE: CCPx Auto-Shutdown Event Status bit
1 = A shutdown event has occurred; CCPx outputs are in shutdown state
0 = CCPx outputs are operating
bit 6-4 CCxPAS<2:0>: CCPx Auto-Shutdown Source Select bits
000 = Auto-shutdown is disabled
001 = Comparator C1 output low(1)
010 = Comparator C2 output low(1)
011 = Either Comparator C1 or C2 low(1)
100 = VIL on INT pin
101 = VIL on INT pin or Comparator C1 low(1)
110 = VIL on INT pin or Comparator C2 low(1)
111 = VIL on INT pin or Comparator C1 or Comparator C2 low(1)
bit 3-2 PSSxAC<1:0>: Pins PxA and PxC Shutdown State Control bits
00 = Drive pins PxA and PxC to ‘0’
01 = Drive pins PxA and PxC to ‘1’
1x = Pins PxA and PxC tri-state
bit 1-0 PSSxBD<1:0>: Pins PxB and PxD Shutdown State Control bits
00 = Drive pins PxB and PxD to ‘0’
01 = Drive pins PxB and PxD to ‘1’
1x = Pins PxB and PxD tri-state
Note 1: If CxSYNC is enabled, the shutdown will be delayed by Timer1
 
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.
 
I just noticed..
TRISE = 1;

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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top