Autor Tema: Iniciando pic32MZ  (Leído 15196 veces)

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

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Iniciando pic32MZ
« en: 07 de Diciembre de 2014, 04:43:04 »
Hola amigos, se está llevando un hilo respecto a los pic32mz y no quiero desvirtuarlo.
Lo que me pasa es que tengo pic32MZ2048ECG100 y no logra hacer que oscile el PORTD.

He probado el multiplicador con varios valores, y nada. Ni siquiera pone el PORTD a cero, es decir no arranca el pic.

Qué debo hacer o en que estoy fallando. El codigo es el siguiente:

Código: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <xc.h>
  4.  
  5. #pragma config POSCMOD = OFF // External Clock Mode
  6. #pragma config FNOSC = SPLL // System Clock is through System PLL
  7. #pragma config FPLLICLK = PLL_FRC // Input to PLL is from Primary Oscillator
  8. #pragma config FPLLIDIV = DIV_1 // Divide input by 3
  9. #pragma config FPLLRNG = RANGE_5_10_MHZ // Input to PLL will be in 5-10 MHz range after division
  10. #pragma config FPLLMULT = MUL_10 // Multiply frequency by 50
  11. #pragma config FPLLODIV = DIV_2 // Divide VCO output by
  12. #pragma config FWDTEN = OFF
  13.  
  14.  
  15. int main(int argc, char** argv) {
  16.  
  17.     unsigned short cont = 0;
  18.     unsigned short i = 0;
  19.  
  20.     TRISD = 0;
  21.     LATD = 0;
  22.    
  23.     while(1)
  24.     {
  25.  
  26.         if(++cont > 0xFF)
  27.         {
  28.             cont = 0;
  29.             if(i)
  30.             {
  31.                 LATD = 0;
  32.                 i = 0;
  33.             }
  34.             else
  35.             {
  36.                 LATD = 0xFFFF;
  37.                 i = 1;
  38.             }
  39.         }
  40.     }
  41.     return (EXIT_SUCCESS);
  42. }




A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: Iniciando pic32MZ
« Respuesta #1 en: 07 de Diciembre de 2014, 04:53:01 »
Es la misma version pero con mas memoria que el que esta usando mig, seguro el te lo soluciona xD

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Iniciando pic32MZ
« Respuesta #2 en: 07 de Diciembre de 2014, 14:37:42 »
Qué tal Kallitos

Qué bien que te aventuraste a aprender con estos micros nuevos.

Un tip... procura usar Harmony para configurar todo. Microchip va a eliminar las librerías PLIB para PIC32 en un rato. Entonces vas a tener que moverte a Harmony de todas formas. Si las usas en tu código, el compilador te avienta un warning con la misma amenaza jeje.

Pero bueno, con tu código aquí los tips:

+ Configura los ANSEL, pull up/down, TRIS, PORTD, estos son los míos...

Código: [Seleccionar]
#define SYS_PORT_D_ANSEL        0x4000
#define SYS_PORT_D_TRIS         0xfe38
#define SYS_PORT_D_ODC          0x0
#define SYS_PORT_D_CNPU         0x1
#define SYS_PORT_D_CNPD         0x0
#define SYS_PORT_D_CNEN         0x0

+ Configura el Peripheral Bus Clock 4, te sugiero que sea al máximo de 100MHz (¿qué veloz no?). Éste sirve para los PORTS. Sí... los GPIO necesitan clock, ¿qué cosas no?

Código: [Seleccionar]
void SYS_CLK_Initialize( const SYS_CLK_INIT const * clkInit )
{
    SYS_DEVCON_SystemUnlock ( );
   
    PLIB_OSC_FRCDivisorSelect( OSC_ID_0, OSC_FRC_DIV_1);
    /* Enable Peripheral Bus 1 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 0, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 0 );
    /* Enable Peripheral Bus 2 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 1, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 1 );
    /* Enable Peripheral Bus 3 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 2, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 2 );
    /* Enable Peripheral Bus 4 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 3, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 3 );
    /* Enable Peripheral Bus 5 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 4, 2 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 4 );
    /* Enable Peripheral Bus 7 */
    PLIB_OSC_PBClockDivisorSet (OSC_ID_0, 6, 1 );
    PLIB_OSC_PBOutputClockEnable (OSC_ID_0, 6 );
    /* Disable Peripheral Bus 8 */
    PLIB_OSC_PBOutputClockDisable (OSC_ID_0, 7 );

    /* Enable and configure REFCLKO1*/
   
    /* ROSEL System Clock SYSCLK */
    PLIB_OSC_ReferenceOscBaseClockSelect ( OSC_ID_0, 0, 0 );
    /* RODIV */
    PLIB_OSC_ReferenceOscDivisorValueSet ( OSC_ID_0, 0, 10 );
    /* ROTRIM */
    PLIB_OSC_ReferenceOscTrimSet ( OSC_ID_0, 0, 0 );

    PLIB_OSC_ReferenceOscEnable ( OSC_ID_0, 0 );
    /* Disable REFCLK1_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 0 );
    /* Disable REFCLKO2*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 1 );
    /* Disable REFCLK2_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 1 );
    /* Disable REFCLKO3*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 2 );
    /* Disable REFCLK3_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 2 );
    /* Disable REFCLKO4*/
    PLIB_OSC_ReferenceOscDisable ( OSC_ID_0, 3 );
    /* Disable REFCLK4_OE*/
    PLIB_OSC_ReferenceOutputDisable ( OSC_ID_0, 3 );

    SYS_DEVCON_SystemLock ( );
}

+ Configura tu POSC o FRC correctamente. ¿Estás usando cristal o el FRC interno? Si usas cristal, checa porfas lo del otro hilo.

+ Si es cristal, checa los multiplicadores para que eleves la velocidad del System Clock a 200MHz. Asegúrate de poner una pull-up de 10k en OSC2. A ver si a ti sí te funciona.

+ Si es FRC, eleva los 8MHz a 200MHz para el System Clock. Checa mi adjunto.

+ Configura todos los configuration registers apropiadamente. Son muy parecidos a los PICs de siempre.

Código: [Seleccionar]
/*** DEVCFG0 ***/

#pragma config DEBUG =      OFF
#pragma config JTAGEN =     OFF
#pragma config ICESEL =     ICS_PGx1
#pragma config TRCEN =      ON
#pragma config BOOTISA =    MIPS32
#pragma config FECCCON =    OFF_UNLOCKED
#pragma config FSLEEP =     OFF
#pragma config DBGPER =     PG_ALL
#pragma config EJTAGBEN =   NORMAL
#pragma config CP =         OFF

/*** DEVCFG1 ***/

#pragma config FNOSC =      SPLL
#pragma config DMTINTV =    WIN_127_128
#pragma config FSOSCEN =    OFF
#pragma config IESO =       OFF
#pragma config POSCMOD =    EC
#pragma config OSCIOFNC =   OFF
#pragma config FCKSM =      CSDCMD
#pragma config WDTPS =      PS1048576
#pragma config WDTSPGM =    STOP
#pragma config FWDTEN =     OFF
#pragma config WINDIS =     NORMAL
#pragma config FWDTWINSZ =  WINSZ_25
#pragma config DMTCNT =     DMT31
#pragma config FDMTEN =     OFF

