Tosc and Fosc

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
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....
 

OBW0549

Joined Mar 2, 2015
3,147
I have programmed succesfuly a PWM output for my PIC but have no idea what Tosc and Fosc is.
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).

I have no idea... :( I dont see anywhere in my code where I am setting it.
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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?
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Can you post your code (between code tags)?

What micro are you using? Here is a reference page for the basics.
http://www.microchip.com/forums/m/tm.aspx?m=46977&p=1
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:
 #pragma config FOSC=INTOSCIO_EC
part, but ok, I am using the internal oscillator, but to what frequency??

Code:
#define USE_OR_MASKS
#include <stdio.h>
#include <stdlib.h>
#include <p18f2553.h>
#include "pwm.h"
#include "adc.h"

#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
#pragma config WDT = OFF //Disable watchdog timer

unsigned int ADCResult=0;

int main(int argc, char** argv)
{
  char period=0x00;
  //unsigned char outputconfig=0,outputmode=0,config=0;
  unsigned int duty_cycle=0;
//----Configure pwm ----
    period = 0xFF;
    OpenPWM1( period);     //Configure PWM module and initialize PWM period

//-----set duty cycle----
//        duty_cycle = 0x0F00;
    SetDCPWM1(0);        //set the duty cycle -this time to 0

    while(1)
    {   unsigned char config1=0x00,config2=0x00,config3=0x00,portconfig=0x00,i=0;

         CloseADC();
          // Initialize ADC for
          // FOSC/2 as conversion clock
          // Result is Right justified
          // Acquisition time of 2 AD
          // Channel 1 for sampling
          // ADC interrupt on
          // ADC reference voltage from VDD& VSS

     config1 = ADC_FOSC_2 | ADC_RIGHT_JUST | ADC_2_TAD ;
    config2 = ADC_CH0 | ADC_INT_ON | ADC_REF_VDD_VSS ;
    portconfig = ADC_15ANA ;
    OpenADC(config1,config2,portconfig);

         ADC_INT_ENABLE();

        for(i=0;i<16;i++)
          {
              ConvertADC();
         while(BusyADC());

              ADCResult += (unsigned int) ReadADC();
          }

         ADCResult /= 16;

         // Now we apply it to the cycle

         //-----set duty cycle----
           duty_cycle = ADCResult;
           SetDCPWM1(duty_cycle);        //set the duty cycle
                                                           // This actually won't work well on a PIC18F2553 because the PWM
                                                           // and the A/D use now different number of bits
                                                         // previously in the 18F2550 both were 10 bits but now A/D is 12 bits
                                                          // So you will notice a updown behavior in the upper levels
          CloseADC();

    }

    //-----close pwm----
    ClosePWM1();

    return (EXIT_SUCCESS);
}
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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.
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
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??
 
Top