electroman2000
Member level 2
- Joined
- Feb 3, 2015
- Messages
- 44
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Activity points
- 496
Hi everyone, I have just moved from mikroC to MPLAB X IDE with XC32 programmer. I'm trying to make the simply LED blinking code. The problem is the blinking is faster than expected.
This is the code:
I'm using the easyPIC fusion v7 board. The same program written in mikroC works well. The PIC32MX795 is connected to 8 Mhz external clock. The #pragma configuration is the same that I set in mikroC.
The problem is that the LED blinking every about 1 second instead of 5 seconds.
What I'm wrong?
Thank you very much
This is the code:
Code:
#include <p32xxxx.h>
#include <plib.h>
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
// PIC32MX795F512L Configuration Bit Settings
// 'C' source line config statements
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider (PLL Divide by 1)
// DEVCFG1
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = XT // Primary Oscillator Configuration (XT osc mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config FWDTEN = ON // Watchdog Timer Enable (WDT Enabled)
// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
void DelayMs(WORD delay)
{
T1CONbits.ON=1; // timer1 ON
while( delay-- ) // do this cycle for a number of 1 ms interrupt egual to delay
{
while(IFS0bits.T1IF==0){}; //wait until 1 ms interrupt
IFS0bits.T1IF=0; // clear flag
while(IFS0bits.T1IF==1){}; // if flag is cleared, go on
}
T1CONbits.ON=0; // timer1 OFF
}
int main(int argc, char** argv) {
SYSTEMConfigPerformance(80000000L);
CheKseg0CacheOn();
mCheConfigure(CHE_CONF_WS2 | CHE_CONF_PF_C);
AD1PCFG = 0xFFFF; // Configure AN pins as digital I/O
DDPCONbits.JTAGEN = 0; // disable the JTAG port
// Configurazione interrupt del timer
T1CONbits.ON=0; // timer1 OFF
T1CONbits.TCKPS=0b00; // prescaler=1 (T1CON <5-4>) , period 1/80 Mhz = 12,5 ns
T1CONbits.TCS=0; // internal clock
TMR1=0; // initial value of timer=0
PR1=80000; // PR set for 1 ms interrupt
IPC1bits.T1IP=0b101; // interrupt priority set to 5 ( IPC1 <4-2> )
IEC0bits.T1IE=1; // generate interrupt if T1IF=1
IFS0bits.T1IF=0; // overflow flag.
TRISB = 0; // Initialize PORTB as output
LATB = 0; // Set PORTB to zero
while(1) {
PORTBINV=0xFFFF; // invert PORTB
DelayMs(5000); // wait 5 seconds
}
return (EXIT_SUCCESS);
}
I'm using the easyPIC fusion v7 board. The same program written in mikroC works well. The PIC32MX795 is connected to 8 Mhz external clock. The #pragma configuration is the same that I set in mikroC.
The problem is that the LED blinking every about 1 second instead of 5 seconds.
What I'm wrong?
Thank you very much