Page 1 of 1

Strange timing issue

Posted: Tue Mar 06, 2012 9:21 am
by djm2
Hi there

I have a PIC18F4685 with a 10MHz crystal and HS-PLL enabled and an I2C LCD.

My program goes like this -

- Set variables to be displayed ie set LCD text to variable and set length of lcd text to variable
- Send command to move the cursor on the LCD to the desired place
- Sent the LCD text out to the LCD.

The code works great it does exactly what it is meant to do. I have setup two macros one to move the cursor and the other to send the text out to the LCD. Each of these macros starts with a START command and finishes with a STOP command. The problem is that even though the macros follow each other immediately with no other tasks being perform no intterupts or other code etc I get a constant 10ms delay between the STOP and the following START command. To see if the problem lay with coming out of and entering macros I have played about and put some I2C activity straight after another lot of I2C data I get the 10ms delay ie START......STOP START.....STOP. This proved that the problem lies between the STOP and START command rather than in entering and leaving macros. I know this does not sound like a lot but it really adds up when you start looping around printing various things out to the LCD. To put this into perspective the average I2C activity length is less than 1ms.

Does anyone know anything about this mystery delay?

David

Re: Strange timing issue

Posted: Tue Mar 06, 2012 9:46 am
by JonnyW
Hello. Could you post your sample program (FCF) and we can have a look at it?

Cheers,

Jonny

Re: Strange timing issue

Posted: Tue Mar 06, 2012 10:03 am
by djm2
Hi there

I have attached the code I was using to test with. I have also included a screen shot of the program I use to look at the logic levels. FYI the slightly wider set of data on the SDA line is the "Please select mode-" text.

David

Re: Strange timing issue

Posted: Tue Mar 06, 2012 10:31 am
by Benj
Hello David,

Yes I know where the delay comes in to it. Basically we added a 10ms delay to the end of the I2C stop routine as on some devices using a smaller delay or no delay causes the I2C hardware to lockup.

You can edit the length of the delay or even remove it altogether by using the code customisation feature.

Select the I2C component on the panel, right click and select custom code. Select the I2C Stop function and edit it. At the bottom of the function is the delay. You can try reducing it or removing it and see if this helps your program.

Let us know how you get on.

Re: Strange timing issue

Posted: Tue Mar 06, 2012 10:43 am
by djm2
Hi

All it says in the custom code for the stop function is -

%a_I2C_Master_Stop();

I got here from the "Customize Component Code" window and then clicking on MI2C_Stop and then clicking on "edit code". I guess I am going to the wrong place.

David

Re: Strange timing issue

Posted: Tue Mar 06, 2012 12:04 pm
by Benj
Hello David,

Ok sorry about that looks like the delay has moved from the component C code to the abstraction layer in version 5.

You will need to open the following file into a text editor.

C:\Program Files\Flowcode\v5\CAL\PIC\PIC_CAL_I2C.c

Scroll down to this function...

CALFUNCTION(void, FC_CAL_I2C_Master_Stop_, (void))

And the line you are looking for is right at the end.

delay_ms(10); //Wait before reusing the I2C BUS

Edit the file and save it, you may want to create a backup first. Then re-compile in Flowcode and the new code should be loaded automatically.

Hope this helps.

Re: Strange timing issue

Posted: Tue Mar 06, 2012 12:34 pm
by djm2
Hi there

Yeah got it and it works better now.

Thanks

David