• AVR Freaks

Helpful ReplyHot!Timer 1 won't work with PIC24 simulated in proteus

Author
vra
Senior Member
  • Total Posts : 123
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
2020/01/28 20:18:34 (permalink)
0

Timer 1 won't work with PIC24 simulated in proteus

Hello everyone, I have a problem here, I am using timer 1 of the PIC24FJ256GA106 in Proteus configured with the external oscillator, I have read several times all the configuration I have to run timer 1 and then generate the respective interrupt but timer 1 just does not increase. I understand that Proteus ignores any clock circuit connected to its clock inputs by design and adjusts to the configuration properties of the model, that is, you change the frequency with a field but you must also configure everything in the code you are doing.
 
By following the steps as they appear in the device and reference manual for the timers I do not achieve anything, simply my code is waiting forever for what will happen, that the T1IF flag overflows because as I said, TMR1 does not Increase, then the code:
 
Los bits de configuración para el reloj están como sigue:
 

#pragma config POSCMOD = HS // Primary Oscillator Select (EC oscillator mode selected)
#pragma config IOL1WAY = ON // IOLOCK One-Way Set Enable bit (Write RP Registers Once)
#pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSCO functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-safe Clock Monitor are disabled)
#pragma config FNOSC = PRI // Oscillator Select (Secondary oscillator (SOSC))
#pragma config IESO = ON // Internal External Switch Over Mode (IESO mode (Two-speed start-up) enabled)

 
my header "sistema.h" is like follows:
 

#ifndef SISTEMA_H
#define SISTEMA_H

#include <xc.h> // include processor files - each processor file is guarded. 

/*Definiciones de datos para desbloquear OSCCONh*/
#define     SOSCENH     2
#define     SOSCEND     0

/*Bit de habilitación de cambio de oscilador OSWEN*/

#define     OSWENI      1

/*Definición de prototipos de funciones para el control del oscilador*/

void Tipo_Osc(unsigned short reloj);    /* Función para configurar el tipo de
                                         * reloj a utilizar.*/

void Sec_Osc(unsigned short secosc);    /* Función para habilitar el uso del
                                         * oscilador secundario.*/
#endif /* SISTEMA_H */

 
mi source file "sistema.c" is like follows:
 

#include "sistema.h"

void Tipo_Osc(unsigned short reloj)
{
    __builtin_write_OSCCONH(reloj); /* Función para configurar el tipo de reloj a
                                     * a utilizar.*/
}

void Sec_Osc(unsigned short secosc) /* Función para habilitar el uso del
                                     * oscilador secundario. */
{                                   
    __builtin_write_OSCCONL(secosc);
}

 
my header file "temporizadores.h" is like follows:
 

#ifndef TEMPORIZADORES_H
#define TEMPORIZADORES_H

#include <xc.h> // include processor files - each processor file is guarded.

void Ciclo_Timer1(unsigned int tempo1, unsigned int conf1);/* Prototipo de
                                         * función para configurar el
                                         * funcionamiento del timer 1. */

void Inicia_Ciclo_Timer1(void);         /* Prototipo de función para iniciar el
                                         * funcionamiento del timer 1. */

void Detiene_Ciclo_Timer1(void);        /* Prototipo de función para detener el
                                         * funcionamiento del timer 1. */

 
mi source file "temporizadores.c" is like follows:
 

#include "temporizadores.h"
#include "sistema.h"

/* Implementación de las funciones para la configuración de los temporizadores*/

void Ciclo_Timer1(unsigned int tempo1, unsigned int conf1) /* Función para la  */
{                                       /* configuración del timer 1.         */
    Sec_Osc(SOSCENH);                   /* No se inicia el timer 1 en esta    */
    T1CON = 0;                          /* ción para dejar al usuario decidir */
    TMR1 = 0;                           /* cuando encenderlo.                 */
    T1CON = conf1;                      /* Está configurado para contar 100ms */
    PR1 = tempo1*0x0ccd;                /* y se usará para hacer el reloj en  */
}                                       /* tiempo real.                       */

