i2c problem

Any bugs you encounter with Flowcode should be discussed here.
DirkB
Posts: 58
http://meble-kuchenne.info.pl
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

i2c problem

Post by DirkB »

Hi,

if I2C or PWM are used, the speed goes extremly down.
Have a little program attached. This problem is in FC5
using PWM not existent. Are this componets in FC8 and
FC9 the problem? FC8 have same problem.

thank you

Dirk
Attachments
LFO_Test.fcfx
(19.37 KiB) Downloaded 55 times

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: i2c problem

Post by BenR »

Hi Dirk,

You have your clock speed defined as 32MHz but in the OSCCON register you have the OSCCON configured for 8MHz. So things like delays etc will be 4x longer then they should be. I see your PLL config setting is enabled so this might not be the problem. I would disable the PLL and use the 32MHz INTOSC.

For 32MHz operation you should instead use this C code.
OSCCON = 0xF0;

Could the timer interrupt be slowing things down?

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: i2c problem

Post by medelec35 »

Hello Dirk.
I have tested your project on a 16F1825 and the PWM frequency is correct.
PWM Frequency.png
PWM Frequency.png (34.41 KiB) Viewed 1742 times
I have not got a DAC to test.
If the DAC is the issue, then maybe the timer4 interrupt is causing an issue as it is set to 31KHz, the same frequency as the PWM.
Martin

DirkB
Posts: 58
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

Re: i2c problem

Post by DirkB »

Hello Ben,

I have configured the chip like this, for 32 MHz.
OSCCON = 0x70; with PLL.
The PWM and the DAC should not be used together. They are only there as an example.
If the PWM OR the DAC is used the blinking frequency of the LED will slow down drastically.
The chip will slow down. I have used timer 4 used. The PWM is working correctly, but the whole
chip will be slower, even as hardware, not only in simulation. The problem with the PWM does
not exist in FC5. I also suspect the timers. The problem is with all timers.

thanks

Dirk

DirkB
Posts: 58
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

Re: i2c problem

Post by DirkB »

Hello Ben,

I have configured the chip like this, for 32 MHz.
OSCCON = 0x70; with PLL.
The PWM and the DAC should not be used together. If the PWM or the DAC is used the blinking frequency
of the LED will be drastically slower. I have used timer 4. The PWM works correctly, but the whole chip slows
down, even as hardware, not only in simulation.

thanks

Dirk

DirkB
Posts: 58
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

Re: i2c problem

Post by DirkB »

I forgot. When I import a project from FC5 with FC6 and open it with FC8 or FC9, there is no problem. Therefore I suspect the I2C components.

Dirk

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: i2c problem

Post by medelec35 »

Hi Dirk.
Can you alter the interrupt frequency so that it's much lower as that could be causing the issue you are facing?
Fast interrupts cause the hardware delays to take much longer.
For example, I had a project that ran at 32MHz.
With an interrupt set at 972Hz, the delays went from 5 to 14 seconds.
This is something to be aware of.
The issue is how many calculations and what other things have to be done in the delay
If you have a simple calculation then the delays won't be affected as much.
So the 5 seconds will be very close to 5 seconds with a 31KHz interrupt
If there is a lot going on within the interrupt e.g multiple, calculations especially using mod or floats
Using components etc then the delay time will be drastically affected.
That is because the delay routine is paused from when the interrupt starts to when it has finished.
I Changed the interrupt to 61Hz and the delays went back to 5 seconds.
Martin

DirkB
Posts: 58
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

Re: i2c problem

Post by DirkB »

Hello Martin,

when I import a project from FC5 with FC6 and open it with FC8 or FC9, there is no problem.
Interrupt frequenzy is 31250 Hz in this project. Therefore I suspect the I2C components.

DirkB
Posts: 58
Joined: Thu Dec 10, 2020 3:55 pm
Been thanked: 4 times

Re: i2c problem

Post by DirkB »

Now for test I have removed the PWM and DAC, for this but connected an i2c LCD and a serial i2c eeprom.
There is no timing problem here.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: i2c problem

Post by medelec35 »

You could just add only the PWM and test the speed,
then remove PWM and just add DAC and see which one causes the issue you are facing.
Martin

Post Reply