• AVR Freaks

Timer1 on PIC24FJ128GA010

Author
JTP5568
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2018/04/16 16:22:06
  • Location: 0
  • Status: offline
2019/11/20 09:14:20 (permalink)
0

Timer1 on PIC24FJ128GA010

All,
I am working to configure the clock on the PIC24FJ128GA010.  To confirm oscillator and timer functionality, I am using an LED blinker to confirm delays.  I would like to use the internal oscillator / PLL combination to achieve 32 MHZ oscillation frequency.  When I configure the oscillator, I select 'FRCDIV' to select the fast RC oscillator with PLL module.  This would give me a FCYC = Fosc / 2.
 
Configuration bits are shown in the code snippet:
 
// CONFIG2
#pragma config POSCMOD = NONE // Primary Oscillator Select (Primary oscillator disabled)
#pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = FRCDIV // Oscillator Select (Fast RC Oscillator with PLL modjkule (FRCPLL))
#pragma config IESO = ON // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) enabled)

// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Windowed Watchdog Timer enabled; FWDTEN must be 1)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2 // Comm Channel Select (Emulator/debugger uses EMUC2/EMUD2)
#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)

 
I then move on to configure the timer 1 register.  I do not intend to use the period reset so I do not initialize the PR1 register.  My initialization of timer 1 along with the delay function is shown below:
 
void initTimer(void)
{
    TMR1 = 0; /* Clear timer register */
    T1CON = 0x8030;
}

void Delay(void)
{
    while (TMR1 < Delay)
    {
        Nop();
        if (TMR1 > 800)
        {
            Nop();
        }
    }
}

 
What I am finding is that TMR1 is not incrementing above 900.  I wanted to see if I would be able to achieve a delay of 1 second but this would require TMR1 to count to ~62,500.  Since TMR1 is a 16 bit register this should be achievable?  Is there anything in my configuration that would be off?  I am using (2/32000000)*256*62500 = 1s.
#1

1 Reply Related Threads

    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Timer1 on PIC24FJ128GA010 2019/11/20 12:22:00 (permalink)
    0
    JTP5568
    ...
    What I am finding is that TMR1 is not incrementing above 900.

    How do you know?
    i.e. what precise test are you doing to determine this?
     

    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
    Jump to:
    © 2019 APG vNext Commercial Version 4.5