element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum Timing calculations on PIC18f
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 460 subscribers
  • Views 267 views
  • Users 0 members are here
Related

Timing calculations on PIC18f

mr.rohit
mr.rohit over 8 years ago

Hi guys,
Was exploring PIC18F controllers timing specification. Unable to understand a couple of things in time generation sequence for based on the same.

 

 

Breadboard arrangement:

MUC:PIC18f46k22

Fosc = (XTAL) = 16MHz (with 22pf decoupling)

Fcpu = Fosc/4 = 4Mhz,

Tcpu = 1/4000000 = 0.25us = 250ns

 

Based on my observations I have noticed the following (pls. refer to attached images):

Case 1:

while(1){

LATDbits.LATD2 = 0;  //turn off led exec#0

LATDbits.LATD2 = 1;  //turn on led exec#1

LATDbits.LATD2 = 0;  //turn off led exec#2

LATDbits.LATD2 = 1;  //turn on led exec#3

}

 

Observations:

Noted for exec#0 and exec#2 Time period = 500ns

After which the pin stays high for exec#3 Time period 750ns and low for exec#0 time period 240ns.

In my opinion every 8-bit instruction is getting executed every 250ns in this case, the rest of the period where the signal is high the MCU is still awaiting instructions to fullfill 4MIPS.

https://drive.google.com/open?id=0B1ujJMA_1UnySUdKMi1JeVhMUWM

 

Case2: (Using ternary operator)

while(1){

LATDbits.LATD2 = LATDbits.LATD2 ? 0:1;

}

 

Observations:

from case2 ON-OFF time period = 3.3us

https://drive.google.com/open?id=0B1ujJMA_1UnydzhQVzRwMTZONWc

 

Case3:

while(1){

   LATDbits.LATD2 = ~ LATDbits.LATD2;            //toggle bit

}

 

Observations:

from case3 ON-OFF time period = 3.9us

https://drive.google.com/open?id=0B1ujJMA_1UnyaXEtX3BLZDNKLTQ

 

Case4: (Using macros)

while(1)

{

LED_OFF();   
LED_ON();
LED_OFF();
LED_ON();

}

 

Observations:

Time period = 500ns

same as case1.

https://drive.google.com/open?id=0B1ujJMA_1UnySUdKMi1JeVhMUWM

 

Please correct me if i am wrong..

Thank u...image

  • Sign in to reply
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 8 years ago +2
    I'm not sure that I understand what is puzzling you: The problem seems to be that you are looking at code in C and attempting to predict what the processor will do - you need to look at the assembler code…
  • koudelad
    koudelad over 8 years ago +1
    In addition to what Michael wrote, have a look at this topic on Microchip forum.
  • michaelkellett
    michaelkellett over 8 years ago

    I'm not sure that I understand what is puzzling you:

     

    The problem seems to be that you are looking at code in C and attempting to predict what the processor will do - you need to look at the assembler code that actually runs on the processor. In the case of your first example the while loop will generate code that uses a jump instruction of some kind after the 4th assignment instruction.

     

    If you want to know what the processor is doing at this very low level then look at the assembler output of the C compiler or use your debugging tools to look at the code on the processor.

     

    It's very difficult to do precise timing by sequences of code - that's why modern micro controllers have timers which are often much easier to manage. You have lots of timers on this processor.

     

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • koudelad
    koudelad over 8 years ago

    In addition to what Michael wrote, have a look at this topic on Microchip forum.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube