EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Timer0 PIC16F917

Timer0 PIC16F917

|

Microcontroller › PIC › Timer0 PIC16F917

  • This topic has 0 replies, 1 voice, and was last updated 13 years, 4 months ago by Dragu Mircea.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • December 30, 2012 at 4:35 pm #2042
    Dragu Mircea
    Participant

    freq. out = freq. clk / (Prescaler*(256 – TMR0)*count) 
    In my program I work with internal clk (T0CS=0) so the freq. clk is 4Mhz/4 = 1Mhz. (internal instruction cycle is 1 microsec). 
    I want to generate a delay of 3 seconds. 
    The RD7 pin must stay 3 seconds ON, then must stay 3 seonds OFF and so on. 
    freq. out = 1 / T = 1 / 3 sec = 0.33Hz and replacing 0.33Hz = 1MHz / (256 * (256 – 0) * count) 
    count = 1MHz / 65536 * 0.33Hz 
    count = 46. 
    In previous programm I made some mistakes. I do not set up the interrupts :  INTCONbits.T0IE = 1;   // Timer 0 Interrupt Enable is set    
                                                                                                                                INTCONbits.GIE = 1;    // Global Interrupt Enable is set 
      

    #include<pic.h> 
    unsigned char counter; 
    void interrupt Timer0_ISR(void) 
    {    
         if ( T0IE && T0IF )                      // are TMR0 interrupts enabled and//is the TMR0 interrupt flag set? 
              {        
                    T0IF = 0;                        // TMR0 interrupt flag must be cleared in software 
                    ++counter;                    // increment the counter variable by 1 
                    if(counter == 46)        
                    PORTDbits.RD7 ^= 1;    // toggle the RD7 pin 
               } 
    } 
    Init(void) 
    { 
          TMR0 = 0;                                      // clear the TMR0 register 
          OPTION_REG = 0B00000111;        // Use the internal instruction clock, choosing to work with a Prescaler (1 : 256) 
          INTCONbits.T0IE = 1;                    // enable TMR0 overflow  
          INTCONbits.GIE = 1;                     // enable Global interrupts 
    } 
    main(void) 
    {    
          TRISD = 0B01111111;    
          PORTDbits.RD7 = 0;    
          Init(); 
          while(1) 
          {         
          } 
    } 
      
    I simulate this program with MPLAB SIM but timer0 dont want to increment. 
    Please help me. 
    All the best. 

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Voltage comparator circuit verification May 10, 2026
  • What is this??? May 10, 2026
  • Why aren’t the power windows in my 2006 Volkswagen Polo 2006 working despite repairing the control unit circuit board? May 10, 2026
  • infiniBand Layer 1 specifications testing question May 8, 2026
  • block RF May 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise