dsPIC33EP Timer differences
I'm facing somewhat a strange issue.
I have two parallel PIC on a board, each has an independent system clock source ASDMB-4.000MHZ-LC-T which is rated +/-50ppm, temperature on the board is homogenous.
The two PIC has the exact same hardware connected to it and runs both on the same code.
I trigger them for measurement (External ADC) at the same time through an I2C general instruction. The measurement is controlled by Timer1 configured for internal instruction clock.
The thing is, over a period of 200ms I get a drift of 1ms (approx 0.5%), very repeatable. The measurement at the start seems to be well synchronized so it doesn't seem to be related to trigger related delay.
Given the input clock source is given at 50ppm, I believe my clock source is stable. To add, T2 blink LED every second and it does not seem to drift.
I went through the code to check if anything would block the timer interrupt, but nothing there and the code is quite minimal. Flag is cleared as first interrupt instruction.
int FICD __attribute__((space(prog), address(0x157F0))) = 0xFFCF;
int FPOR __attribute__((space(prog), address(0x157F2))) = 0xFFDF;
int FWDT __attribute__((space(prog), address(0x157F4))) = 0xFF7F;
int FOSC __attribute__((space(prog), address(0x157F6))) = 0xFF58;
int FOSCSEL __attribute__((space(prog), address(0x157F8))) = 0xFFFB;
int FGS __attribute__((space(prog), address(0x157FA))) = 0xFFFF;
T1CONbits.TON = 0; // Disable Timer
T1CONbits.TCKPS = 0b00;
T1CONbits.TCS = 0; // Select internal instruction cycle clock
T1CONbits.TGATE = 0; // Disable Gated Timer mode
TMR1 = 0; // Clear timer register
PR1 = 400; // Ltime for 10us
_T1IP = 4; // Set Timer1 Interrupt Priority Level
_T1IF = 0; // Clear Timer1 Interrupt Flag
_T1IE = 1; // Enable Timer1 interrupt
T1CONbits.TON = 0;
// 4 Mhz Clock
CLKDIVbits.PLLPRE = 1;
PLLFBD = 178;
CLKDIVbits.PLLPOST = 0;
// Initiate Clock Switch to Primary Oscillator with PLL (NOSC = 0b011)
__builtin_write_OSCCONL(OSCCON | 0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC != 0b011);
// Wait for PLL to lock
while (OSCCONbits.LOCK != 1);
post edited by Blue_Key - 2019/08/21 06:02:54