/*** DEVCFG2 ***/

#pragma config FPLLIDIV =   DIV_1
#pragma config FPLLRNG =    RANGE_5_10_MHZ
#pragma config FPLLICLK =   PLL_FRC
#pragma config FPLLMULT =   MUL_50
#pragma config FPLLODIV =   DIV_2
#pragma config UPLLFSEL =   FREQ_24MHZ
#pragma config UPLLEN =     ON

/*** DEVCFG3 ***/

#pragma config USERID =     0xffff
#pragma config FMIIEN =     OFF
#pragma config FETHIO =     OFF
#pragma config PGL1WAY =    ON
#pragma config PMDL1WAY =   OFF
#pragma config IOL1WAY =    OFF
#pragma config FUSBIDIO =   OFF

/*** BF1SEQ0 ***/

#pragma config TSEQ =       0xffff
#pragma config CSEQ =       0xffff

+ Procura usar los typedefs de stdint.h, son más estándar y no te pierdes buscando tamaños de variables...

Código: [Seleccionar]
#ifndef int8_t
typedef __int8_t int8_t;
#define int8_t __int8_t
#endif

#ifndef uint8_t
typedef __uint8_t uint8_t;
#define uint8_t __uint8_t
#endif

#ifndef int16_t
typedef __int16_t int16_t;
#define int16_t __int16_t
#endif

#ifndef uint16_t
typedef __uint16_t uint16_t;
#define uint16_t __uint16_t
#endif

#ifndef int32_t
typedef __int32_t int32_t;
#define int32_t __int32_t
#endif

#ifndef uint32_t
typedef __uint32_t uint32_t;
#define uint32_t __uint32_t
#endif

#ifndef int64_t
typedef __int64_t int64_t;
#define int64_t __int64_t
#endif

#ifndef uint64_t
typedef __uint64_t uint64_t;
#define uint64_t __uint64_t
#endif

#ifndef intptr_t
typedef __intptr_t intptr_t;
#define intptr_t __intptr_t
#endif

#ifndef uintptr_t
typedef __uintptr_t uintptr_t;
#define uintptr_t __uintptr_t
#endif

+ Si usas cristal checa que la R de 1M esté conectada en paralelo al cristal.

+ Puedes medir el System Clock con un truco... usando REFCLKO... lo hice con Harmony, pero ya lo deshabilité. El chiste es que sacas una división del System Clock por un pin del PIC y pues puedes medir el reloj de esa manera. Así es como descubrí que el POSC no me funcionaba.

Y eso es lo que se me ocurre por el momento. Harmony hizo la mayoría por mí, lo bueno es que habiendo ya usado PICs reconozco y entiendo el código que genera... muy rebuscado, pero bueno, lo genera.

Saludos.

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Iniciando pic32MZ
« Respuesta #3 en: 07 de Diciembre de 2014, 14:41:26 »
Ahhh... y me cuentas cómo te va con la promesa en tu firma...

Citar
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

jejej

2MB de ROM... son 2MB de ROM jajaj  :mrgreen:

¡Otro tip!

+ No habilites la optimización más allá de 0... el depurar te va a dar dolores de cabeza.

+ Cuando el POSC no funciona, el micro se auto protege y se mueve al BFRC... es un resonador de backup de 8MHz también... pero imagino que es más inexacto que el FRC.
« Última modificación: 07 de Diciembre de 2014, 14:44:49 por migsantiago »

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #4 en: 09 de Diciembre de 2014, 16:53:19 »
Hola migsantiago, muchas gracias por tu respuesta.

Utilicé los fuses que me indicaste, y le hice unas modificaciones para trabajar con el oscilador interno, ya había leído el otro post de pic32MZ y preferí no tomar ese camino.

No uso PLIB, nunca me gustó, prefiero hacer codigo a pulso, no me gusta usar librerías de las que no se como funcionan internamente, prefiero la libertad, jajajaja. Bueno hago esto lo más que pueda, pero cuando ya toca USB le dejo la chamba a microchip.

Estuve viendo Harmony, y opino que microchip nos está encerrando en su mundo, no me gusta para nada, aunque ví que tiene librerías para todo, aun así no va conmigo.

Logré hacer funcionar los puertos, por lo menos el PORTB y D oscilaron los demás no los probé, tengo un analizador y medí hasta 6Mhz, aunque creo que estan a mas frecuencia, el analizador ya no da más.

Probé Timer a 32bits y no me dá muy exacto el tiempo que seteo, con pic24EP me daba menos error.
No he podido hacer trabajar la interrupción, estoy en eso aun.

Probé UART2 y funcionó a la primera.

La verdad es que el código de C30 calzó rápido, no tuve problema.

Logré sacar por un pic el REFCLKO3 y REFCLKO4 con divisor de 100 y me dio 1Mhz, comprobando que el PLL me dá 200Mhz.

Pongo por aca el codigo de lo que voy:
Código: C
  1. /*
  2.  * File:   MAIN_PIC32MZ.c
  3.  * Author: Carlos
  4.  *
  5.  * Created on 8 de diciembre de 2014, 09:57 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <xc.h>
  12. #include <sys/attribs.h>
  13.  
  14. #define MIPS    100.0
  15. #define FCY     100000000
  16.  
  17. #define BAUDIOS_9600            9600
  18. #define _9600_BAUDIOS           (FCY/(4*(unsigned long)BAUDIOS_9600))-1
  19.  
  20. #pragma config DEBUG =      OFF
  21. #pragma config JTAGEN =     OFF
  22. #pragma config ICESEL =     ICS_PGx2
  23. #pragma config TRCEN =      ON
  24. #pragma config BOOTISA =    MIPS32
  25. #pragma config FECCCON =    OFF_UNLOCKED
  26. #pragma config FSLEEP =     OFF
  27. #pragma config DBGPER =     PG_ALL
  28. #pragma config EJTAGBEN =   NORMAL
  29. #pragma config CP =         OFF
  30.  
  31. // DEVCFG1
  32.  
  33. #pragma config FNOSC =      SPLL
  34. #pragma config DMTINTV =    WIN_127_128
  35. #pragma config FSOSCEN =    OFF
  36. #pragma config IESO =       OFF
  37. #pragma config POSCMOD =    OFF
  38. #pragma config OSCIOFNC =   OFF
  39. #pragma config FCKSM =      CSDCMD
  40. #pragma config WDTPS =      PS1048576
  41. #pragma config WDTSPGM =    STOP
  42. #pragma config FWDTEN =     OFF
  43. #pragma config WINDIS =     NORMAL
  44. #pragma config FWDTWINSZ =  WINSZ_25
  45. #pragma config DMTCNT =     DMT31
  46. #pragma config FDMTEN =     OFF
  47.  
  48. // DEVCFG2
  49.  
  50. #pragma config FPLLIDIV =   DIV_1
  51. #pragma config FPLLRNG =    RANGE_5_10_MHZ
  52. #pragma config FPLLICLK =   PLL_FRC
  53. #pragma config FPLLMULT =   MUL_50
  54. #pragma config FPLLODIV =   DIV_2
  55. #pragma config UPLLFSEL =   FREQ_24MHZ
  56. #pragma config UPLLEN =     OFF
  57.  
  58. // DEVCFG3
  59.  
  60. #pragma config USERID =     0xffff
  61. #pragma config FMIIEN =     OFF
  62. #pragma config FETHIO =     OFF
  63. #pragma config PGL1WAY =    ON
  64. #pragma config PMDL1WAY =   OFF
  65. #pragma config IOL1WAY =    OFF
  66. #pragma config FUSBIDIO =   OFF
  67.  
  68. // BF1SEQ0
  69.  
  70. #pragma config TSEQ =       0xffff
  71. #pragma config CSEQ =       0xffff
  72.  
  73. char    str_TX_UART[100];
  74.  
  75.  
  76.  
  77. void init_PORTS(void);
  78. void out_CLK(void);
  79. void init_timer32(void);
  80. void __ISR (_TIMER_3_VECTOR, IPL1SRS) Timer3Handler (void);
  81. void calculo_frecuencia(unsigned long val_frec);
  82.  
  83. void UART2Init(unsigned short baudios);
  84. void UART2PutChar( char ch );
  85. void UART2PrintString( char *str );
  86.  
  87. int main() {
  88.  
  89.  
  90.     out_CLK();
  91.     init_PORTS();
  92.     UART2Init(_9600_BAUDIOS);
  93.    
  94.     sprintf(str_TX_UART,"Iniciando Sistema\r\n");UART2PrintString(str_TX_UART);
  95.     sprintf(str_TX_UART,"PIC32MZ2048ECG100 I/PT\r\n");UART2PrintString(str_TX_UART);
  96.     sprintf(str_TX_UART,"Uart2 Init\r\n");UART2PrintString(str_TX_UART);
  97.     sprintf(str_TX_UART,"      9600 Baudios\r\n");UART2PrintString(str_TX_UART);
  98.     sprintf(str_TX_UART,"Timer3 Init\r\n");UART2PrintString(str_TX_UART);
  99.  
  100.     init_timer32();
  101.     calculo_frecuencia(1000000);
  102.  
  103.     //unsigned short  cont_S = 0;
  104.  
  105.     while(1)
  106.     {
  107.        
  108.     if(IFS0bits.T3IF)
  109.         {
  110.         //sprintf(str_TX_UART,"Seg: %5u\r\n",cont_S++);UART2PrintString(str_TX_UART);
  111.         IFS0bits.T3IF   = 0;          
  112.         LATB = ~LATB;
  113.         }//
  114.    
  115.     }//
  116.     return (EXIT_SUCCESS);
  117. }//
  118.  
  119. void init_PORTS(void)
  120. {
  121.     PB4DIVbits.ON           = 1;        ////    CLOCK PB4 ENABLE PARA GPIO's
  122.     PB4DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  123.  
  124.     ANSELA  = 0;
  125.     ODCA    = 0;
  126.     CNPUA   = 0;
  127.     CNPDA   = 0;
  128.     TRISA   = 0;
  129.     LATA    = 0;
  130.  
  131.     ANSELB  = 0;
  132.     ODCB    = 0;
  133.     CNPUB   = 0;
  134.     CNPDB   = 0;
  135.     TRISB   = 0;
  136.     LATB    = 0;
  137.  
  138.     ANSELC  = 0;
  139.     ODCC    = 0;
  140.     CNPUC   = 0;
  141.     CNPDC   = 0;
  142.     TRISC   = 0;
  143.     LATC    = 0;
  144.  
  145.     ANSELD  = 0;
  146.     ODCD    = 0;
  147.     CNPUD   = 0;
  148.     CNPDD   = 0;
  149.     TRISD   = 0;
  150.     LATD    = 0;
  151.  
  152.     ANSELE  = 0;
  153.     ODCE    = 0;
  154.     CNPUE   = 0;
  155.     CNPDE   = 0;
  156.     TRISE   = 0;
  157.     LATE    = 0;
  158.  
  159.     ANSELF  = 0;
  160.     ODCF    = 0;
  161.     CNPUF   = 0;
  162.     CNPDF   = 0;
  163.     TRISF   = 0;
  164.     LATF    = 0;
  165.  
  166.     ANSELG  = 0;
  167.     ODCG    = 0;
  168.     CNPUG   = 0;
  169.     CNPDG   = 0;
  170.     TRISG   = 0;
  171.     LATG    = 0;
  172. }//
  173.  
  174. void out_CLK(void)
  175. {
  176. RPD2Rbits.RPD2R         = 0b1101;   ////    SALIDA DE REFCLKO4 POR EL PORT D2
  177. //CNCONDbits.ON           = 0;
  178.  
  179. REFO4TRIMbits.ROTRIM    = 0;
  180.  
  181. REFO4CONbits.RODIV      = 100;      ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  182. REFO4CONbits.OE         = 1;        ////    OUTPUT ENABLED
  183. REFO4CONbits.ROSEL      = 7;        ////    FUENTE DE CLOCK PLL
  184. REFO4CONbits.ON         = 1;        ////    HABILITADO EN MODULO
  185.  
  186. RPB0Rbits.RPB0R         = 0b1111;   ////    SALIDA DE REFCLKO3 POR EL PORT B0
  187. //CNCONDbits.ON           = 0;
  188.  
  189. REFO3TRIMbits.ROTRIM    = 0;
  190.  
  191. REFO3CONbits.RODIV      = 100;      ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  192. REFO3CONbits.OE         = 1;        ////    OUTPUT ENABLED
  193. REFO3CONbits.ROSEL      = 7;        ////    FUENTE DE CLOCK PLL
  194. REFO3CONbits.ON         = 1;        ////    HABILITADO EN MODULO
  195. }
  196.  
  197. void __ISR (_TIMER_3_VECTOR, IPL1SRS) Timer3Handler (void)
  198. {
  199. LATB = ~LATB;
  200. IFS0bits.T3IF   = 0;
  201. }
  202.  
  203. void calculo_frecuencia(unsigned long val_frec)
  204. {
  205. float dato1;
  206. unsigned long   valor_a_cargar;///valor que se usara en carga de timers
  207.  
  208. sprintf(str_TX_UART,"      %u Hz\r\n",val_frec);UART2PrintString(str_TX_UART);
  209.  
  210. dato1 = (float)val_frec;   //paso valores a float
  211. dato1 = 1000000/dato1;
  212.  
  213.  
  214. valor_a_cargar = (unsigned long)dato1;
  215.  
  216. val_frec = 1000000/val_frec;
  217.  
  218.  
  219. val_frec *= MIPS;
  220. val_frec /= 2;
  221. PR2 = val_frec;            ///cargo los 16 bits bajos
  222. PR3 = val_frec>>16;         ///cargo los 16 bits altos
  223. TMR2    = 0;
  224. TMR3    = 0;
  225. }//
  226.  
  227. void init_timer32(void)////timer2 y timer3 forman timer32
  228. {
  229. PB3DIVbits.ON           = 1;        ////    CLOCK PB3 ENABLE PARA TIMER
  230. PB3DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  231.  
  232. T2CONbits.T32   = 1;            ////habilito timer32 bits
  233. T2CONbits.TGATE = 0;
  234. T2CONbits.TCS   = 0;
  235. T2CONbits.TON   = 1;
  236.  
  237. IFS0bits.T3IF   = 0;         ///limpio el flag de interrupcion
  238. IEC0bits.T3IE   = 0;         ///habilito la interrupcion
  239. }//
  240.  
  241. void UART2Init(unsigned short baudios)
  242. {
  243.     RPB2Rbits.RPB2R         = 0b0010;   ////    PPS UART2TX
  244.     PB2DIVbits.ON           = 1;        ////    CLOCK PB2 ENABLE PARA UART
  245.     PB2DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  246.  
  247.     U2BRG = baudios;
  248.     U2MODE = 0;
  249.     U2MODEbits.BRGH = 1;
  250.     U2STA = 0;
  251.     U2MODEbits.UARTEN = 1;
  252.     U2STAbits.UTXEN = 1;
  253.     //_U2RXIF = 0;
  254. }//
  255.  
  256. void UART2PrintString( char *str )
  257. {
  258.     unsigned char c;
  259.  
  260.     while( (c = *str++) )
  261.         UART2PutChar(c);
  262. }//
  263.  
  264. void UART2PutChar( char ch )
  265. {
  266.     U2TXREG = ch;
  267.         Nop();
  268.     while(U2STAbits.TRMT == 0);
  269. }//

Aqui se vé 1Mhz de salida de REFCLKO en el canal 6 en los demas un LATB = ~LATB;



Y aca pues me aproveche del Harmony para setear registros y obtener la frecuencia de referencia en un pin.



Con respecto a lo de mi firma, es justo por eso que necesito usar este micro, por los 2MB de flash que trae, usé un pic24EP512GU810 de 512 KB y me quedé corto de ROM, ojalá pueda usar toda la memoria sin retricciones.

Lo de la optimización no lahe movido, esta en 0.

Debugear con pickit3 es muy pesado y lento, menos mal ya me funcionó la UART con esta ya puedo saber como van las operaciones y registros.

Continúo mi camino, si hay algo en que te pueda ayudar me avisas mig.

Saludos.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: Iniciando pic32MZ
« Respuesta #5 en: 09 de Diciembre de 2014, 18:20:39 »
Interesante :)

Que manera de tener que configurar cosas para el PLL :/, ademas tenes como 8 bus de clock uno para cada cosa, para programarlo terminas con un alto de hoja al lado de la PC para tener todo a mano.

Citar
No uso PLIB, nunca me gustó, prefiero hacer codigo a pulso, no me gusta usar librerías de las que no se como funcionan internamente, prefiero la libertad, jajajaja. Bueno hago esto lo más que pueda, pero cuando ya toca USB le dejo la chamba a microchip.

Estuve viendo Harmony, y opino que microchip nos está encerrando en su mundo, no me gusta para nada, aunque ví que tiene librerías para todo, aun así no va conmigo.

Si es lo que me molesta un poco a mi tambien.
Lo de las librerias yo soy feliz que esten o hacer una de las mias con referencias a esas siempre y cuando pueda ver que es lo que hace dentro de las mismas, es decir que registros cargan, como lo cargan, etc etc etc. Creo que eso es vital, sino ante cualquier problema no sabes como solucionarlo y terminas arrancandote los pelos y finalmente haciendote una libreria vos mismo.

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Iniciando pic32MZ
« Respuesta #6 en: 09 de Diciembre de 2014, 19:15:11 »
Muy bien Kallitos. Qué bueno que modificas cosas a mano.

Yo empecé con Harmony por la facilidad de configuración en unas cosas, pero la SD library no la pude compilar.

Hay un dato importante que olvidé mencionar en mi mensaje... debes habilitar la pre-caché. La ROM es más lenta que el reloj del CPU. La prechaché agiliza esa situación. Checa los ejemplos de Harmony... se llama devCon_Precache algo así... así volará más rápido tu micro.

Gracias, por ahora no he encontrado más issues en el micro... todo normal... jejej  :mrgreen:

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #7 en: 10 de Diciembre de 2014, 11:19:43 »
Bueno estoy detenido, no puedo hacer funcionar las interrupciones, ya probé con Timer3 y Uart2, no funcionan.

Ya puse :
Código: C
  1. INTCONbits.MVEC = 1;    /// MULTIVECTOR INTERRUPCIONES

Y nada, viendo el pdf pic32MZ encontré esto:

CONFIG3
bit 6 VEIC: External Vector Interrupt Controller bit
1 = Support for an external interrupt controller is implemented.
bit 5 VINT: Vector Interrupt bit
1 = Vector interrupts are implemented

Y no lo puedo modificar, ando buscando en fuses, y nada, no lo encuentro, me echan una mano.

saludos.

Edito: Son registros de sólo lectura.
« Última modificación: 10 de Diciembre de 2014, 11:47:05 por KALLITOS »
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #8 en: 10 de Diciembre de 2014, 11:59:57 »
Hay un dato importante que olvidé mencionar en mi mensaje... debes habilitar la pre-caché. La ROM es más lenta que el reloj del CPU. La prechaché agiliza esa situación. Checa los ejemplos de Harmony... se llama devCon_Precache algo así... así volará más rápido tu micro.

Código: C
  1. PRECONbits.PFMWS    = 2;    ///2 ESTADOS DE ESPERA PARA CACHE SEGUN TABLA 36-13  PIC32MZ 166 < SYSCLK <= 200
  2.     PRECONbits.PREFEN   = 2;
  3.     /*  11 = Enable predictive prefetch for any address
  4.         10 = Enable predictive prefetch for CPU instructions and CPU data
  5.         01 = Enable predictive prefetch for CPU instructions only
  6.         00 = Disable predictive prefetch
  7.      */

