I2C library works great! Issue with clock

Discuss the Firewing language

I2C library works great! Issue with clock

Postby zoof » Wed Mar 27, 2013 6:08 pm

Using DS1307 as a framework for I2C, I have managed to stream data to the console from a 3-axis gryo, st micro L3G20.
Right now it is in program form and I will work to do the minor changes to make it a module after I finalize other features.

In attempting to get a feel for the speed of pic24, I decided to use the clock = 80 and = 64 (using compiler version 0.7.1.2C).
but the baud rate didn't appear to be tracking the fosc/fcyc speed change.

I manually changed U1MODE to &H8088 and U1BRG to 35 to obtain 115200 baud for 32 Mhz before attempting
further investigation, either way, I could not get 115200 to work for 64 or 80Mhz (or 38400).
I changed these two registers in Sub Main() to override the settings in console.bas .

I also wanted to verify that I2C delays don't get broken with the increased clock speeds.

Any thoughts?

ZOOF!!
User avatar
zoof
 
Posts: 5
Joined: Thu Nov 08, 2012 3:02 pm

Re: I2C library works great! Issue with clock

Postby David John Barker » Thu Mar 28, 2013 9:09 am

First of all, if using a Firewing board the baudrate is fixed at 384000. We may look at changing that in the future, but for the time being it is fixed (unless using UART2).

> ...decided to use the clock = 80 and = 64 (using compiler version 0.7.1.2C).
> but the baud rate didn't appear to be tracking the fosc/fcyc speed change.

I'm not seeing that here. This is my test program:

Code: Select all
clock = 80
Sub Main() 
   dim index as ushort = 1
   while true
      Console.Write(cstr(index),13,10)
      index += 1
   end while
End Sub

programmed into this Firewing board:

http://www.firewing.info/pmwiki.php?n=F ... .MainBoard

and this is the output using the serial communicator software:

Code: Select all
1
2
3
4
...

and so on. If you are still seeing a fail, try using an external xtal. Although the people I have spoken to can happily run serial comms @ 40 MIPS using an internal OSC, an external xtal will be much more accurate for this type of protocol.

> I also wanted to verify that I2C delays don't get broken with the increased clock speeds.

I used this program:

http://www.firewing.info/pmwiki.php?n=F ... er.LCDPlus

with this board:

http://www.firewing.info/pmwiki.php?n=F ... .LCDShield

with a change to the top of the program, like this:
Code: Select all
clock = 80

' file imports...
imports LCDDogm                      ' import DOGM LCD library
imports DS1307                       ' import RTC module
Imports OW                           ' one wire, used for search

The board uses a DS1307 I2C RTC, which works fine at this speed. In addition, the One Wire (OW) temperature sensor and SD card all worked fine.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: I2C library works great! Issue with clock

Postby zoof » Thu Mar 28, 2013 1:49 pm

Hi David,

I investigated further and wanted to share results to see what the issue may be.

I have the serial communicator plug-in set at the proper 38400 and works fine under usual conditions.
I did 3 trials with clock = 32, 64 and 80.

Immediately in main() I capture the firewing assigned value of U1BRG into a UShort variable as well
as OSCCON, CLKDIV and PLLFBD.

For all 3 cases the following value for the system clock is present, meaning the actual cpu
clock was running at 32 Mhz, CLKDIV and/or PLLFBD would have shown the clock change:

OSCCON = &H1120
CLKDIV = &H3040
PLLFBD = 33

The firewing assignment for U1BRG was as follows (of which the values are correct per assumed CLK):

32Mhz : 25 decimal
64Mhz : 51 decimal
80Mhz : 64 decimal

What I see happening is that the compiler is assigning the correct prescaler for the UART with the
assigned/requested clock speed, but the actual Clock doesn't actually change from 32Mhz, so the
baud rate ends up not being 38400 but slower due to the increased BRG divisor values.

I was able to console.write the 64MHZ and 80Mhz values by manually assigning U1BRG to 25 to
match the actual running frequency.
User avatar
zoof
 
Posts: 5
Joined: Thu Nov 08, 2012 3:02 pm

Re: I2C library works great! Issue with clock

Postby David John Barker » Thu Mar 28, 2013 1:58 pm

If you are not using the Firewing board, it is likely that your configuration fuse settings are incorrect. The Firewing loader sets the fuses settings in such a way that allows the OSC settings to be changed in code - see the device file on how the values are changed.

In summary, compiler is working correctly - likely cause of problem is configuration fuse settings.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: I2C library works great! Issue with clock

Postby zoof » Thu Apr 04, 2013 1:49 am

Thanks David,

I am very much enjoying learning the subtle intricacies of the language and features.
The compiler is working very well and does some amazing things.

I am also simultaneously learning the PIC24 as well, so little by little I am making good progress.

I took some time to learn about how the PIC24 clocks work and all of the registers involved,
it took me some days to get that all sorted out!

In my non-standard home-made firewing setup, I now have the internal rc oscillator running at 80 Mhz
and I am using UART1 at 115200 baud. The I2C library is working flawlessly and I've switched
to using the UART library instead of Console for future capability.

Everything is rock steady with the IDE, Compiler and Serial Monitor.

In the next days, I plan to split my current program into two modules that I consider complete,
the RC Clock frequency switcher and the L3G20 gyro driver.

Next Steps will be I2C module to acess an LSM303 accelerometer/magnetometer module
and a module driver for an LPS331 barometer.

When these modules are complete I plan to combine them for use as an IMU.

Then I hope to fold in your GPS and SD card code into the IMU.

All this is just the first half of my project, hopefully I can make it to phase II !!

Thanks again for such a wonderful development environment.

ZOOF!!
User avatar
zoof
 
Posts: 5
Joined: Thu Nov 08, 2012 3:02 pm

Re: I2C library works great! Issue with clock

Postby David John Barker » Thu Apr 04, 2013 8:11 am

Thanks for your feedback - please keep us informed of your progress. If you have any config settings or code to share, please do post. Or you could post an article here:

http://www.firewing.info/pmwiki.php?n=F ... rewingUser
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest

x