Can not get PIC18F14K50 Special Event Trigger to work

Author
DavidEGrayson
Super Member
  • Total Posts : 108
  • Reward points : 0
  • Joined: 2009/01/08 01:16:58
  • Location: Las Vegas, NV
  • Status: offline
2009/03/20 11:13:20 (permalink)
0

Can not get PIC18F14K50 Special Event Trigger to work

I have a Low Pin Count USB Development Kit with a PIC18F14K50 microcontroller on it, and I am programming it using the MPLAB REAL ICE.

I am trying to take AD conversions at regular intervals using the "Special Event Trigger" described in Chapter 14 of the PIC18F14K50 datasheet. The Special Event Trigger is a feature of the Enhanced Capture/Compare/PWM (ECCP) module, where during compare mode, the ECCP is supposed to trigger an AD conversion every time the comparison succeeds (i.e. the comparison registers match the selected timer).

Here is the C code I wrote, that I expect to work but doesn't:


#include <p18f14k50.h>

// Configuration bits for the Low Pin Count Development Kit
#pragma config CPUDIV=NOCLKDIV, USBDIV=OFF
#pragma config IESO=OFF, FCMEN=OFF, PCLKEN=ON, PLLEN=ON, FOSC=HS
#pragma config PWRTEN=OFF, BOREN=OFF, BORV=30
#pragma config WDTEN=OFF
#pragma config LVP=ON, XINST=OFF

// Hardware on the Low Pin Count Development Kit
#define LED0 LATCbits.LATC0
#define LED1 LATCbits.LATC1

#define TRIS_LED0 TRISCbits.TRISC0
#define TRIS_LED1 TRISCbits.TRISC1

void main()
{
// LED0 and LED1 start off
TRIS_LED0 = 0;
TRIS_LED1 = 0;
LED0 = 0;
LED1 = 0;

// Configure RC5/CCP1/P1A to be an output, as it says to do in Section 14.3.1 of the data sheet
TRISCbits.TRISC5 = 0;

// Configure RB4/AN10 to be an analog input (that's the trimpot)
ANSELHbits.ANS10 = 1;
TRISBbits.TRISB4 = 1;

// Configure the ADC
ADCON1 = 0; // reference voltages are VDD and VSS
ADCON2 = 0b00111110; // FOSC/64, 20 TAD
ADCON0 = 0b00101001; // Enable ADC, select channel 10

// Configure Timers
T1CON = 0b10110001; // timer 1 enabled, prescaler 1:8, 16-bit read/writes
T3CON = 0; // timer 1 is the source for ECCP1

// Configure the ECCP
CCPR1H = 0xFF;
CCPR1L = 0xFF;
CCP1CON = 0b00001011; // start AD conversion on successful compare (TMR1L==CCPR1L and TMR1H==CCPR1H)

// If I uncomment this line, then one AD conversion will be
// done, so the LED1 will turn on once and stay on.
//ADCON0bits.GO = 1;

while(1)
{
// The compare module triggers every .044 seconds.
// When that happens, it sets PIR1bits.CCP1IF. So you will see LED0
// toggle 23 times per second.

if (PIR1bits.CCP1IF)
{
PIR1bits.CCP1IF = 0;
LED0 = !LED0;
}

// Also, when the compare module triggers, it SHOULD start an AD conversion,
// and when that is done, the ADC module should set PIR1bits.ADIF.
// So LED1 should be toggling also, but it does not.

if(PIR1bits.ADIF)
{
PIR1bits.ADIF = 0;
LED1 = !LED1;
}
}
}


When I load the program above on to my PIC18F14K50, I expect to see LED0 and LED1 toggling 23 times for second. But I only see LED1 toggling.

I have attached the MPLAB Project, C source code, and precompiled HEX file for this program. It would be great if someone can look at it and tell me what I'm doing wrong, or tell me if this is a confirmed problem with the PIC18F14K50!

Thanks!

--David Grayson
#1

4 Replies Related Threads

    spotty
    Super Member
    • Total Posts : 280
    • Reward points : 0
    • Joined: 2008/04/03 11:15:31
    • Location: 0
    • Status: offline
    RE: Can not get PIC18F14K50 Special Event Trigger to work 2009/03/20 15:13:46 (permalink)
    0
    What's the default ( after reset ) value of ANS Bit 5, Port C1 ??
    I don't think Microchip really meant to say the acquisition time is 7 Mega Seconds, I think it's it's a typo for 7uSec. Even at 48MHz, a value of 20 is a 'TAD' high. Try 64/6 .
    #2
    DavidEGrayson
    Super Member
    • Total Posts : 108
    • Reward points : 0
    • Joined: 2009/01/08 01:16:58
    • Location: Las Vegas, NV
    • Status: offline
    RE: Can not get PIC18F14K50 Special Event Trigger to work 2012/11/26 15:33:20 (permalink)
    0
    Apparently the problem I was experiencing (back in March 2009!) is an actual problem with the PIC18F14K50.  It is listed as a known problem in section 9.1 of Revision H of the PIC18(L)F1XK50 Silicon Errata and Data Sheet Clarification, which was published in November 2012.  According to that document, the problem is fixed in the A8 and B0 silicon revisions, so that is good news.
     
    --David
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: Can not get PIC18F14K50 Special Event Trigger to work 2012/11/27 01:23:39 (permalink)
    0
    thanks for reporting Smile

    GENOVA :D :D ! GODO
    #4
    vloki
    Jo, alla!
    • Total Posts : 6784
    • Reward points : 0
    • Joined: 2007/10/15 00:51:49
    • Location: Germany
    • Status: offline
    RE: Can not get PIC18F14K50 Special Event Trigger to work 2012/11/27 02:08:51 (permalink)
    0
    Yes, good news. Thank you.
    (Last year we had same problem with this chip and special even trigger)

    Uffbasse !
    #5
    Jump to:
    © 2018 APG vNext Commercial Version 4.5