Hecho.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #9 en: 10 de Diciembre de 2014, 16:44:18 »
Interrupción Timer2+3  y 4+5  ya estan trabajando.
Ahora Interrupción UART2, que aun no quiere.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #10 en: 11 de Diciembre de 2014, 12:47:16 »
Bueno voy avanzando de a pocos aunque continúa la interrupción UART sin funcionar:

No salta al codigo de interrupción, más el flag si se activa, no sé que mas modificar para que funcione.

pego codigo por si a alguien lo usa.

Código: C
  1. /*
  2.  * File:   MAIN_PIC32MZ.c
  3.  * Author: Carlos
  4.  *
  5.  * Created on 8 de diciembre de 2014, 09:57 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. #include <xc.h>
  13. #include <proc/p32mz2048ecg100.h>
  14. #include <sys/attribs.h>
  15. #include <stdint.h>
  16.  
  17.  
  18. #define MIPS    100.0
  19. #define FCY     100000000
  20.  
  21. #define BAUDIOS_9600            9600
  22. #define _9600_BAUDIOS           (FCY/(4*(unsigned long)BAUDIOS_9600))-1
  23.  
  24. #pragma config DEBUG =      OFF
  25. #pragma config JTAGEN =     OFF
  26. #pragma config ICESEL =     ICS_PGx2
  27. #pragma config TRCEN =      ON
  28. #pragma config BOOTISA =    MIPS32
  29. #pragma config FECCCON =    OFF_UNLOCKED
  30. #pragma config FSLEEP =     OFF
  31. #pragma config DBGPER =     PG_ALL
  32. #pragma config EJTAGBEN =   NORMAL
  33. #pragma config CP =         OFF
  34.  
  35. // DEVCFG1
  36.  
  37. #pragma config FNOSC =      SPLL
  38. #pragma config DMTINTV =    WIN_127_128
  39. #pragma config FSOSCEN =    OFF
  40. #pragma config IESO =       OFF
  41. #pragma config POSCMOD =    OFF
  42. #pragma config OSCIOFNC =   OFF
  43. #pragma config FCKSM =      CSDCMD
  44. #pragma config WDTPS =      PS1048576
  45. #pragma config WDTSPGM =    STOP
  46. #pragma config FWDTEN =     OFF
  47. #pragma config WINDIS =     NORMAL
  48. #pragma config FWDTWINSZ =  WINSZ_25
  49. #pragma config DMTCNT =     DMT31
  50. #pragma config FDMTEN =     OFF
  51.  
  52. // DEVCFG2
  53.  
  54. #pragma config FPLLIDIV =   DIV_1
  55. #pragma config FPLLRNG =    RANGE_5_10_MHZ
  56. #pragma config FPLLICLK =   PLL_FRC
  57. #pragma config FPLLMULT =   MUL_50
  58. #pragma config FPLLODIV =   DIV_2
  59. #pragma config UPLLFSEL =   FREQ_24MHZ
  60. #pragma config UPLLEN =     OFF
  61.  
  62. // DEVCFG3
  63.  
  64. #pragma config USERID =     0xffff
  65. #pragma config FMIIEN =     OFF
  66. #pragma config FETHIO =     OFF
  67. #pragma config PGL1WAY =    ON
  68. #pragma config PMDL1WAY =   OFF
  69. #pragma config IOL1WAY =    OFF
  70. #pragma config FUSBIDIO =   OFF
  71.  
  72. // BF1SEQ0
  73.  
  74. #pragma config TSEQ =       0xffff
  75. #pragma config CSEQ =       0xffff
  76.  
  77. unsigned char contador = 0;
  78. char str_TX_UART[100];
  79. unsigned char flag_T3 = 0;
  80. unsigned char flag_T5 = 0;
  81. unsigned char flag_T7 = 0;
  82. unsigned char flag_T9 = 0;
  83. unsigned char flag_U2 = 0;
  84. unsigned char dat_U2 = 0;
  85. unsigned char flag_Iext0 = 0;
  86. unsigned char flag_Iext1 = 0;
  87. unsigned char flag_Iext2 = 0;
  88. unsigned char flag_Iext3 = 0;
  89. unsigned char flag_Iext4 = 0;
  90.  
  91. void code_basura(void);
  92. void init_PORTS(void);
  93. void out_CLK(void);
  94. void init_timer32(void);
  95. //void __attribute__((vector(_TIMER_3_VECTOR), interrupt(ipl1), nomips16)) Timer3Handler(void);
  96. void __ISR(_TIMER_3_VECTOR, ipl1) T3_Interrupt(void);
  97. //void __ISR_AT_VECTOR(_TIMER_3_VECTOR, ipl3) T3_Interrupt(void);
  98. void calculo_frecuencia(unsigned int val_frec);
  99.  
  100. //void __attribute__((vector(_UART2_RX_VECTOR), interrupt(ipl1), nomips16)) U2RXHandler(void);//
  101. void __ISR(_UART2_RX_VECTOR, ipl1)U2RXHandler(void);
  102. void UART2Init(unsigned short baudios);
  103. void UART2PutChar(char ch);
  104. void UART2PrintString(char *str);
  105.  
  106. //void __attribute__((vector(_TIMER_5_VECTOR), interrupt(ipl1), nomips16)) Timer5Handler(void);
  107. void __ISR(_TIMER_5_VECTOR, ipl1) T5_Interrupt(void);
  108. void TimerInit(void);
  109.  
  110. void __ISR(_TIMER_7_VECTOR, ipl1) T7_Interrupt(void);
  111. void __ISR(_TIMER_9_VECTOR, ipl1) T9_Interrupt(void);
  112. void __ISR(_EXTERNAL_2_VECTOR, ipl1) Int2_Interrupt(void);
  113. void init_IExt0(void);
  114. void init_IExt1(void);
  115. void init_IExt2(void);
  116. void init_IExt3(void);
  117. void init_IExt4(void);
  118.  
  119. int main() {
  120.  
  121.     //    PB7DIVbits.ON           = 1;        ////    CLOCK PB3 ENABLE PARA TIMER
  122.     //    PB7DIVbits.PBDIV        = 2;        ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  123.  
  124.     PRECONbits.PFMWS = 2; ///2 ESTADOS DE ESPERA PARA CACHE SEGUN TABLA 36-13  PIC32MZ 166 < SYSCLK <= 200
  125.     PRECONbits.PREFEN = 2;
  126.     /*  11 = Enable predictive prefetch for any address
  127.         10 = Enable predictive prefetch for CPU instructions and CPU data
  128.         01 = Enable predictive prefetch for CPU instructions only
  129.         00 = Disable predictive prefetch
  130.      */
  131.  
  132.  
  133.     out_CLK();
  134.     init_PORTS();
  135.     UART2Init(_9600_BAUDIOS);
  136.  
  137.     sprintf(str_TX_UART, "Iniciando Sistema\r\n");
  138.     UART2PrintString(str_TX_UART);
  139.     sprintf(str_TX_UART, "PIC32MZ2048ECG100 I/PT\r\n");
  140.     UART2PrintString(str_TX_UART);
  141.     sprintf(str_TX_UART, "Uart2 Init\r\n");
  142.     UART2PrintString(str_TX_UART);
  143.     sprintf(str_TX_UART, "      9600 Baudios\r\n");
  144.     UART2PrintString(str_TX_UART);
  145.     sprintf(str_TX_UART, "Timer3 Init\r\n");
  146.     UART2PrintString(str_TX_UART);
  147.  
  148.  
  149.     init_timer32();
  150.     calculo_frecuencia(10);
  151.  
  152.     TimerInit();
  153.  
  154.     PR4 = PR2; // Period register
  155.     PR5 = PR3; // Period register
  156.  
  157.     PR6 = PR2; // Period register
  158.     PR7 = PR3; // Period register
  159.  
  160.     PR8 = PR2; // Period register
  161.     PR9 = PR3; // Period register
  162.  
  163.     init_IExt0();
  164.     init_IExt1();
  165.     init_IExt2();
  166.     init_IExt3();
  167.     init_IExt4();
  168.    
  169.  
  170.    
  171.     INTCONbits.MVEC = 1; /// MULTIVECTOR INTERRUPCIONES
  172.     __builtin_enable_interrupts();
  173.  
  174.     while (1) {
  175.      
  176.        
  177.         if(IFS4bits.U2RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  178.             sprintf(str_TX_UART, "UART: %c\r\n",U2RXREG);UART2PrintString(str_TX_UART);
  179.             IFS4bits.U2RXIF = 0;
  180.             }        
  181.  
  182.         if (flag_U2) {      ///CODIGO QUE DEBE EJECUTARSE RESULTADO DEL CODIGO DE LA INTERRUPCION
  183.             flag_U2 = 0;
  184.             sprintf(str_TX_UART, "UART: \r\n");UART2PrintString(str_TX_UART);
  185.         }
  186.  
  187.         if (flag_T3) {
  188.             flag_T3 = 0;
  189.             sprintf(str_TX_UART, "Timer 3\r\n");
  190.             UART2PrintString(str_TX_UART);
  191.         }//
  192.  
  193.         if (flag_T5) {
  194.             flag_T5 = 0;
  195.             sprintf(str_TX_UART, "Timer 5\r\n");
  196.             UART2PrintString(str_TX_UART);
  197.         }//
  198.         if (flag_T7) {
  199.             flag_T7 = 0;
  200.             sprintf(str_TX_UART, "Timer 7\r\n");
  201.             UART2PrintString(str_TX_UART);
  202.         }//
  203.         if (flag_T9) {
  204.             flag_T9 = 0;
  205.             sprintf(str_TX_UART, "Timer 9\r\n");
  206.             UART2PrintString(str_TX_UART);
  207.         }//
  208.  
  209.         if (flag_Iext0) {
  210.             flag_Iext0 = 0;
  211.             sprintf(str_TX_UART, "IEXT0\r\n");
  212.             UART2PrintString(str_TX_UART);
  213.         }
  214.  
  215.         if (flag_Iext1) {
  216.             flag_Iext1 = 0;
  217.             sprintf(str_TX_UART, "IEXT1\r\n");
  218.             UART2PrintString(str_TX_UART);
  219.         }
  220.  
  221.         if (flag_Iext2) {
  222.             flag_Iext2 = 0;
  223.             sprintf(str_TX_UART, "IEXT2\r\n");
  224.             UART2PrintString(str_TX_UART);
  225.         }
  226.  
  227.         if (flag_Iext3) {
  228.             flag_Iext3 = 0;
  229.             sprintf(str_TX_UART, "IEXT3\r\n");
  230.             UART2PrintString(str_TX_UART);
  231.         }
  232.  
  233.         if (flag_Iext4) {
  234.             flag_Iext4 = 0;
  235.             sprintf(str_TX_UART, "IEXT4\r\n");
  236.             UART2PrintString(str_TX_UART);
  237.         }
  238.  
  239.     }//
  240.     return (EXIT_SUCCESS);
  241. }//
  242.  
  243. void code_basura(void)      ///CODIGO USADO PARA CUANDO HAY POCAS INSTRUCCIONES EN MAIN PRINCIPAL, LAS INTERRUPCIONES PUEDAN EJECUTARSE NORMALMENTE
  244. {
  245. switch (contador) {
  246.                 /////contador = 0;
  247.             case 0:contador++;
  248.                 break;
  249.             case 1:contador++;
  250.                 break;
  251.             case 2:contador++;
  252.                 break;
  253.             case 3:contador++;
  254.                 break;
  255.             case 4:contador++;
  256.                 break;
  257.             case 5:contador++;
  258.                 break;
  259.             case 6:contador++;
  260.                 break;
  261.             case 7:contador++;
  262.                 break;
  263.             case 8:contador++;
  264.                 break;
  265.             case 9:contador++;
  266.                 break;
  267.             case 10:contador++;
  268.                 break;
  269.             case 11:contador++;
  270.                 break;
  271.             case 12:contador++;
  272.                 break;
  273.             case 13:contador++;
  274.                 break;
  275.             case 14:contador++;
  276.                 break;
  277.             case 15:contador++;
  278.                 break;
  279.             case 16:contador++;
  280.                 break;
  281.             case 17:contador++;
  282.                 break;
  283.             case 18:contador++;
  284.                 break;
  285.             case 19:contador++;
  286.                 break;
  287.             case 20:contador++;
  288.                 break;
  289.             case 21:contador++;
  290.                 break;
  291.             case 22:contador++;
  292.                 break;
  293.             case 23:contador = 0;
  294.                 break;
  295.         }
  296.  
  297. }
  298.  
  299.  
  300. void init_PORTS(void) {
  301.     PB4DIVbits.ON = 1; ////    CLOCK PB4 ENABLE PARA GPIO's
  302.     PB4DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  303.  
  304.     ANSELA = 0;
  305.     ODCA = 0;
  306.     CNPUA = 0;
  307.     CNPDA = 0;
  308.     TRISA = 0;
  309.     LATA = 0;
  310.  
  311.     ANSELB = 0;
  312.     ODCB = 0;
  313.     CNPUB = 0;
  314.     CNPDB = 0;
  315.     TRISB = 0;
  316.     LATB = 0;
  317.  
  318.     ANSELC = 0;
  319.     ODCC = 0;
  320.     CNPUC = 0;
  321.     CNPDC = 0;
  322.     TRISC = 0;
  323.     LATC = 0;
  324.  
  325.     ANSELD = 0;
  326.     ODCD = 0;
  327.     CNPUD = 0;
  328.     CNPDD = 0;
  329.     TRISD = 0;
  330.     LATD = 0;
  331.  
  332.     ANSELE = 0;
  333.     ODCE = 0;
  334.     CNPUE = 0;
  335.     CNPDE = 0;
  336.     TRISE = 0;
  337.     LATE = 0;
  338.  
  339.     ANSELF = 0;
  340.     ODCF = 0;
  341.     CNPUF = 0;
  342.     CNPDF = 0;
  343.     TRISF = 0;
  344.     LATF = 0;
  345.  
  346.     ANSELG = 0;
  347.     ODCG = 0;
  348.     CNPUG = 0;
  349.     CNPDG = 0;
  350.     TRISG = 0;
  351.     LATG = 0;
  352. }//
  353.  
  354. void out_CLK(void) {
  355.     RPD2Rbits.RPD2R = 0b1101; ////    SALIDA DE REFCLKO4 POR EL PORT D2
  356.     //CNCONDbits.ON           = 0;
  357.  
  358.     REFO4TRIMbits.ROTRIM = 0;
  359.  
  360.     REFO4CONbits.RODIV = 100; ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  361.     REFO4CONbits.OE = 1; ////    OUTPUT ENABLED
  362.     REFO4CONbits.ROSEL = 7; ////    FUENTE DE CLOCK PLL
  363.     REFO4CONbits.ON = 1; ////    HABILITADO EN MODULO
  364.  
  365.     RPB0Rbits.RPB0R = 0b1111; ////    SALIDA DE REFCLKO3 POR EL PORT B0
  366.     //CNCONDbits.ON           = 0;
  367.  
  368.     REFO3TRIMbits.ROTRIM = 0;
  369.  
  370.     REFO3CONbits.RODIV = 100; ////    DIVIDE LOS 200Mhz PARA OBTENER 1Mhz Y PODER MEDIRLO CON ANALIZADOR
  371.     REFO3CONbits.OE = 1; ////    OUTPUT ENABLED
  372.     REFO3CONbits.ROSEL = 7; ////    FUENTE DE CLOCK PLL
  373.     REFO3CONbits.ON = 1; ////    HABILITADO EN MODULO
  374. }
  375.  
  376. void __ISR(_TIMER_3_VECTOR, ipl1) T3_Interrupt(void) {
  377.     flag_T3 = 1;
  378.     IFS0bits.T3IF = 0;
  379. }
  380.  
  381. void __ISR(_UART2_RX_VECTOR, ipl1)U2RXHandler(void) {
  382.     flag_U2 = 1; //
  383.     U2TXREG = U2RXREG; //while(!U2STAbits.TRMT); flag_U2 = 1;
  384.     IFS4bits.U2RXIF = 0;
  385. }
  386.  
  387. void calculo_frecuencia(unsigned int val_frec) {
  388.     if (!val_frec)val_frec = 1;
  389.     sprintf(str_TX_UART, "      %u Hz\r\n", val_frec);
  390.     UART2PrintString(str_TX_UART);
  391.     val_frec = 1000000 / val_frec;
  392.     val_frec *= MIPS;
  393.     val_frec *= 10;
  394.  
  395.     sprintf(str_TX_UART, "val_frec %u\r\n", val_frec);
  396.     UART2PrintString(str_TX_UART);
  397.  
  398.     PR2 = val_frec & 0x0000FFFF; ///cargo los 16 bits bajos
  399.     PR3 = (val_frec >> 16) & 0x0000FFFF; ///cargo los 16 bits altos
  400.     TMR2 = 0;
  401.     TMR3 = 0;
  402. }//
  403.  
  404. void init_timer32(void)////timer2 y timer3 forman timer32
  405. {
  406.     PB3DIVbits.ON = 1; ////    CLOCK PB3 ENABLE PARA TIMER
  407.     PB3DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  408.  
  409.     T2CONbits.TON = 0; // Stop timer
  410.     T3CONbits.TON = 0; // Stop timer
  411.     TMR2 = 0; // Clear contenst of the TMR4
  412.     T2CONbits.T32 = 1; // 32-bit timer
  413.     T2CONbits.TCKPS = 0; // Divide by 8
  414.     T2CONbits.TCS = 0; // Internal clock
  415.     IPC3bits.T3IP = 1; // Set priority level = 1
  416.     IPC3bits.T3IS = 1; // Set sub-priority level = 1
  417.     IFS0bits.T3IF = 0; // Clear the Timer4 interrupt status flag
  418.     IEC0bits.T3IE = 1; // Enable Timer5 interrupts
  419.     T2CONbits.TON = 1; // Start timer
  420.  
  421.     T6CONbits.TON = 0; // Stop timer
  422.     T7CONbits.TON = 0; // Stop timer
  423.     TMR6 = 0; // Clear contenst of the TMR4
  424.     T6CONbits.T32 = 1; // 32-bit timer
  425.     T6CONbits.TCKPS = 0; // Divide by 8
  426.     T6CONbits.TCS = 0; // Internal clock
  427.     IPC8bits.T7IP = 1; // Set priority level = 1
  428.     IPC8bits.T7IS = 1; // Set sub-priority level = 1
  429.     IFS1bits.T7IF = 0; // Clear the Timer4 interrupt status flag
  430.     IEC1bits.T7IE = 1; // Enable Timer5 interrupts
  431.     T6CONbits.TON = 1; // Start timer
  432.  
  433.     T8CONbits.TON = 0; // Stop timer
  434.     T9CONbits.TON = 0; // Stop timer
  435.     TMR8 = 0; // Clear contenst of the TMR4
  436.     T8CONbits.T32 = 1; // 32-bit timer
  437.     T8CONbits.TCKPS = 0; // Divide by 8
  438.     T8CONbits.TCS = 0; // Internal clock
  439.     IPC10bits.T9IP = 1; // Set priority level = 1
  440.     IPC10bits.T9IS = 1; // Set sub-priority level = 1
  441.     IFS1bits.T9IF = 0; // Clear the Timer4 interrupt status flag
  442.     IEC1bits.T9IE = 1; // Enable Timer5 interrupts
  443.     T8CONbits.TON = 1; // Start timer
  444. }//
  445.  
  446. void UART2Init(unsigned short baudios) {
  447.     TRISDbits.TRISD4 = 1;
  448.  
  449.     RPB2Rbits.RPB2R = 0b0010; ////    PPS UART2TX
  450.     U2RXRbits.U2RXR = 0b0100; ////    RX2 EN PIND4
  451.  
  452.     PB2DIVbits.ON = 1; ////    CLOCK PB2 ENABLE PARA UART
  453.     PB2DIVbits.PBDIV = 2; ////    DIVIDE LOS 200Mhz ENTRE 2 Y LOGRA 100Mhz
  454.  
  455.     U2BRG = baudios;
  456.     U2STA = 0;
  457.     U2MODE = 0;
  458.     U2MODEbits.BRGH = 1;
  459.     U2STAbits.URXEN = 1;
  460.     U2STAbits.UTXEN = 1;
  461.     U2STAbits.URXISEL = 0;
  462.  
  463.  
  464.     IPC36bits.U2EIP = 1;
  465.     IPC36bits.U2EIS = 1;
  466.     IFS4bits.U2RXIF = 0;
  467.     IEC4bits.U2RXIE = 1;
  468.  
  469.     U2MODEbits.ON = 1;
  470.  
  471. }//
  472.  
  473. void UART2PrintString(char *str) {
  474.     unsigned char c;
  475.  
  476.     while ((c = *str++))
  477.         UART2PutChar(c);
  478. }//
  479.  
  480. void UART2PutChar(char ch) {
  481.     U2TXREG = ch;
  482.     Nop();
  483.     while (!U2STAbits.TRMT);
  484. }//
  485.  
  486. void TimerInit(void) {
  487.     T4CONbits.TON = 0; // Stop timer
  488.     T5CONbits.TON = 0; // Stop timer
  489.     TMR4 = 0; // Clear contenst of the TMR4
  490.     T4CONbits.T32 = 1; // 32-bit timer
  491.     T4CONbits.TCKPS = 0; // Divide by 8
  492.     PR4 = 1000; // Period register
  493.     T4CONbits.TCS = 0; // Internal clock
  494.     IPC6bits.T5IP = 1; // Set priority level = 1
  495.     IPC6bits.T5IS = 1; // Set sub-priority level = 1
  496.     IFS0bits.T5IF = 0; // Clear the Timer4 interrupt status flag
  497.     IEC0bits.T5IE = 1; // Enable Timer5 interrupts
  498.     //asm volatile("ei"); // Assembler interrupts enable
  499.     T4CONbits.TON = 1; // Start timer
  500. }
  501.  
  502. void __ISR(_TIMER_5_VECTOR, ipl1) T5_Interrupt(void) {
  503.     flag_T5 = 1;
  504.     LATBbits.LATB3 = ~LATBbits.LATB3;
  505.     IFS0bits.T5IF = 0; //Clear flag
  506. }
  507.  
  508. void __ISR(_TIMER_7_VECTOR, ipl1) T7_Interrupt(void) {
  509.     flag_T7 = 1;
  510.     IFS1bits.T7IF = 0; //Clear flag
  511. }
  512.  
  513. void __ISR(_TIMER_9_VECTOR, ipl1) T9_Interrupt(void) {
  514.     flag_T9 = 1;
  515.     IFS1bits.T9IF = 0; //Clear flag
  516. }
  517.  
  518. void __ISR(_EXTERNAL_0_VECTOR, ipl1) Int0_Interrupt(void) {
  519.     flag_Iext0 = 1;
  520.     IFS0bits.INT0IF = 0; //Clear flag
  521. }
  522.  
  523. void __ISR(_EXTERNAL_1_VECTOR, ipl1) Int1_Interrupt(void) {
  524.     flag_Iext1 = 1;
  525.     IFS0bits.INT1IF = 0; //Clear flag
  526. }
  527.  
  528. void __ISR(_EXTERNAL_2_VECTOR, ipl1) Int2_Interrupt(void) {
  529.     flag_Iext2 = 1;
  530.     IFS0bits.INT2IF = 0; //Clear flag
  531. }
  532.  
  533. void __ISR(_EXTERNAL_3_VECTOR, ipl1) Int3_Interrupt(void) {
  534.     flag_Iext3 = 1;
  535.     IFS0bits.INT3IF = 0; //Clear flag
  536. }
  537.  
  538. void __ISR(_EXTERNAL_4_VECTOR, ipl1) Int4_Interrupt(void) {
  539.     flag_Iext4 = 1;
  540.     IFS0bits.INT4IF = 0; //Clear flag
  541. }
  542.  
  543.  
  544.  
  545. void init_IExt0(void) {
  546.     TRISDbits.TRISD0 = 1;
  547.     IPC0bits.INT0IP = 1;
  548.     IPC0bits.INT0IS = 1;
  549.     //INT0Rbits.INT0R = 1; ///PORTG9 ENTRADA INTEX2
  550.     IFS0bits.INT0IF = 0;
  551.     IEC0bits.INT0IE = 1;
  552. }
  553.  
  554. void init_IExt1(void) {
  555.     TRISGbits.TRISG9 = 1;
  556.     IPC2bits.INT1IP = 1;
  557.     IPC2bits.INT1IS = 1;
  558.     INT1Rbits.INT1R = 1; ///PORTG9 ENTRADA INTEX2
  559.     IFS0bits.INT1IF = 0;
  560.     IEC0bits.INT1IE = 1;
  561. }
  562.  
  563. void init_IExt2(void) {
  564.     TRISGbits.TRISG6 = 1;
  565.     IPC3bits.INT2IP = 1;
  566.     IPC3bits.INT2IS = 1;
  567.     INT2Rbits.INT2R = 1; ///PORTG6 ENTRADA INTEX2
  568.     IFS0bits.INT2IF = 0;
  569.     IEC0bits.INT2IE = 1;
  570. }
  571.  
  572. void init_IExt3(void) {
  573.     TRISGbits.TRISG8 = 1;
  574.     IPC4bits.INT3IP = 1;
  575.     IPC4bits.INT3IS = 1;
  576.     INT3Rbits.INT3R = 1; ///PORTG8 ENTRADA INTEX2
  577.     IFS0bits.INT3IF = 0;
  578.     IEC0bits.INT3IE = 1;
  579. }
  580.  
  581. void init_IExt4(void) {
  582.     TRISGbits.TRISG7 = 1;
  583.     IPC5bits.INT4IP = 1;
  584.     IPC5bits.INT4IS = 1;
  585.     INT4Rbits.INT4R = 1; ///PORTG7 ENTRADA INTEX2
  586.     IFS0bits.INT4IF = 0;
  587.     IEC0bits.INT4IE = 1;
  588. }



