Menu

Timer0 on 16F18346

Help
2021-03-10
2021-03-11
  • David Stephenson

    I am trying to get two units to synchronize this requires TIMER0 to be re-set to zero on one of the units when the other has a timer0 overflow.
    This does not seem to be happening I set TMR0H=b'00000000' then TMR0L=b'00000000' and it doesn't work.
    the ASM shows CLRF TMR0H and CLRF TMR0L.
    Now according to the datasheet there is something strange about these registers the gist being that you are not actually writing to the registers but to a buffer (which is supposed to update the registers after a TMR0L write).
    Any help would be appreciated.

     
  • Anobium

    Anobium - 2021-03-11

    Works here. Maybe id works because I force the SetTimer to select the overloaded WORD method.

    Evan

    #chip 16F18346
    #option Explicit
    
    #Define TMR0_16BIT
    SetTimer 0, [word]0x1234
    
    SetTimer 0,[word]0
    
    
    ''' GCB Optimisation file for library
    #Define USE_Timer1 Na
    #Define USE_Timer2 Na
    #Define USE_Timer3 Na
    #Define USE_Timer4 Na
    #Define USE_Timer5 Na
    #Define USE_Timer6 Na
    
     
  • David Stephenson

    Thanks for the help. I started to think it was a prescaler problem, but apparently this should be reset on a TMR0L write. I'm sure I must be doing something daft as I've got this to work on other projects (writing to the registers that is not resetting them). I've never tried to synchronize two timers (and over a RF link).
    I will think about it some more and maybe try TIMER1 instead, but this does have a poorer selection of scaling (8:1 is the best it can manage).

     
  • Anobium

    Anobium - 2021-03-11

    Using the inbuilt functions will resolve. You are loading the two registers in the wrong order.

     
  • David Stephenson

    Are you sure I'm doing it in the wrong order? I write to TMR0H (to the buffer) then a write to TMR0L will load TMR0L and transfer the value from the TMR0H buffer to the actual register.
    Well that's how I interpreted the datasheet.
    I have now put the
    TMR0H=b'00000100'
    TMR0L=b'00000000'
    in a different place in the program and it now works (note: I have had to make TMR0H=4 as it is further down in the program and would otherwise miss the transmission on the next wake-up).
    All I can think of is that the SPI was (probably) still active when the first attempt at zeroing was made, but would this make a difference?
    I am using a RFM69 for the RF link it is sending weather data every 1 minute and I wanted to get receiver and transmitter synchronized to minimize battery use - the outside unit uses 0.9 uA when in sleep. I can post the relevant register values to use for this device if anybody is interested.

     
    • Anobium

      Anobium - 2021-03-11

      Dunno.

      As updating the timer0 registers in order is critical. As you are writing directly to the registers and not using the libraries I would be totally guessing.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.