Code speed and execution time


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    Unfortunately your chosen PIC does not have hardware implementation of i2c Master. If you want to use h/w i2c, you'll have to change PICs.

    For start/stop, etc, you have to read the datasheet of the slave. They usually show graphical timing charts that show when the individual pins must be driven high or low. For a typical eeprom, like the 24LC08b for instance, a START is this...
    eeprom_start:
    high data
    high clock
    low data

    Now those are states, not commands. While you can use the command, it is not recommended for several reasons. First, i2c should have pullups, and you are supposed to turn the pin into an input to let it get pulled high. Second, you have to wait for the pin to get pulled high, and third, my preference is to avoid PBP's High and Low commands because they turn the pin into an output then set it high...and that takes too many instructions. I like to manually set the Tris register myself, and manually set the port pins--but that is personal preference.

    ...and eeprom_stop is this...
    low data
    high clock
    high data

    Ack is the slave acknowledging the data; usually it is pulling the data line low...
    Eeprom_Ack:
    repeat
    until SDA_Pin = 0

    After you get that worked out, you look at the byte write (for instance) timing chart. My eeprom d/s shows this timing...

    Eeprom_Start
    i2cout Control
    Ack
    i2cout Address
    ack

    LoopStart:
    i2cout YourData
    ack
    If NotDoneSendingData goto LoopStart
    Eeprom_Stop

    If sticking with the s/w commands, you'd probably want to make your own i2c command, too. The ones built in to PBP are painfully slow because they are designed to be idiot-proof. You can see the timing charts of the d/s to learn when to pull the clock and data pins low.

    It can be done and is easy for the experienced...but this is not a trivial undertaking for a newbie. TIming charts in datasheets may be initially intimidating, but once you get it it's simple.

  2. #2
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    tenaja

    Thanks for the great explanation

    As far as the PIC goes, I have the following

    18F14K50
    16C745
    12F675dsPIC 33FJ120P
    16F84
    16F676
    24FJ64GA002
    16F81930F2010
    16HV785
    If any of these pop out as ones you know would be suitable, please let me know, otherwise I will go searching.

    It is not critical that I use the 16F690, its just that it is installed on the LPC demo board.

    My project is (what I thought in the start would be simple - now I know otherwise) to save a sinewave in an EEprom and get a value and send it out to the DAC. Then a switch to change the speed of the loop to give 50 or 60 hertz.

    Thanks
    aajgss

  3. #3
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    I don't have your list of PICs memorized, so you'll have to read the datasheets. Just search for "master" in the i2c section and make sure it is not implemented in firmware.

    GIven your 50/60hz output, I'm guessing a dc/ac converter? Most dc/ac converters use a "modified sine wave" that only has two or three steps in each direction. You should be fine with a lookup table...you can probably squeeze in a decent curve in the same space the s/w i2c commands consume, and save the hassle of the eeprom.

  4. #4
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    OK, Checked all my PIC's and find that the 18F14K50 is listed in the data sheet as having a Master Sync Serial Port.

    I have tried the I2Cread and I2Cwrite with this and never got it to work. Could this be because it is hardware and not software?

    I shall continue and report back at the next hurdle!!

    Thanks
    aajgss

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts