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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 delay generation
  • 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 17 replies
  • Subscribers 474 subscribers
  • Views 1603 views
  • Users 0 members are here
Related

delay generation

mr.rohit
mr.rohit over 8 years ago

Delay generation using timer in pic18f46k22

 

I am using timer interrupt for delay generation in pic18f

when i generate  any delay using timer that time this delay is not proper which i want,it showing some difference in time.

i want knw what is the reason of that difference ?

plz help me...

thank u..

  • Sign in to reply
  • Cancel

Top Replies

  • koudelad
    koudelad over 8 years ago in reply to mr.rohit +4
    Well... A calculator is useful only after you fully understand, what it calculates. There is no information about age or function... First, trust the datasheet of PIC18F46K22 . Microchip tries to have…
  • koudelad
    koudelad over 8 years ago in reply to mr.rohit +4
    I am glad I could help. And welcome to element14 community To be honest, when I started with 16F PICs (13 years ago), I only had some book that didn't provide much explanation. Then I opened the datasheet…
  • koudelad
    koudelad over 8 years ago +3
    Hello, there are too many variables. The more details you add, the more we would be able to help you. Basically, I would focus on the following: 1) oscillator frequency and stability - this is crucial…
  • koudelad
    koudelad over 8 years ago

    Hello,

    there are too many variables. The more details you add, the more we would be able to help you.

    Basically, I would focus on the following:

    1) oscillator frequency and stability - this is crucial - are you using an integrated RC or some kind of external oscillator? (What are the conditions your design works in? e.g. variable temperature..)

    2) is your timer (and prescaler / postscaler) set correctly?

    3) do you work with the timer properly? (for example if you generate periodically an interrupt, but have poorly written ISR, it looses precision; the same if multiple interrupts occur at once or even worse, the same source of interrupt occurs multiple times, before you finish the ISR)

    4) What makes you think that you have a difference in time delay? Do you have any measurement instrument? What delays are you trying to achieve?

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • mr.rohit
    mr.rohit over 8 years ago in reply to koudelad

    i am  using DSO for time period measurement

    i want time delay in microsecond for CTMU unit in pic18f46k22

    i am using internal oscillator with PLL - 64MHz (16MHz  + 4xPLL),

     

    my timer register detail is

     

     

    T0CONbits.T0PS = 1;                 //timer0 prescalar enable    

        T0CONbits.PSA = 1;

        T0CONbits.T0PS0 = 0;

        T0CONbits.T0PS1 = 0;

        T0CONbits.T0PS2 = 0;

        T0CONbits.T08BIT = 1; //8 BIT MODE

        INTCONbits.TMR0IE = 1; //Enable TIMER0 Interrupt

        T0CONbits.TMR0ON = 1; //Now start the timer!

        T0CONbits.T0CS = 0;

        TMR0 = 254; //load count in TMR0 register

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

    Hello,

    just a few thoughts:

    • The internal 16 MHz oscillator is supposed to by factory-calibrated to +/- 1 %. By using 4x PLL you multiply the error up to 4 times. What delay are you trying to achieve and what is the delay you actually measure?
    • I haven't programmed a PIC for a while, but I would suggest to do the configuration to T0CON at once (and as a final step, enable it).
    • Timer0 consists of TMR0L and TMR0H registers. What is the line "TMR0 = 254" supposed to do? BTW it is not recommended to set a value of an enabled counter.
    • The ISR is also important and comes as a factor into the equation. What do you do and how in your ISR?
    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • mr.rohit
    mr.rohit over 8 years ago in reply to koudelad

    hello

     

    i am trying to achieve 10us delay and i am getting time period on DSO is 17us

    Timer0 is 8-bit timer so i set maximum count ie 254

     

     

    check this page

    PIC Timer Calculator

     

     

    thank u..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • koudelad
    koudelad over 8 years ago in reply to mr.rohit

    Well... A calculator is useful only after you fully understand, what it calculates. There is no information about age or function...
    First, trust the datasheet of PIC18F46K22. Microchip tries to have backwards compatibility to earlier released PICs, however, an actual datasheet is the only trustworty document about the device. Chapter 11 is all about Timer0.

     

    Now comes the math homework image

     

    Your internal oscilator deliveres 16 MHz * 4 (for PLL) = 64 MHz
    If you want to use the internal oscilator as a clock source for Timer0, it uses Fosc / 4 = 16 MHz.
    Then, optionally, you can use a prescaler of 1:2 - 1:256 and the timer can be used as 8 / 16 bits.

    The period for 16 MHz is 1 / 16 000 000 = 62.5 ns
    To achieve 10 us delay, you need to delay for 10 * 10^-6 / 62.5 * 10^-9 = 160 cycles. This perfectly fits into an 8 bit timer, without using a prescaler.

     

    If you multiply the period of 62.5 ns by your 254 value, you get 16 us. (I guess the additional 1 us goes to Timer0 setting after enabling and the ISR.)

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • mr.rohit
    mr.rohit over 8 years ago in reply to koudelad

    hello david...

    I am new in Embedded world and this is realy helpfull for me to understand timer interrupt

    thank u so much david..imageimage

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • koudelad
    koudelad over 8 years ago in reply to mr.rohit

    I am glad I could help. And welcome to element14 community image

    To be honest, when I started with 16F PICs (13 years ago), I only had some book that didn't provide much explanation. Then I opened the datasheet and realized that it is the only source of reliable information (and erratas, that are related to specific products).

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • mr.rohit
    mr.rohit over 8 years ago in reply to koudelad

    hmm...

    Really u have lots of experience in Embedded..

    nice to meet u..image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB over 8 years ago

    How precise and how accurate?

     

    Accurate timing comes down to a time base and synchronization.

     

    You can accomplish these tasks depending upon your requirements.

     

    Please share them if you want a good answer.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mr.rohit
    mr.rohit over 8 years ago in reply to DAB

    hello...

     

    I am working with Capacitive sensor using CTMU in pic18f46k22..I am refering AN1375 App note for CTMU..

    this microcontroller having CTMU unit for capacitive sensor.in CTMU registers , i am using 5.5uA internal current source,and 14us delay which is generated by timer interrupt for CTMU.

    calculations....

    c = 30 pf

    I = 5.5uA

    T = 14us

    v = ?

     

    according to mathematical calculation

    v = (I*T)/C

    v = (5.5uA * 14us)/30pf

    v = 2.56v

     

    my question is ,

    Can i use the time delay in millisecond using timer interrupt for CTMU ?

    plz help me, i am not able to understand the accurate calculations..

    thank u..

    • Cancel
    • Vote Up 0 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