Author Topic: PIC24F - cannot reprogram reference clock output.  (Read 2222 times)

0 Members and 1 Guest are viewing this topic.

Offline aljTopic starter

  • Contributor
  • Posts: 17
  • Country: us
PIC24F - cannot reprogram reference clock output.
« on: March 31, 2020, 08:47:50 pm »
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. I e i can initially set it but consequent writes to REFOCONbits.RODIV have no effect.

Also if I disable output (REFOCONbits.ROEN = 0;) then enable it again - it does not get re-enabled, there is no clock in the output, where it was there prior to disabling.
 
Maybe there is a config that prevents me from changing reference clock reprogramming? 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 divisor?
 
 
Any help is greatly appreciated.
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: PIC24F - cannot reprogram reference clock output.
« Reply #1 on: April 01, 2020, 07:00:15 am »
In some PIC24s there may be two things at play:

One of the configuration registers may have a bit which determines how many times certain other registers are able to be changed. Things like peripheral pin assignments and oscillator config can be limited to a single configuration between resets.

If that bit is set to allow multiple reconfigurations then you may need to perform an unlock sequence sequence each time you want to change them (this is meant to prevent inadvertant changes during operation). There are some built-in macros in xc24 that allow you to unlock the OSCCON register, which then also allows things like the PPS configuration to be changed. It's something along the lines of __builtin_osccon_unlock or thereabouts. You could check the xc24 manual for details.

I don't have access to specifics right now so going by memory, but look into those two things and see how you get on.
 

Offline aljTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: PIC24F - cannot reprogram reference clock output.
« Reply #2 on: April 01, 2020, 10:25:49 am »
I read all dox left and right. There is FCKSM1 configuration bit which unlocks writing to OSCCON, but I'm not even touching it.
General PIC24F dox says i can write to REFOCONbits.RODIV as many times as i like without even disabling REFOCONbits.ROEN  (although it is recommended to disable then enable after change). But.... i cannot even do that alone (disable then enable). What is really weird is that if i wasnt allowed to modify REFOCON then i should not be able to disable it, but i can enable then disable and then I cannot reenable it anymore.

This is chip datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/30001037c.pdf
page 101 says about FCKSM1
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."

Chip errata:
http://ww1.microchip.com/downloads/en/DeviceDoc/80000534e.pdf
... it is amazing that they mislabeled chip pins in the doc. Cost me some lost time and PCB cutting.


And this chip does not have PPS so it seems.  I'm almost ready to redo PCB and try it on some other PIC (or maybe get different DIP20 chip with PPS and make it pin-compatible) but what if (as most oftenly happens) this is my screwup and that will not fix the issue.....
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: PIC24F - cannot reprogram reference clock output.
« Reply #3 on: April 01, 2020, 11:11:00 pm »
Hm yes, tricky situation. I would also post on the Microchip forum itself. Dont get me wrong, there are some very helpful people here on the EEVblog forum and I have had some of my own questions answered here, but you may find more focussed and specialised help over there.
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: PIC24F - cannot reprogram reference clock output.
« Reply #4 on: April 02, 2020, 10:55:28 pm »
 :(

Not sure what else. I read through the docs and it seems straight forward enough, but Ive never used anything like this personally so other than going right back to basics (although your code doesnt look overly complex) I feel fresh out of ideas.

The *only* thing I would try is using the OSCCON unlock sequence and see if that does anything at all. It doesnt seem like it will from what the docs say, but sometimes you never know. Could be a new erratta item.  :-//

Final resort, perhaps make a support request to Microchip themselves and see if you can get any joy directly from them.
 

Offline aljTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: PIC24F - cannot reprogram reference clock output.
« Reply #5 on: April 18, 2020, 10:46:02 pm »
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 right away (and cycling ROEN off and on) and problem went away. However this issue does not happen if clock source is system clock, i e only with external clock source.
« Last Edit: April 18, 2020, 11:02:41 pm by alj »
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 861
  • Country: gb
Re: PIC24F - cannot reprogram reference clock output.
« Reply #6 on: April 21, 2020, 08:50:33 am »
Good to know you got it sorted.

I suppose there's nothing in the manual to suggest you had to do that...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->