void Inicia_Ciclo_Timer1(void)          /* Inicia el timer 1.                 */
{
    T1CONbits.TON = 1;


void Detiene_Ciclo_Timer1(void)         /* Detiene el timer 1.                */
{
    T1CONbits.TON = 0;
}

 
my "main.c" is the following:
 

int main(void) {
    Tipo_Osc(PROSC);
    Sec_Osc(SOSCENH);
    Confi_E_S();
    Inicia_Interr();
    Ciclo_Timer1(100,0b0000000000000010);
    PORTDbits.RD11 = 1;
    Inicia_Ciclo_Timer1();
    while(!IFS0bits.T1IF);
    PORTDbits.RD11 = 0;
    Detiene_Ciclo_Timer1();
    while(1);
    return 0;
}

 
mi "interrup.h" is:
 

#ifndef INTERRUP_H
#define INTERRUP_H

#include <xc.h>
#include "globales.h"

/*            Definición de constantes a usar en las interrupciones.          */

void Inicia_Interr(void);           /* Prototipo de función para configurar e
                                     * iniciar las fuentes de interrupción.   */

/* Prototipos de función para manejar las fuentes de interrupción */

void __attribute__((interrupt(no_auto_psv))) _T1Interrupt(void);/* Prototipo de
                                             * función para manejar la
                                             * interrupción del timer 1.      */

void __attribute__((interrupt(no_auto_psv))) _T2Interrupt(void);/* Prototipo de
                                             * función para manejar la
                                             * interrupción del timer 2.      */

void __attribute__((interrupt(no_auto_psv))) _CNInterrupt(void);/* Prototipo de
                                             * función para manejar la
                                             * interrupción por notificación
                                             * de cambio en los pines
                                             * seleccionados.                 */
#endif /* INTERRUP_H */

 
mi interrup.c is:
 

#include "interrup.h"

void Inicia_Interr(void)                /* Función para configurar e iniciar
                                         * las fuentes de interrupción.       */
{
    IEC0bits.T1IE = 1;                  /* Configuración de las interrupciones*/
    IPC0bits.T1IP = 1;                  /* para el timer 1.                   */
    IFS0bits.T1IF = 0;
   
    IEC0bits.T3IE = 1;                  /* Se habilita la interrupción        */
                                        /* para el timer de 32 bits, se       */
    IPC2bits.T3IP = 1;                  /* establece la prioridad de la       */
    IFS0bits.T3IF = 0;                  /* interrupción en 1 y se borra la    */
                                        /* la bandera del timer de 32         */
                                        /* bits.                              */
   
    IEC1bits.CNIE = 1;                  /* Se habilitan los pines CN62 a CN65 */
    IPC4bits.CNIP = 2;                  /* para detectar el cambio de estado, */
    IFS1bits.CNIF = 0;                  /* esto es, los Puerto E,4 a Puerto   */
    CNEN4 = 0xc000;                     /* E,7 para detectar la tecla         */
    CNEN5 = 0x0003;                     /* presionada. También se configuró la*/
                                        /* prioridad de la interrupción por   */
                                        /* notificación de cambio de estado en*/
                                        /* 2, un nivel más alta que la del    */
                                        /* temporizador.                      */
}

/*               Funciones para el manejo de interrupciones                   */

void __attribute__((interrupt(no_auto_psv))) _T1Interrupt(void)/* Función para*/
{                                       /* manejo de la interrupción del      */
                                        /* timer 1, para usarlo como ciclo de */
    IFS0bits.T1IF =0;                   /* trabajo del sistema.               */
}

 
but since timer 1 does not increase then it does not enter the interrupt routine for timer 1.
In the end I can configure succesfully 32 bit timers but I can't configure the timer 1
 
Could someone help me with this? Thanks in advance for the help provided.
#1
ric
Super Member
  • Total Posts : 25493
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Timer 1 won't work with PIC24 simulated in proteus 2020/01/28 20:43:58 (permalink)
0
This sounds like a Proteus problem.
Proteus is NOT a Microchip product. they have their own support forum.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
vra
Senior Member
  • Total Posts : 123
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
Re: Timer 1 won't work with PIC24 simulated in proteus 2020/01/28 21:15:24 (permalink)
0
ric
This sounds like a Proteus problem.Proteus is NOT a Microchip product. they have their own support forum. 


Thanks Rick, I only wanted to know if my code was well written because I couldn't understand why it doesn't work.
#3
Aussie Susan
Super Member
  • Total Posts : 3663
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: Timer 1 won't work with PIC24 simulated in proteus 2020/01/29 18:22:11 (permalink) ☄ Helpfulby vra 2020/02/04 15:58:00
5 (2)
In 'Ciclo_Timer1' you set PR1 to the parameter 'tempo1' multiplied by 0x0ccd (or 3,277). When you call that function,you are specifying the parameter to be 100 - 100 * 3277 = 327,700 = 0x50014 which will be truncated to 0x0016 (as a 16-bit value).
Do you intend that to happen? (It has all of the hallmarks of a logic error to me.)
However, I suspect that you problem is with the other parameter that you pass in - that big long binary value that has bit 1 set. That is used to set T1CON which means that you are setting the TCS bit. With that bit set, the clock source is the T1CK pin. If you are not driving that in your simulation when the timer will just sit there.
Susan
#4
vra
Senior Member
  • Total Posts : 123
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
Re: Timer 1 won't work with PIC24 simulated in proteus 2020/02/04 14:55:00 (permalink)
0
Aussie Susan
In 'Ciclo_Timer1' you set PR1 to the parameter 'tempo1' multiplied by 0x0ccd (or 3,277). When you call that function,you are specifying the parameter to be 100 - 100 * 3277 = 327,700 = 0x50014 which will be truncated to 0x0016 (as a 16-bit value).
Do you intend that to happen? (It has all of the hallmarks of a logic error to me.)
However, I suspect that you problem is with the other parameter that you pass in - that big long binary value that has bit 1 set. That is used to set T1CON which means that you are setting the TCS bit. With that bit set, the clock source is the T1CK pin. If you are not driving that in your simulation when the timer will just sit there.
Susan




Hi Susan, thanks for the help. In fact the parameter of PR1 was wrong and "thank you for the clarification".
 
About the timer 1 source even if the oscillator circuit is in the simulation, the model of the microcontroller  doesn't do anything with that because the labcenter staff says in the help that the model use a written modifiable parameter as timer clock source so I don't what to do next.
#5
vra
Senior Member
  • Total Posts : 123
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
Re: Timer 1 won't work with PIC24 simulated in proteus 2020/02/04 15:57:19 (permalink)
0
@Aussie Susan thanks again for the help, wath was wrong was my undertanding of how timer 1 uses the external clock (just as you said), I've just putted an square signal of 32768 Hz in T1CK and the timer 1 started to work (as you said).
 
Thank you so much.
 
#6
Jump to:
© 2020 APG vNext Commercial Version 4.5