I'm trying to use the DSM module to copy FOSC to an output pin.
Here is my code-
#optionExplicit
#chip16F18313,.032768' 32K crystal on ra4-ra5
#configrstosc=ext1x, fextosc=lp
#startupInitPPS, 85SubInitPPSUNLOCKPPSRA2PPS=0x001F'DSM > RA2LOCKPPSEndSubdirra1out' leddirra2out' clockosccon1=b'01110000''do clock switch, set nosc=7 (extosc), and ndiv=0dowhile(!ORDY):loopmdcon=0' disable dsm and set defaultsmdsrc=0mden=1' bit to enable dsm modulemdsrc=0' set mdms bits in mdsrc (use mdbit as modulator)mdcarl=0b1010' use fosc as one signal, not inverted, not synchronizedmdcarh=0' use vss as one signal, not inverted, not synchronizedmdout=1' bit to enable dsm output (to be sent to ra2)mdbit=1' modulator signal onra1=1do:loop
Nothing happens. Can anyone see where I went wrong here?
My goal is to pass the FOSC to an output pin so I can measure precisely what frequency the chip is running on and adjust the caps for the crystal appropriately. Just throwing a scope on SOSCI adds enough capacitance to change the frequency slightly.
I went through all the peripherals, and this seemed the most likely to use, but if anyone else knows an easier way to pass a 32K crystal driven FOSC to an output pin, I would appreciate the info :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I should mention that passing FOSC is not the ultimate goal, I would really like to pass SOSC to an output pin since the final goal is to get it running as good as possible for the six projects I have been working on that need a good clock. If you know how to pass SOSC to an output pin, please enlighten me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FOSC is available and the DSM Module is not required, just use the option CLKOUTEN = ON
and FOSC should be available on pin 3, RA4.
I am not able to test it myself but play around with it and see what you can get, I have used that several times on other devices to test timing with a frequency counter.
Cheers
Chris
Last edit: Chris Roper 2019-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That was my first attempt. After failure I noticed in the desciption-
bit 8 CLKOUTEN: Clock Out Enable bit
If FEXTOSC = EC, HS, HT or LP, then this bit is ignored; otherwise:
1 = OFF CLKOUT function is disabled; I/O or oscillator function on OSC2
0 = ON CLKOUT function is enabled; FOSC/4 clock appears at OSC2<
So, If "FEXTOSC = EC, HS, HT or LP, then this bit is ignored", there is no way to get FOSC to run at 32K and not use FEXTOSC. Thus my attempt to route it through a peripheral module. Also, that would give FOSC/4, not exactly what I was looking for.
I thought I'd ask it case in was some simple thing I was just missing again, but I'll figure something out eventually.
Last edit: Jim giordano 2019-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why not use the Reference Clock Output Module ? Should output FOSC as a square wave.
See the Datasheet (Page 361)
Use PPS to configure reference clock output pin
Configure pin as output
Set CLKRCON Register to CLKRCON = 0b10010000
This works on 16F15323 using internal LFINTC as clock source. (31 Khz). Logic analyzer shows 31.58 Khz on Reference Clock Pin
Should also work on 16F18313 with external crystal. If breadboarding, note that a breadboard will add 2 -4 Picofarads of capacitance at each leg of the crystal.
Last edit: William Roth 2019-11-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This was about the third thing I tried, but back then I didn't know about the bug in the compiler that always sets OSCCON1 to HFINTOSC for the 16F18xxx chips. Doing the clock switch made them work.
#optionExplicit'#define dolfint
#ifdefdolfint
#chip16F18313,.031000' 31K internal
#configRSTOSC=LFINT' switch to lfint (bug in compiler always sets to HFINTOSC for 16F18xxx)osccon1=b'01000000''do clock switch, set nosc=4 (lfintosc) and ndiv=0dowhile(!ORDY):loop
#endif
#definedocrystal
#ifdefdocrystal
#chip16F18313,.032768' 32K crystal on ra4-ra5
#configrstosc=ext1x, fextosc=lp' switch to external crystalosccon1=b'01110000''do clock switch, set nosc=7 (extosc), and ndiv=0dowhile(!ORDY):loop
#endif'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.5.28'PinManager data: v1.78.0'Generated for 16F18313
#startupInitPPS, 85
#definePPSToolPart16F18313SubInitPPSUNLOCKPPS'Module: CLKREFRA2PPS=0x001E'CLKR > RA2LOCKPPSEndSubdirra1out' led, just to make sure it'sworkingdirra2out' clockclkrcon=0b10010000' 50% duty cycle should be ignored when using foscra1=1do:loop
Evan-
If you haven't started on the dsm stuff, you can put it on the long term todo list as I no longer need it :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to use the DSM module to copy FOSC to an output pin.
Here is my code-
Nothing happens. Can anyone see where I went wrong here?
My goal is to pass the FOSC to an output pin so I can measure precisely what frequency the chip is running on and adjust the caps for the crystal appropriately. Just throwing a scope on SOSCI adds enough capacitance to change the frequency slightly.
I went through all the peripherals, and this seemed the most likely to use, but if anyone else knows an easier way to pass a 32K crystal driven FOSC to an output pin, I would appreciate the info :)
I should mention that passing FOSC is not the ultimate goal, I would really like to pass SOSC to an output pin since the final goal is to get it running as good as possible for the six projects I have been working on that need a good clock. If you know how to pass SOSC to an output pin, please enlighten me.
You can't output SOSC, if you needed access to that you would have to use an external clock generator.
https://www.microchip.com/design-centers/clock-and-timing/clock-generation
FOSC is available and the DSM Module is not required, just use the option CLKOUTEN = ON
and FOSC should be available on pin 3, RA4.
I am not able to test it myself but play around with it and see what you can get, I have used that several times on other devices to test timing with a frequency counter.
Cheers
Chris
Last edit: Chris Roper 2019-11-27
I can look later this week. I doing real for a few days.
I would be using DSM and CLC.
That was my first attempt. After failure I noticed in the desciption-
So, If "FEXTOSC = EC, HS, HT or LP, then this bit is ignored", there is no way to get FOSC to run at 32K and not use FEXTOSC. Thus my attempt to route it through a peripheral module. Also, that would give FOSC/4, not exactly what I was looking for.
I thought I'd ask it case in was some simple thing I was just missing again, but I'll figure something out eventually.
Last edit: Jim giordano 2019-11-27
Why not use the Reference Clock Output Module ? Should output FOSC as a square wave.
See the Datasheet (Page 361)
This works on 16F15323 using internal LFINTC as clock source. (31 Khz). Logic analyzer shows 31.58 Khz on Reference Clock Pin
Should also work on 16F18313 with external crystal. If breadboarding, note that a breadboard will add 2 -4 Picofarads of capacitance at each leg of the crystal.
Last edit: William Roth 2019-11-30
Yes! That works. Thanks :)
This was about the third thing I tried, but back then I didn't know about the bug in the compiler that always sets OSCCON1 to HFINTOSC for the 16F18xxx chips. Doing the clock switch made them work.
Evan-
If you haven't started on the dsm stuff, you can put it on the long term todo list as I no longer need it :)