Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Patch for 8051 timer

2 posters

Go down  Message [Page 1 of 1]

1Patch for 8051 timer Empty Patch for 8051 timer Tue Oct 03, 2023 2:20 pm

royqh1979



Two issues when I'm tring to use Timer 1 mode 2 ( 8-bit auto reload mode, it's used by uart to set the baud rate)

- TL1's value is not updated UNLESS mcu monitor is displayed with TCON monitored.

It seems that some operation in i51core directly access mem , instead of calling GET_RAM, so the watcher on the TL1 won't be triggered and it's value not get updated. I changed all direct access to m_dataMem to GET_RAM and SET_RAM.

- TL1's value is counted starting from 0, instead from value in TH1.

When TLx get updated, add the value in THx to it.



Attachments
Patch for 8051 timer Attachment8051timer.zip
You don't have permission to download attachments.
(2 Kb) Downloaded 1 times

2Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 2:38 pm

arcachofo

arcachofo

I don't remember much about 8051 Timers, but for what I see in the code, mode 2 is supposed to be 8 bits??

3Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 2:43 pm

royqh1979



arcachofo wrote:I don't remember much about 8051 Timers, but for what I see in the code, mode 2 is supposed to be 8 bits??
yes, it's the 8 bits auto reload mode.

Patch for 8051 timer Snap134

4Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 2:59 pm

arcachofo

arcachofo

Ok, I see.
But I think that is already done:
When you write TH1 McuTimer::countWriteH() is called.
This calls: 51Timer::updtCount(), and here:
case 2: // 8 bits
m_countStart = COUNT_H; // Load this value after overflow

5Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:06 pm

arcachofo

arcachofo

I think this problem is probably solved with GET_RAM()

Patch for GET_RAM() applied at Rev 1959.

6Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:19 pm

royqh1979



arcachofo wrote:Ok, I see.
But I think that is already done:
When you write TH1 McuTimer::countWriteH() is called.
This calls: 51Timer::updtCount(), and here:
   case 2: // 8 bits
       m_countStart = COUNT_H; // Load this value after overflow

Nop. in  I51Timer::updtCount(), countVal and  COUNT_L is calculated as the following:
Code:

        uint64_t timTime = m_ovfCycle-Simulator::self()->circTime(); // Next overflow time - current time
        uint16_t countVal = timTime/m_mcu->psInst()/m_prescaler;
        if( m_mode == 0 )  // 13 bits
        ....
        else if( m_mode == 2 ) // 8 bits
        {
            COUNT_L = ( countVal ) & 0xFF;
            //if( m_countH ) m_countH[0] = (countVal>>8) & 0xFF;
        }
So countVal (COUNT_L) is just the difference between overflow time and current time.

This can be verified by watch TL1's value change in the mcu monitor.

7Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:30 pm

royqh1979



royqh1979 wrote:So countVal (COUNT_L) is just the difference between overflow time and current time.

This can be verified by watch TL1's value change in the mcu monitor.

I rechecked McuTimer::updtCount() and found that I've also made a mistake here:

COUNT_L should be (m_ovfMatch-countVal) & 0xFF

And I'm afraid the calculation in I51Timer::updtCount() for mode 0 is wrong, either.

8Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:31 pm

arcachofo

arcachofo

So countVal (COUNT_L) is just the difference between overflow time and current time, it always start from 0.
But overflow time is not calculated from 0, it is calculated from m_countStart:

Code:
void McuTimer::runEvent()            // Overflow
{
...
    m_countVal = m_countStart;            // Reset count value
...
    sheduleEvents();
}
void McuTimer::sheduleEvents()
{
...
        uint64_t cycles = (ovfPeriod-m_countVal)*m_scale; // cycles in ps
...
}

This can be verified by watch TL1's value change in the mcu monitor.
I will have a look, but this must be done after GET_RAM patch.

9Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:33 pm

royqh1979



arcachofo wrote:
But overflow time is not calculated from 0, it is calculated from m_countStart:

I compared  McuTimer::updtCount() with I51Timer::updtCount() and found that I've also made a mistake:

COUNT_L should be (m_ovfMatch-countVal) & 0xFF

And I'm afraid the calculation in I51Timer::updtCount() for mode 0 is wrong, either.

10Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:35 pm

arcachofo

arcachofo

I rechecked McuTimer::updtCount() and found that I've also made a mistake here:

COUNT_L should be (m_ovfMatch-countVal) & 0xFF

And I'm afraid the calculation in I51Timer::updtCount() for mode 0 is wrong, either.
Yes, it could be some issue here.
If I remember well at some point I changed McuTimer::updtCount() but maybe not updated I51Timer::updtCount()

11Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 3:39 pm

royqh1979



arcachofo wrote:
Yes, it could be some issue here.
If I remember well at some point I changed McuTimer::updtCount() but maybe not updated I51Timer::updtCount()

Yeah. And I think we could just update m_countVal here as well.

12Patch for 8051 timer Empty Re: Patch for 8051 timer Tue Oct 03, 2023 4:06 pm

arcachofo

arcachofo

Yeah. And I think we could just update m_countVal here as well.
At Rev 1960 counter calculation is splitted in it's own function and called from McuTimer::updtCount() and I51Timer::updtCount().

13Patch for 8051 timer Empty Re: Patch for 8051 timer Wed Oct 04, 2023 2:09 am

royqh1979



arcachofo wrote:
At Rev 1960 counter calculation is splitted in it's own function and called from McuTimer::updtCount() and I51Timer::updtCount().


Great!

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum