• AVR Freaks

Hot!Timer1 RTC - need help

Author
Martin
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2010/06/29 12:12:01
  • Location: 0
  • Status: offline
2019/05/04 13:25:40 (permalink)
0

Timer1 RTC - need help

Hello,
I have 32kHz oscillator connected on pins SOSCI and SOSCI of my dsPic30F4013. my problem is that  the timer counter is not increasing when the TCS is set to external. TMR1 is always 0x0000 without any movement.
What  i am doing wrong? Please help.
 
The timer1 is configured like this:
 
_TCS = 1; //source internal 1- external,0-internal
_TSYNC = 0; //Async
_TON = 1; //enable timer 1
_LPOSCEN =1 ;
_T1IE = 1; //enable interrupt
_TCKPS = 3; //PRESCALLER 1:256
PR1 = 0xffff;
 
post edited by Martin - 2019/05/04 23:00:10
#1

2 Replies Related Threads

    dan1138
    Super Member
    • Total Posts : 3166
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Timer1 RTC - need help 2019/05/05 02:04:01 (permalink)
    0
    From the dsPIC30F4013 data sheet DS70138G-page 146:

    20.2.8 PROTECTION AGAINST ACCIDENTAL WRITES TO OSCCON

    A write to the OSCCON register is intentionally made difficult because it controls clock switching and clock scaling.

    To write to the OSCCON low byte, the following code sequence must be executed without any other instructions in between:

    Byte Write 0x46 to OSCCON low
    Byte Write 0x57 to OSCCON low

    Byte write is allowed for one instruction cycle. Write the desired value or use bit manipulation instruction.

    To write to the OSCCON high byte, the following instructions must be executed without any other instructions in between:

    Byte Write 0x78 to OSCCON high
    Byte Write 0x9A to OSCCON high

    Byte write is allowed for one instruction cycle. Write the desired value or use bit manipulation instruction.

    Try this:
        _TCS = 1; //source internal 1- external,0-internal
        _TSYNC = 0; //Async
        _TON = 1; //enable timer 1
        // _LPOSCEN =1 ;
        __builtin_write_OSCCONL(OSCCON | (1<<_OSCCON_LPOSCEN_POSITION));
        _T1IE = 1; //enable interrupt
        _TCKPS = 3; //PRESCALLER 1:256
        PR1 = 0xffff;

    #2
    Martin
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2010/06/29 12:12:01
    • Location: 0
    • Status: offline
    Re: Timer1 RTC - need help 2019/05/26 12:44:17 (permalink)
    0
    I found out that all dsPIC30F having general  problem with clock switch to LP oscilator. Is described in errata. Working with LP oscillator with those chips is not possible
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5