• AVR Freaks

Hot!Calibrate Oscilloscope

Page: 12 > Showing page 1 of 2
Author
Speedi
New Member
  • Total Posts : 13
  • Reward points : 0
  • Status: offline
2019/11/04 05:14:08 (permalink)
0

Calibrate Oscilloscope

Hi
 
In advance, sorry if I get worded wrong or used wrong grammar.
 
Have been playing around with an PIC16F for a while now, to learn, and PIC16F73 because that's what I had lying around, and I use PicKit 3.
 
Previously only familiar with Basic, Turbo Pascal, VB6.0 and superficial assembly. So it takes some time as I have to get myself into the PIC settings and learn C++, but it is slowly moving forward :)
 
For the most part I have made great use of this forum, searched and read, but now I do not seem to be able to find an answer to a question, which I hope you could help me with.
 
Have learned the control of Ports I/O, made an I2C protocol, made a setup for A/D, made some INT and Timer. So still much to be learned. When I started with I2C and found that this PIC does not have full master and I do not seem to be able to make it work, like what I have read in many places, eg baud rate.
 
SSPEN = 0 /off 
SSPM3-0 = 1011 /master with firmware
CKP = 0 /clock stretch
UA = 0 /no update (10-bit)
SSPEN = 1 /on
 
The only thing this did was that I could take control of RC3 and 4, but I had to control everything myself, and it really worked fine. A week ago, I sat and watched Project Properties, under XC8 Linker and put the checkmark in the Calibrate oscillator, this changed everything. It has made some features work, but on the other hand has done everything I have programmed unstable and unpredictable :-/ as if the PIC has got a brain of its own :) 
 
Question 1)
Now it seems a bit like the settings I make during Initialize are the settings the PIC is constantly looking back to, so if in initialize eg RB0 = 0 and in execution under main set RB0 = 1, then RB0 does not stay 1, but automatically goes back to 0, but how can this happen since the PIC does not have multi threads?
 
Have understood that the osc code is automatically erased when the PIC is erased and that it is not automatically rewritten, and also that this code is not code protected. So wonder why this is not by default marked in properties, but do not quite understand what the difference is?
 
Question 2)
If I need to write/set up this osc calibration manually, where or in what register do I do this? and what is the default value that Microsoft has set and that is not recommended to change? (Alternate oscillator calibration value 0x3400)
 
Question 3)
Setop as HS at 16Mhz (CCO), but when using calibrate oscillator, it seems more like that the PIC is using internal RC and that the external osc is not used at all, is this correct?
 
Without the use of calibrate oscillator, I often seem to not have oscillated at start, but seems to work every time witch calibrate oscillator turned on. Has been confusing, especially after using the calibrate oscillator. 
 
Without having change my code and when I write to I2C I find that after sending data out, RC4 starts to swing by itself, and afterwards when RC3-4 should being idle, RC4 is still swings. Why RC4 does it and not RC3, I don't understand. Maybe for the same reason as written under question 1?
 
Hope you can help me further in my search for understanding, thank you.
 
#1

25 Replies Related Threads

    jack@kksound
    code tags!
    • Total Posts : 3211
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 12:48:26 (permalink)
    0
    I suggest you post the code you are using to test in the PIC, all of it.
    #2
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 12:52:24 (permalink)
    0
    It will say nothing about the calibration oscillator.
    #3
    1and0
    Access is Denied
    • Total Posts : 9864
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 13:11:57 (permalink)
    +1 (1)
    I see as you do in XC8 Project Properties > XC8 Linker > Runtime, there is a checkbox for "Calibrate oscillator" to initialize the oscillator with the oscillator constant. However, as far as I know, the PIC16F73 does _NOT_ have an oscillator calibration.
     
    Edit: I must have missed something. What does the linker has to do with oscillator calibration?!.
    Edit2: To answer myself, I guess the code snippet to read and store the calibration value is linked in by the linker. ;)
    post edited by 1and0 - 2019/11/04 13:28:01
    #4
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 13:39:00 (permalink)
    0
    Ok, but otherwise read that it is only the MID-RANGE MCU FAMILY that has it, otherwise I couldn't find anything about it. However, it does make a difference as mentioned.

    http://www.farnell.com/da..eets/1931209.pdf#page63

    http://www.farnell.com/da...ts/1931209.pdf#page123

    http://www.farnell.com/da...ts/1931209.pdf#page209

    😁
    post edited by Speedi - 2019/11/04 13:47:42
    #5
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/04 13:43:26 (permalink)
    +2 (2)
    Speedi
    ...
    Previously only familiar with Basic, Turbo Pascal, VB6.0 and superficial assembly. So it takes some time as I have to get myself into the PIC settings and learn C++, but it is slowly moving forward :)

    I assume you are using XC8 as the C compiler.
    Note, this is C, not C++ !
    Microchip do not have any C++ compilers for 8 bit PICs (or 16 bit ones, only the 32 bit PIC32 series)(
     

    When I started with I2C and found that this PIC does not have full master and I do not seem to be able to make it work, like what I have read in many places, eg baud rate.

    Indeed.
    You have chosen a very old, very simple part, which only has full support for I2C Slave mode.
    Many PIC's from nearly 20 years ago also have support for Master mode, but the PIC16F73 is not one of them.
    If you'd chosen a more recent part, it would have been cheaper, have full I2C support, and a much better built in clock that could run up to 32MHz.
     

    Now it seems a bit like the settings I make during Initialize are the settings the PIC is constantly looking back to, so if in initialize eg RB0 = 0 and in execution under main set RB0 = 1, then RB0 does not stay 1, but automatically goes back to 0, but how can this happen since the PIC does not have multi threads?

    Those old PIC's have a problem when accessing GPIO ports rapidly, due to the RMW (Read-Modify-Write) operaiton of the BSF and BCF instructions. There are literally thousands of topics in this forum talking about this.
    Again, a more modern PIC16F device totally cures this problem by implementing "LATx" registers.
     

    Have understood that the osc code is automatically erased when the PIC is erased and that it is not automatically rewritten, and also that this code is not code protected. So wonder why this is not by default marked in properties, but do not quite understand what the difference is?

    The internal oscillator calibration value IS automatically saved and restored if you use Microchip tools to program your chip. It shouldn't matter if you're using the external oscillator though.
    Edit: As 1and0 states, this PIC does not have a calibration value (as it does not contain an internal oscillator to calibrate)
     
    We don't know HOW you are enabling the external oscillator because you have resisted showing us all your code.
     
     
    post edited by ric - 2019/11/04 14:26:25

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    1and0
    Access is Denied
    • Total Posts : 9864
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 14:17:36 (permalink)
    +1 (1)
    Speedi
    Ok, but otherwise read that it is only the MID-RANGE MCU FAMILY that has it, otherwise I couldn't find anything about it. However, it does make a difference as mentioned.

    As I said, the PIC16F73 does ***NOT*** have an internal oscillator calibration constant.
    post edited by 1and0 - 2019/11/04 14:18:50
    #7
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 14:38:03 (permalink)
    0
    Ric
     
    There is a lot to keep track of, so only C and not C++ (y)
     
    Read something about this the other day. Read Modify Write Problem with Mid-Range PIC Microcontrollers
     
    Is there anything else I can or should setop about osc?
    "Question 3) Setop as HS at 16Mhz (CCO)"
     
    // CONFIG
    #pragma config FOSC = HS
    #pragma config WDTE = OFF
    #pragma config PWRTE = OFF
    #pragma config CP = OFF
    #pragma config BOREN = OFF
     
    #define _XTAL_FREQ 16000000
    #8
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 14:43:34 (permalink)
    0
    1and0
     
    Understood, but why is there a change / difference when it's turned on?
     
    It should also be mentioned that just before, MPLAB was also updated to 5.25 Do not know if this may also have an impact on the change I experience?
     
    #9
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/04 14:47:42 (permalink)
    0
    Yes, the CONFIG settings look ok, assuming you have an external 16MHz crystal connected with the correct load capacitors.
    The _XTAL_FREQ line does not control your speed. That is how you tell the compiler how fast you are running so it can correctly calculate the software delays in the __wait_us() and __wait_ms() macros.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 15:02:35 (permalink)
    0
    ric
     
    It is a Colpitts Crystal Oscillator and have examined it with frequency counter and it oscillates in neat and stable sinus curve.
     
    Ok, so the PIC is not set to run that frequency :-/ what frequency does it run with, now that I do not enable the internal RC?
     
    Which PIC would you recommend that is closest to 73?
    post edited by Speedi - 2019/11/04 15:04:23
    #11
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/04 15:20:18 (permalink)
    0
    Speedi
    ric
     
    It is a Colpitts Crystal Oscillator and have examined it with frequency counter and it oscillates in neat and stable sinus curve.

    So you're not using the oscillator circuit built into the PIC at all?
    Which PIC pin have you connected the output to?
     

    Ok, so the PIC is not set to run that frequency :-/ what frequency does it run with, now that I do not enable the internal RC?

    If you're using an external oscillator, then it runs at the speed of that oscillator.
     

    Which PIC would you recommend that is closest to 73?

    You can use Microchip's selection guide at https://www.microchip.com/maps/microcontroller.aspx
    and select any PIC16F1xxxx or PIC16F1xxxxx device that matches your requirements.
     
    If you want a 28 pin device in a DIP package, a PIC16F1512 or PIC16F15345 is about a third of the price of a PIC16F73, and much nicer.
    However there are lots of choices for only a few cents more, depending upon what mix or memory and peripherals you would like.
    If this is for experimenting, one which has PPS (Programmable Pin Select) can be very useful, as it lets you connect peripherals to almost any pin you want.
     
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/04 15:35:09 (permalink)
    +1 (1)
    n.b. I've just used a PIC16F18456 in a couple of "one off" designs, and it's a very nice part to work with.
    Two UARTS, PPS, and a number of interesting peripherals I haven't even played with yet.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #13
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/04 16:11:33 (permalink)
    0
    To get to know the PIC, I have deactivate everything, I assume, and then only activated what I need when I need it. Otherwise, there is too much confusion, which happens very quickly anyway :( So no, not what I have the opportunity to deactivate and is conscious of, I do not use the internal RC. Neither Timer, even I have tried Timer0 for a time :)
     
    Pin 9 is In and pin 10 is out, do not use pin 10 (out)
     
    "runs at the speed of that oscillator" OK, now for a moment you made me more confused about the frequency :D
     
    The link is nice, has only seen another version of the one and tried to search, bought PIC16F1713-I/SP and PIC18F23K20-I/SP, both wrong :) Wrong dip and volts, but now I have them.. Quickly read about PPS, sounds like a really good idea (y)
     
    Although I am someone who wants to finish what I am working on, learning. Then I also think that this 73 seemed unstable, but just thought it was my programming or lack of understanding of the circle. With the "mistakes" and shortcomings it has, it is probably unnecessary learning, even though it has taught me a lot...
    #14
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/05 00:29:01 (permalink)
    0
    Speedi
    To get to know the PIC, I have deactivate everything, I assume, and then only activated what I need when I need it.

    Almost everything starts off deactivated anyway.
    The only thing you actively need to "disable" is if you are using analog capable pins for a digital function, as they always power up in analog mode.
     

    ...
    Pin 9 is In and pin 10 is out, do not use pin 10 (out)

    So you are saying you connected your oscillator to pin 9?
    Yes, that is the CLKIN pin, so should work.
     

    "runs at the speed of that oscillator" OK, now for a moment you made me more confused about the frequency :D

    Why?
    If your external oscillator is 16MHz, then that is your PIC's oscillator frequency.
    Where is the confusion?
     

    The link is nice, has only seen another version of the one and tried to search, bought PIC16F1713-I/SP and PIC18F23K20-I/SP, both wrong :) Wrong dip and volts, but now I have them..

    I see the PIC16F73 is a full width DIP, and the 1713 is a skinny DIP. That should be easy to work around.
    What do you mean "wrong volts" ?
    They can both run from 5V
     
    post edited by ric - 2019/11/05 00:42:03

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    Mysil
    Super Member
    • Total Posts : 3403
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/05 00:37:55 (permalink)
    +1 (1)
    Hi,
    PIC18F23K20-I/SP do not have PPS(Peripheral Pin Select). All pins do what is shown in the Pin diagram Figure 1, and in Table 1. 
    PIC18F23K20 is may Not be powered with any voltage higher than 3.6 V.
    If you have PICkit3 (or PICkit2) for programming, then you may do experiments and debugging in the in the PIC18F23K20 with power from the PICkit programmer. In MPLAB X Project Properties, PICkit3, Option categories: Power, there is settings for Voltage to be used, you may select 3.25V and mark "Power from PICkit 3". Do Not connect  any outside 5V power supply.
     
    PPS may be useful, but it is one more challenge to learn, and one more possibility of making mistakes.
    PIC16F1713-I/SP have PPS for many Dgital peripherals.
    You may do some experiments without PPS settings:
    General port I/O using TRISx and LATx registers for Output, and PORTx registers for Input, do not use PPS. 
    Timers using internal clock frequency are not changed by PPS.
    ADC measurements use their own Analog multiplexer in the ADC peripheral, and do not use PPS.
    PIC16F1713-I/SP may be used with any power voltage between 2.5 V and 5.5 V.
     
    Code shown in message #1 is wrong, in C language, comments should be written either as:
    /* Comment txt */
    // or, Another comment line
        SSPEN = 0; // off 
        SSPCON1bits.SSPM = 8;        /* I2C Master mode with clock from Fosc/4 and SSPADD register. */
        SSP1CON1bits.SSPM = 0b1000;   // Another way of doing the same.
        CKP = 0; //clock stretch, This is not used in I2C Master mode.
        UA = 0;  //no update (10-bit)  // This is a read-only status bit that is only used in 10 bit address I2C Slave mode.
        SSPEN = 1 //on  

     
    Regards,
        Mysil
    #16
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/05 02:29:35 (permalink)
    0
    MySil
     
    Only have SSPCON, neither SSPCON1 nor SSP1CON1, but know both
    //
    / ** /
    dec 8 = bin 0b1000 = hex 0x08
    However, this PIC does not have a command 0b1000
     
    0000 = SPI Master mode, clock = FOSC/4
    0001 = SPI Master mode, clock = FOSC/16
    0010 = SPI Master mode, clock = FOSC/64
    0011 = SPI Master mode, clock = TMR2 output/2
    0100 = SPI Slave mode, clock = SCK pin. SS pin control enabled.
    0101 = SPI Slave mode, clock = SCK pin. SS pin control disabled. SS can be used as I/O pin.
    0110 = I2C Slave mode, 7-bit address
    0111 = I2C Slave mode, 10-bit address
    1011 = I2C Firmware Controlled Master mode (slave IDLE)
    1110 = I2C Slave mode, 7-bit address with START and STOP bit interrupts enabled
    1111 = I2C Slave mode, 10-bit address with START and STOP bit interrupts enabled
     
    "CKP = 0; //clock stretch, This is not used in I2C Master mode."
    Isn't it a slave who uses clock stretching, and therefore the master who has to wait for or expect the clock to be stretched?
     
    "SSPCON1bits.SSPM = 8; /* I2C Master mode with clock from Fosc/4 and SSPADD register. */"
    You write "Fosc/4 and SSPADD" what I also read about and which should refer to the baud rate, but don't seem to understand the meaning behind or see an effect from it, since SSPADD is the slave address. Can you elaborate on this?
    #17
    Speedi
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/05 02:43:01 (permalink)
    0
    ric
     
    Only tested A / D with temperature sensitive resistance on RA0 and RA3 as Vref, seemed to work properly, but otherwise disabled it during further experimentation with other functions.
     
    Was confused when you stated this "The _XTAL_FREQ line does not control your speed." but come to understand what you're referring to :)
     
    First ordered 1713 which should have been the same SPDIP as F73, but he sent the thiny one. Then ordered the 23K20 without noticing it was the wide one. Ordered only to not have to spend time making new print layout, but think I will find the PIC I want to use, order it and make a new layout once and for all (y)
     
    #18
    ric
    Super Member
    • Total Posts : 24202
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Calibrate Oscilloscope 2019/11/05 03:12:06 (permalink)
    +1 (1)
    Speedi
    However, this PIC does not have a command 0b1000

    Indeed, because as already discussed, the PIC16F73 does not support Master mode.
    That is the bit pattern used to enable Master mode in PICs that DO support it.
     

    "CKP = 0; //clock stretch, This is not used in I2C Master mode."
    Isn't it a slave who uses clock stretching, and therefore the master who has to wait for or expect the clock to be stretched?

    Which is why it says "not used in I2C Master mode"
     

    "SSPCON1bits.SSPM = 8; /* I2C Master mode with clock from Fosc/4 and SSPADD register. */"
    You write "Fosc/4 and SSPADD" what I also read about and which should refer to the baud rate, but don't seem to understand the meaning behind or see an effect from it, since SSPADD is the slave address. Can you elaborate on this?

    In PICs which do support Master mode, the SSPADD register serves a second purpose, because the Master does not have a slave address. Instead, it is used to hold a value involved in generating the baud clock.
    This is all academic if your PIC doesn't have full Master mode support.
     
    Edit: FYI, in Microchip terminology, an "SSP" peripheral (Synchronous Serial Port) has slave-only I2C capability.
    An MSSP (Master Synchronous Serial Port) has both Master and Slave I2C capability.
     
    Not all MSSP peripherals are identical. Some have more control registers to implement extra functionality
    (e.g. address masking in slave mode, SMBUS compatibility, and so on)
     
    post edited by ric - 2019/11/05 03:40:47

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #19
    1and0
    Access is Denied
    • Total Posts : 9864
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Calibrate Oscilloscope 2019/11/05 03:56:27 (permalink)
    0
    Speedi
    Understood, but why is there a change / difference when it's turned on?
     
    It should also be mentioned that just before, MPLAB was also updated to 5.25 Do not know if this may also have an impact on the change I experience?

    I don't know why there's a change/difference when the "calibrate oscillator" option is turned on. There should be no difference at all as the 16F73 has NO internal oscillator calibration value. I bet the hex files generated with and without that option are identical and work the same. 
     
    If you've observed there is a change, then your problem is elsewhere. ;)
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5