saludos.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #11 en: 11 de Diciembre de 2014, 14:21:27 »
Ni Uart1 ni Uart2 quieren

Código: C
  1. if(IFS3bits.U1RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  2.             sprintf(str_TX_UART, "UART1: %c\r\n",U1RXREG);UART1PrintString(str_TX_UART);
  3.             IFS3bits.U1RXIF = 0;
  4.             }
  5.  
  6.         if(IFS4bits.U2RXIF) {   ///CODGIO QUE SE EJECUTA DIRECTAMENTE SIN EJECUTAR CODIGO DE INTERRUPCION
  7.             sprintf(str_TX_UART, "UART2: %c\r\n",U2RXREG);UART2PrintString(str_TX_UART);
  8.             IFS4bits.U2RXIF = 0;
  9.             }

Pero asi sí van.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: Iniciando pic32MZ
« Respuesta #12 en: 11 de Diciembre de 2014, 14:36:16 »
Por que vi que tiene muchos modos de configuracion entre los cuales calcula la posicion del vector, con una base + offset , etc.
Es lo que le llama Multi-Vector mode

Multi-Vector mode – interrupt requests will be serviced at the calculated vector address

Sino inicia en
Single Vector mode – all interrupt requests will be serviced at one vector address (mode out of reset)

por lo que deberias de preguntar si o si cual es el flag, no se si te lo hace el compilador o no, es como si fuera una interrupcion de un pic de gama media/baja.

