• AVR Freaks

Hot!Unable to change REFOCONbits.RODIV

Author
alj
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2015/02/14 13:31:44
  • Location: 0
  • Status: offline
2020/03/30 00:47:53 (permalink)
0

Unable to change REFOCONbits.RODIV

Hi Everybody!
I'm trying to make programmable clock divider based on PIC24F08KL301  .
 
I have external clock supplied to pin 7 and I have divided clock coming in out of pin 18.
the "rate" consists from 3 lower bits which represent division, with 4th bit representing external relay switching XTAL.
Everything works great except that i cannot change clock division.
Writes to REFOCONbits.RODIV do not change the output.
I tried different combination, to the point of completely removing all logic and changing division twice - it does not work.
Also if I disable output (REFOCONbits.ROEN = 0;) then enable it again - it does not get reenabled.
 
Maybe there is a config that prevents me from changing divisor? Did not find anything in dox. Errata does not have anything related to this issue.
 
my project sources:
https://gitlab.com/aleynikov/daccontrol/-/tree/Forum/DACcontrol.X
init is done in DACmain.c  lines 86 - 93
clock change is done in dac.c line 74
 
What am i doing wrong and how can I change divider?
 
 
Any help is greatly appreciated.
#1

6 Replies Related Threads

    NorthGuy
    Super Member
    • Total Posts : 6072
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Unable to change REFOCONbits.RODIV 2020/04/02 07:07:29 (permalink)
    4 (1)
    Puzzling.
     
    Does the REFOCON register change. Can you read it and see the value?
     
    Does the problem persist if you set ROSEL to 0?
    #2
    alj
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2015/02/14 13:31:44
    • Location: 0
    • Status: offline
    Re: Unable to change REFOCONbits.RODIV 2020/04/02 19:04:09 (permalink)
    0
    Short answer: Yes the register changes, yes the problem persists.
     
    I e i can write different values to REFOCON.RODIV and if i immediately read the value from REFOCON.RODIV it changes to the one i just wrote.
    But the output does not change and it corresponds only to the FIRST value I wrote to RODIV in DACmain.c. If I change that first value then output is different (and corresponds to that value) but I cannot ever change it second time even though actual value in register changes (checked by reading).
     
    If I set ROSEL to 0 behavior does not change. I e I still cannot change output but the value in the REFOCON.RODIV changes fine.
    #3
    alj
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2015/02/14 13:31:44
    • Location: 0
    • Status: offline
    Re: Unable to change REFOCONbits.RODIV 2020/04/02 19:08:51 (permalink)
    0
    More info about chip:
    Chip errata:
    http://ww1.microchip.com/downloads/en/DeviceDoc/80000534e.pdf
     
    This is chip datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/30001037c.pdf
    page 102 says about REFOCON
     
    Here is general oscillator guide http://ww1.microchip.com/downloads/en/devicedoc/39700c.pdf
    from 6:13 ..... "This postscaler can be changed as needed at run time. It is recommended that the
    clock generator be disabled prior to changing the RODIV bits to ensure the smoothest speed
    transition."



    This presumes that i do not need to disable clock generator. But then if i did i cannot re-enable it ever again.
    #4
    alj
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2015/02/14 13:31:44
    • Location: 0
    • Status: offline
    Re: Unable to change REFOCONbits.RODIV 2020/04/02 20:27:36 (permalink)
    0
    Also tried __builtin_write_OSCCONL((uint8_t) (0x01))  after divisor change - no success.
     
    #5
    NorthGuy
    Super Member
    • Total Posts : 6072
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Unable to change REFOCONbits.RODIV 2020/04/03 06:19:01 (permalink)
    5 (1)
    If the value in REFOCON has changed, but the output frequency has not, this is obviously a silicon bug. In this case, you should file a support ticket with Microchip. However, silicon bugs are rare, so you should report a bug only if you're 100% sure that's the case. The best way to make sure is to create a separate project, which initializes REFOCON, then changes the value after a second or two. Make sure there's nothing else in the project and that WDT is disabled. If the problem persists, send the test project to Microchip along with a ticket. However, It's much more likely that you'll find out that the test project works as expected, which means that there's a bug in your code.
     
    It's likely that your project overwrites your new REFOCON values elsewhere - either your code does this unintentionally, or WDT resets the PIC restoring the initial values, or something of that sort.
     
     
    #6
    alj
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2015/02/14 13:31:44
    • Location: 0
    • Status: offline
    Re: Unable to change REFOCONbits.RODIV 2020/04/18 15:46:17 (permalink)
    5 (1)
    I figured out the issue.
    1. When changing divisor need to cycle ROEN off and on.
    2. When you enable output you cannot disable it immediately, THis is what caused the problem so it seem. I removed code which was setting divisor 2-nd time (and doing ROEN off and on) right away and problem went away. However this issue does not happen if clock source is system clock, i e only with external clock source.
    post edited by alj - 2020/04/18 16:00:44
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5