lcgamboa / picsimlab

PICsimLab - Programmable IC Simulator Laboratory
GNU General Public License v2.0
442 stars 85 forks source link

Gpboard simulation speed issue #110

Closed Kabak85 closed 3 months ago

Kabak85 commented 3 months ago

Hello,

Version : 0.9.2 240302 Windows64_WC DIST on windows 7.

Simulation speed is not the same between gpboard and the oscilloscope/Vterm.

In this simulation, the 16F84 periodically send the letter "X" at the rate of 1600 BPS but scope/Vterm see it 6 times faster (9600 BPS). The same HEX file on gpsim with a 1600bps USART terminal seem works correctly.

Test serial.zip

lcgamboa commented 3 months ago

Hi @Kabak85,

Yes, I have already detected this problem but I still don't know how to solve it. The simulation step code is defined in this function, but it apparently is not working correctly. This problem affects the serial and other peripherals. Creating a blink using a timer and another using a delay, the one using the timer runs twice as slow as it should and the one using the delay six times slower, so the problem is not simply adjusting the frequency. If I manage to solve the problem I will let you know.

Kabak85 commented 3 months ago

Hi @lcgamboa

I know that on PIC, the oscillator frequency (Fosc) can :

I'm not very good with C and pointer and without comments ... but if i understand, your code using a state named "mExecute2ndHalf". But if it's the second cycles of some instruction, you miss a lot of event.

I see ClockPhase but don't understand exactly what is it. If this value represent clock oscillator edge, you will have have a more reliable base. I saw also cycles related counter in gpsim code used for simulation time.

lcgamboa commented 3 months ago

Hi @Kabak85 ,

this issue is fixed in the last unstable release. Clearing the halt breakpoint every cycle makes the peripherals work at the correct speed.

Kabak85 commented 3 months ago

Hi @lcgamboa

I confirm you solve the issue.

Thanks.