Probaste de ponerlo en Multi-vector ? es decir habilitar el bit MVEC de INTCON

Citar
To configure the CPU in Single Vector mode, the following CPU registers (Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 0
•IE bit (Status<0>) = 1
•Bev = 1

Citar
To configure the CPU in Computed Offset mode, the following CPU registers (IntCtl, Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•VS<6:0> bits (IntCtl<9:5> or INTCON<20:16>) ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 1
•IE bit (Status<

Aunque si fuera esto las demas tampoco andarian, probaste subirle la prioridad?
« Última modificación: 11 de Diciembre de 2014, 14:40:12 por KILLERJC »

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #13 en: 11 de Diciembre de 2014, 14:39:46 »
Sí ya lo hice, fijate en el código completo que coloqué en la linea 171 alli está habilitado multivector, además las interrupciones: INTEXT0,INTEXT1,INTEXT2,INTEXT3,INTEXT4,T3,T5,T7,yT9 ya estan funcionando al mismo tiempo.

Por eso no entiendo por qué no funciona Uart1 ni Uart2 no he probado aun con mas interrupciones.

saludos.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.

Desconectado KALLITOS

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1256
Re: Iniciando pic32MZ
« Respuesta #14 en: 11 de Diciembre de 2014, 14:50:22 »
Por que vi que tiene muchos modos de configuracion entre los cuales calcula la posicion del vector, con una base + offset , etc.
Es lo que le llama Multi-Vector mode

Multi-Vector mode – interrupt requests will be serviced at the calculated vector address

Sino inicia en
Single Vector mode – all interrupt requests will be serviced at one vector address (mode out of reset)

por lo que deberias de preguntar si o si cual es el flag, no se si te lo hace el compilador o no, es como si fuera una interrupcion de un pic de gama media/baja.

Probaste de ponerlo en Multi-vector ? es decir habilitar el bit MVEC de INTCON

Citar
To configure the CPU in Single Vector mode, the following CPU registers (Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 0
•IE bit (Status<0>) = 1
•Bev = 1

Citar
To configure the CPU in Computed Offset mode, the following CPU registers (IntCtl, Cause and Status) and the INTCON register must be configured as follows:
•EBase ≠ 00000
•VS<6:0> bits (IntCtl<9:5> or INTCON<20:16>) ≠ 00000
•IV bit (Cause<23>) = 1
•MVEC bit (INTCON<12>) = 1
•IE bit (Status<

Aunque si fuera esto las demas tampoco andarian, probaste subirle la prioridad?

KILLERJC donde puedo encontrar esa documentación que referencias, gracias por tus respuestas.
A un microcontrolador hay que sacarle hasta el ultimo byte....(YO)

Cómo puede ser que un pic24EP512 me quede corto de memoria, señores de MICROCHIP saquen pics con más memoria flash

Más de 45 mil lineas de codigo y aun no termino el equipo, asu mare!!

S34ML08G1TFI200 no necesito mas memoria externa.