Tosc and Fosc

Discussion in 'The Projects Forum' started by KansaiRobot, Apr 16, 2015.

  1. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Ok. I confess it. I have programmed succesfuly a PWM output for my PIC but have no idea what Tosc and Fosc is.
    Yes, I have read the Datasheet :/ and still can't understand what they refer to.
    I just did a search on the huge datasheet of Tosc. No definition was found.Just 50 uses of it.

    For example the following page http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html ask me "My PIC is clocked at"....

    I have no idea... :( I dont see anywhere in my code where I am setting it.

    and another thing is that what is the correspondence of say 16MHz and whatever register I have to (or did ) set

    Any help... (or maybe it is the end of the workday and I am just tired cause I dont understand....
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,809
    834
  3. OBW0549

    Well-Known Member

    Mar 2, 2015
    1,319
    888
    Fosc = your oscillator frequency (for example, 16 MHz).
    Tosc = 1/Fosc = the period of your oscillator (for example, 62.5 ns in the case of Fosc = 16 MHz).

    The oscillator is configured by the device configuration bits. These are set either in code, with CONFIG statements (if I remember correctly; they may be called something else now), or are set through the Device Configuration menu in MPLAB.
     
    KansaiRobot likes this.
  4. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    In most datasheets it is located in the spreadsheet like tables that come after the electrical characteristics. The section title in Microchip datasheets "AC Characteristics". When you did the massive search did you look at the context in which the term occurred or were you looking for some preconceived image of what a definition is supposed to look like?
     
  5. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Ok so Fosc is frequency of the crystal. But what if I am using the internal oscillator?

    I am using 18F2553. Previously I used the 18F2550.

    My code
    I think I am probably "setting" this in the
    Code (Text):
    1.  #pragma config FOSC=INTOSCIO_EC
    part, but ok, I am using the internal oscillator, but to what frequency??

    Code (Text):
    1.  
    2. #define USE_OR_MASKS
    3. #include <stdio.h>
    4. #include <stdlib.h>
    5. #include <p18f2553.h>
    6. #include "pwm.h"
    7. #include "adc.h"
    8.  
    9. #pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
    10. #pragma config WDT = OFF //Disable watchdog timer
    11.  
    12. unsigned int ADCResult=0;
    13.  
    14. int main(int argc, char** argv)
    15. {
    16.   char period=0x00;
    17.   //unsigned char outputconfig=0,outputmode=0,config=0;
    18.   unsigned int duty_cycle=0;
    19. //----Configure pwm ----
    20.     period = 0xFF;
    21.     OpenPWM1( period);     //Configure PWM module and initialize PWM period
    22.  
    23. //-----set duty cycle----
    24. //        duty_cycle = 0x0F00;
    25.     SetDCPWM1(0);        //set the duty cycle -this time to 0
    26.  
    27.     while(1)
    28.     {   unsigned char config1=0x00,config2=0x00,config3=0x00,portconfig=0x00,i=0;
    29.  
    30.          CloseADC();
    31.           // Initialize ADC for
    32.           // FOSC/2 as conversion clock
    33.           // Result is Right justified
    34.           // Acquisition time of 2 AD
    35.           // Channel 1 for sampling
    36.           // ADC interrupt on
    37.           // ADC reference voltage from VDD& VSS
    38.  
    39.      config1 = ADC_FOSC_2 | ADC_RIGHT_JUST | ADC_2_TAD ;
    40.     config2 = ADC_CH0 | ADC_INT_ON | ADC_REF_VDD_VSS ;
    41.     portconfig = ADC_15ANA ;
    42.     OpenADC(config1,config2,portconfig);
    43.  
    44.          ADC_INT_ENABLE();
    45.  
    46.         for(i=0;i<16;i++)
    47.           {
    48.               ConvertADC();
    49.          while(BusyADC());
    50.  
    51.               ADCResult += (unsigned int) ReadADC();
    52.           }
    53.  
    54.          ADCResult /= 16;
    55.  
    56.          // Now we apply it to the cycle
    57.  
    58.          //-----set duty cycle----
    59.            duty_cycle = ADCResult;
    60.            SetDCPWM1(duty_cycle);        //set the duty cycle
    61.                                                            // This actually won't work well on a PIC18F2553 because the PWM
    62.                                                            // and the A/D use now different number of bits
    63.                                                          // previously in the 18F2550 both were 10 bits but now A/D is 12 bits
    64.                                                           // So you will notice a updown behavior in the upper levels
    65.           CloseADC();
    66.  
    67.     }
    68.  
    69.     //-----close pwm----
    70.     ClosePWM1();
    71.  
    72.     return (EXIT_SUCCESS);
    73. }
    74.  
    75.  
    So I am setting period and duty cycle with hexadecimal values and the A/D conversion use FOSC/2 as conversion clock.
    However what do these hexadecimal values are in real human readable values, I have no idea.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    Like almost everything else about the part, you'll find the answer in the datasheet. Try to read one in a little more detail before taking the shortcut (for you) of asking somebody. We have to download it and read it because we can't keep this information on the top of our heads, especially if we've never used the part before. Show a little bit of industry.
     
  7. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Well, it seems and I can be totally wrong (that is why I ask) that since I am using the internal oscillator, the default output frequency of the internal oscillator is set at 1MHz. (Datasheet page 31)

    So I suppose this is Fosc??
     
  8. OBW0549

    Well-Known Member

    Mar 2, 2015
    1,319
    888
    Yes.
     
    KansaiRobot likes this.
Loading...