Autor Tema: dspic33ep128gm604 a veces funciona otras veces no  (Leído 1488 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado elianailoveyou

  • PIC10
  • *
  • Mensajes: 4
dspic33ep128gm604 a veces funciona otras veces no
« en: 28 de Marzo de 2016, 19:37:44 »
Al poner en funcionamiento un sencillo programa (prender led) en el dspic33ep128gm604 noto con desagrado, que no funciona. vuelvo a intentarlo, y después de muchas cortar y alimentar el dspic, FUNCIONA, Sin embargo vuelvo a cortar la alimentación, y este deja de funcionar, y asi sucesivamente.  :?. Por favor me podrían explicar porque sucede esto, y cual seria la solución.  :( obviamente necesito el dspic para una aplicación mas compleja que prender un led. Me he dado cuenta también, que cuando el dspic funciona el Vcap es de 1.8v (hasta 2.4 v según el datasheet), cuando deja de hacerlo el Vcap es de 3.3, tal vez por ahí este el error, pero no tengo idea de como resolverlo. otra cosa al quemar el mplab este graba normal, sin lanzar algún error. estoy usando el oscilador interno a 40MIPS.

Les dejo lo que programe en MPLAB

#include "xc.h"
#include <libpic30.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>


/* Configuration Bit Settings */
//_FOSCSEL(IESO_OFF & FNOSC_PRIPLL);
//_FOSC(FCKSM_CSDCMD & IOL1WAY_ON & OSCIOFNC_OFF & POSCMD_HS);
//_FWDT(FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR128 & WDTPOST_PS32768);

_FOSCSEL(FNOSC_FRC & IESO_OFF); //PWMLOCK_OFF necesario para q funcione el pwm correctamente
// Enable Clock Switching and Configure POSC in HS mode
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_NONE);
_FWDT(FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR128 & WDTPOST_PS32768); // Watchdog des-habilitado.
_FICD(JTAGEN_OFF & ICS_PGD2)


////_FPOR(PWMPIN_ON & HPOL_ON & LPOL_ON & ALTI2C_OFF & FPWRT_PWR128)
//
//_FICD(JTAGEN_ON & ICS_PGD2);
//_FBS(BSS_NO_FLASH & BWRP_WRPROTECT_OFF)
//_FGS(GCP_OFF & GWRP_OFF);

void Configuracion_40MIPS(void);
void config_io_digital(void);

int main(void) {
    config_io_digital();
    Configuracion_40MIPS();
    //        AD1PCFGL = 0xFFFF;
    _TRISB7 = 0;
    _LATB7 = 0;

    while (1) {
        _LATB7 = ~_LATB7;
        __delay32(4000000);
    }
    return 0;

}

void Configuracion_40MIPS(void) {


    // Configure PLL prescaler, PLL postscaler, PLL divisor
    PLLFBD = 41; // M = 43
    _PLLPOST = 0; // N2 = 2
    _PLLPRE = 0; // N1 = 2
    // Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
    __builtin_write_OSCCONH(0x01);
    __builtin_write_OSCCONL(0x01);
    // Wait for Clock switch to occur
    while (_COSC != 0b001);
    //  delay_ms(500);
    // Wait for PLL to lock
    while (_LOCK != 1) {
    };
}

////void Configuracion_40MIPS(void) {
//    CLKDIVbits.PLLPRE = 2; ///* N1 = 4    //CLKDIV = 0x0000; //N1=2 (factor de preescaler), N2=2(factor post-escaler)
//    PLLFBD = 30; // M=32. multiplica la entrada a PLL
//    CLKDIVbits.PLLPOST = 0; // /* N2 = 2 */
//    while (_LOCK == 0);
//}

void config_io_digital(void) { //COFIGURAR PINES DSPIC33EP
    ANSELA = 0x00;
    ANSELB = 0x00;
    ANSELC = 0x00;

}

« Última modificación: 29 de Marzo de 2016, 15:07:54 por elianailoveyou »

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:dspic33ep128gm604 a veces funciona otras veces no
« Respuesta #1 en: 29 de Marzo de 2016, 19:27:54 »
Parece todo bien.. no se para que tenes tantos includes cuando solo basta el de xc.h

el no tener el de libpic puede levantar un warning en el uso de _delay32() pero se puede usar.

Lo unico que no veo es donde definis la frecuencia para que se calcule el delay, es decir:

Código: C
  1. #define FCY 79220000UL

y tambien me parece raro la forma de los fuses. Ya que el mismo MPLAB X te lo saca asi:

fuses.c:
Código: C
  1. // DSPIC33EP128GM604 Configuration Bit Settings
  2.  
  3. // 'C' source line config statements
  4.  
  5. #include <xc.h>
  6.  
  7. // FICD
  8. #pragma config ICS = PGD2               // ICD Communication Channel Select bits (Communicate on PGEC2 and PGED2)
  9. #pragma config JTAGEN = OFF             // JTAG Enable bit (JTAG is disabled)
  10.  
  11. // FPOR
  12. #pragma config BOREN = ON               //  (BOR is enabled)
  13. #pragma config ALTI2C1 = OFF            // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
  14. #pragma config ALTI2C2 = OFF            // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
  15. #pragma config WDTWIN = WIN25           // Watchdog Window Select bits (WDT Window is 25% of WDT period)
  16.  
  17. // FWDT
  18. #pragma config WDTPOST = PS32768        // Watchdog Timer Postscaler bits (1:32,768)
  19. #pragma config WDTPRE = PR128           // Watchdog Timer Prescaler bit (1:128)
  20. #pragma config PLLKEN = ON              // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
  21. #pragma config WINDIS = OFF             // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
  22. #pragma config FWDTEN = OFF             // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)
  23.  
  24. // FOSC
  25. #pragma config POSCMD = NONE            // Primary Oscillator Mode Select bits (Primary Oscillator disabled)
  26. #pragma config OSCIOFNC = OFF           // OSC2 Pin Function bit (OSC2 is clock output)
  27. #pragma config IOL1WAY = OFF            // Peripheral pin select configuration (Allow multiple reconfigurations)
  28. #pragma config FCKSM = CSECME           // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are enabled)
  29.  
  30. // FOSCSEL
  31. #pragma config FNOSC = FRC              // Oscillator Source Selection (Internal Fast RC (FRC))
  32. #pragma config PWMLOCK = OFF            // PWM Lock Enable bit (PWM registers may be written without key sequence)
  33. #pragma config IESO = OFF               // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source)
  34.  
  35. // FGS
  36. #pragma config GWRP = OFF               // General Segment Write-Protect bit (General Segment may be written)
  37. #pragma config GCP = OFF                // General Segment Code-Protect bit (General Segment Code protect is Disabled)

Todo lo demas parece correcto, comenzando con FRC sin PLL, luego haciendo un cambio a FRC con PLL, como se escribe, los rangos de frecuencia, todo correcto. Incluso cree un pryecto apra compilarlo y que tiene 2 archivos, el main.c y el fuses.c que pase antes...

main.c
Código: C
  1. #include "xc.h"
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4.  
  5.  
  6. void Configuracion_Oscilador(void);
  7. void Configuracion_Pines(void);
  8.  
  9. int main(void)
  10. {
  11.     Configuracion_Pines();
  12.     Configuracion_Oscilador();
  13.    
  14.     while(1)
  15.     {
  16.         _LATB7 = ~ _LATB7;
  17.         __delay32(4000000);
  18.     }
  19.    
  20.     return 0;
  21. }
  22.  
  23. void Configuracion_Oscilador(void)
  24. {
  25.     /*
  26.      *  7.37Mhz Frc interno , entrada de frecuencia se cumple 0.8Mhz 8.0Mhz
  27.      *  Fin * M/N1 = Fvco = 158Mhz tambien se cumple , 120 a 340 Mhz
  28.      *  Fsalida = Fvco / N2 = 79.22Mhz  cumple con lo establecido, 15 a 120Mhz
  29.      */
  30.    
  31.     PLLFBD = 41;                // M = 43
  32.     _PLLPOST = 0;     // N1 = 2
  33.     _PLLPRE = 0;      // N2 = 2
  34.    
  35.     __builtin_write_OSCCONH(0x01);              // Nuevo oscilador en FRC con PLL
  36.     __builtin_write_OSCCONL(OSCCON | 0x01);     // Activo el bit para el cambio de oscilador
  37.    
  38.     // Esperamos el cambio de clock, es decir cuando el oscilador actual pase a ser el FRC con PLL
  39.     while (_COSC != 0b001);
  40.    
  41.     // Esperamos al PLL que se enganche
  42.     while (_LOCK != 1);
  43. }
  44.  
  45. void Configuracion_Pines(void)
  46. {
  47.     ANSELA = 0;
  48.     ANSELB = 0;
  49.     ANSELC = 0;
  50.    
  51.     _TRISC7 = 0;
  52.     _LATB7 = 0;
  53. }

El unico warning:
Código: [Seleccionar]
main.c:25:9: warning: implicit declaration of function '__delay32'
Y al menos en la simulacion funciona todo bien. Deberias revisar bien la conexion por las dudas.
« Última modificación: 30 de Marzo de 2016, 00:51:47 por KILLERJC »

Desconectado elianailoveyou

  • PIC10
  • *
  • Mensajes: 4
Re:dspic33ep128gm604 a veces funciona otras veces no
« Respuesta #2 en: 31 de Marzo de 2016, 17:35:11 »
Muchisimas gracias por el tiempo dedicado, me has aclarado varias dudas, solucione el problema revisando la hoja de datos del dspic y respetando las conexiones recomendadas. :lol: