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
i2c problem
-
- Posts: 58
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 10, 2020 3:55 pm
- Been thanked: 4 times
-
- Matrix Staff
- Posts: 1739
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 440 times
- Been thanked: 603 times
Re: i2c problem
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Matrix Staff
- Posts: 1451
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 512 times
- Been thanked: 472 times
Re: i2c problem
Hello Dirk.
I have tested your project on a 16F1825 and the PWM frequency is correct. 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.
I have tested your project on a 16F1825 and the PWM frequency is correct. 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
Re: i2c problem
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
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
Re: i2c problem
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
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
Re: i2c problem
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
Dirk
-
- Matrix Staff
- Posts: 1451
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 512 times
- Been thanked: 472 times
Re: i2c problem
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.
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
Re: i2c problem
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.
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.
Re: i2c problem
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.
There is no timing problem here.