Menu

Data signal modulator (DSM) question

Help
2019-11-27
2019-11-30
  • Jim giordano

    Jim giordano - 2019-11-27

    I'm trying to use the DSM module to copy FOSC to an output pin.
    Here is my code-

    #option Explicit
    #chip 16F18313,.032768  ' 32K crystal on ra4-ra5
    #config rstosc=ext1x, fextosc=lp
    
    #startup InitPPS, 85
    Sub InitPPS
      UNLOCKPPS
      RA2PPS = 0x001F    'DSM > RA2
      LOCKPPS
    End Sub
    
    dir ra1 out ' led
    dir ra2 out ' clock
    
    osccon1=b'01110000' 'do clock switch, set nosc=7 (extosc), and ndiv=0
    do while (!ORDY):loop
    
    mdcon=0   ' disable dsm and set defaults
    mdsrc=0
    mden=1    ' bit to enable dsm module
    mdsrc=0   ' set mdms bits in mdsrc (use mdbit as modulator)
    mdcarl=0b1010 ' use fosc as one signal, not inverted, not synchronized
    mdcarh=0  ' use vss as one signal, not inverted, not synchronized
    mdout=1   ' bit to enable dsm output (to be sent to ra2)
    
    mdbit=1   ' modulator signal on
    
    ra1=1
    
    do: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 :)

     
  • Jim giordano

    Jim giordano - 2019-11-27

    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.

     
    • Chris Roper

      Chris Roper - 2019-11-27

      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
  • Anobium

    Anobium - 2019-11-27

    I can look later this week. I doing real for a few days.

    I would be using DSM and CLC.

     
  • Jim giordano

    Jim giordano - 2019-11-27

    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
  • William Roth

    William Roth - 2019-11-30

    Why not use the Reference Clock Output Module ? Should output FOSC as a square wave.
    See the Datasheet (Page 361)

    1. Use PPS to configure reference clock output pin
    2. Configure pin as output
    3. 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
    • Jim giordano

      Jim giordano - 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.

      #option Explicit
      
      '#define dolfint
      #ifdef dolfint
        #chip 16F18313,.031000  ' 31K internal
        #config RSTOSC=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=0
      do while (!ORDY):loop
      #endif
      
      #define docrystal
      #ifdef docrystal
        #chip 16F18313,.032768  ' 32K crystal on ra4-ra5
        #config rstosc=ext1x, fextosc=lp
        ' switch to external crystal
        osccon1=b'01110000' 'do clock switch, set nosc=7 (extosc), and ndiv=0
        do while (!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
      #startup InitPPS, 85
      #define PPSToolPart 16F18313
      Sub InitPPS
        UNLOCKPPS
        'Module: CLKREF
        RA2PPS = 0x001E    'CLKR > RA2
        LOCKPPS
      End Sub
      
      dir ra1 out ' led, just to make sure it's working
      dir ra2 out ' clock
      
      clkrcon=0b10010000   ' 50% duty cycle should be ignored when using fosc
      
      ra1=1
      do: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 :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.