18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    @ fosc=16mhz settings from mcc for a 10mS timer
    pic18f25k22
    Code:
     // Set TMR0 to the options selected in the User Interface
        // TMR0H 0; 
        TMR0H = 0x00;
        // TMR0L 100; 
        TMR0L = 0x64;
     
        // Load TMR0 value to the 8-bit reload variable
        timer0ReloadVal = 100;
        // Clearing IF flag
        INTCONbits.TMR0IF = 0;
        // T0PS 1:256; T08BIT 8-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned; 
        T0CON = 0xD7;
    18f27k40
    Code:
           // Set TMR0 to the options selected in the User Interface
    
        // T0CS FOSC/4; T0CKPS 1:64; T0ASYNC synchronised; 
        T0CON1 = 0x46;
    
        // TMR0H 155; 
        TMR0H = 0x9B;
    
        // TMR0L 0; 
        TMR0L = 0x00;
    
        // Clearing IF flag
        PIR0bits.TMR0IF = 0;
    
        // T0OUTPS 1:1; T0EN enabled; T016BIT 8-bit; 
        T0CON0 = 0x80;
    Last edited by richard; - 22nd July 2018 at 00:32.
    Warning I'm not a teacher

  2. #2
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    thanks guys

    i am running at 32mhz , so a few changes , its nice have both the prescaller and the postscaller something that timer0 never had , and without it 10ms in 8bit mode functioning in same way as TMR2 would not be possible at 32mhz

    i pointed this out cos i have ported timer0 code from one processor to another , and was not expecting a change in timer0 internal functions when in 8 bit mode

    cheers

    Sheldon

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    oh and when i first setup this original code, back some years back i refereed to this calculator, so dont use this calc for timer 0 for k40


    Name:  timer0 calc.JPG
Views: 1341
Size:  62.5 KB

  4. #4
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    // T0CS FOSC/4; T0CKPS 1:64; T0ASYNC synchronised;
    // TMR0H 155;
    // TMR0L 0;
    // T0OUTPS 1:1; T0EN enabled; T016BIT 8-bit;
    For the K40 in 8-bit mode I don't see how that gets you 10ms @ 16MHz clock

    Doesn't that get you 156 x 64 x 250ns = 2.496ms ?

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    Doesn't that get you 156 x 64 x 250ns = 2.496ms ?
    yes , my bad it needs to be T0CKPS 1:256;

    accidently set fosc to 4mhz when trying to match sheldons settings trying to guess at his fosc and forgot to regenerate the code
    Warning I'm not a teacher

  6. #6
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    it needs to be T0CKPS 1:256
    That'll get you a lot closer... 9.984ms

    If you use the postscaler you can get 10.000ms:

    - set prescaler to 1:32 T0CKPS<3:0> = 0101
    - set postscaler to 1:10 T0OUTPS<3:0> = 1001
    - set period count = 125 (load TMR0H with 125-1=124)
    gets you 32 x 10 x 125 x 250ns = 10.000ms

    For 32MHz, just change the prescaler to 1:64:
    64 x 10 x 125 x 125ns = 10.000ms

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: 18f27k40 - timer0 changes from K22, K80 series 8bit/16bit mode

    i'm impressed on just how versatile these later generation chips are. there is heaps to learn
    Warning I'm not a teacher

Similar Threads

  1. 18f27k40 - adc settings
    By longpole001 in forum PBP3
    Replies: 5
    Last Post: - 12th July 2018, 11:34
  2. PBP for dsPIC 16bit??
    By photoelectric in forum PBP Wish List
    Replies: 33
    Last Post: - 9th July 2014, 08:13
  3. PIC18f2620 Timer0 in 16-bit mode
    By Bruce in forum General
    Replies: 0
    Last Post: - 18th August 2010, 03:08
  4. AD7705 is 15bit or 16bit ADC
    By ravindrajoga in forum Off Topic
    Replies: 1
    Last Post: - 13th July 2007, 14:09
  5. 8bit var holds 16bit data!??
    By mofarngo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th August 2005, 20:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts