The easy to answer question is to put your code in the cool code box, you have to do this:
[ code ]
put code here
[ / code ]
but with no spaces
Still thinking on the real question
The easy to answer question is to put your code in the cool code box, you have to do this:
[ code ]
put code here
[ / code ]
but with no spaces
Still thinking on the real question
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
I am not familiar with I2C, but I do notice that in your initial description you say the crystal is 8M, but in the code it is defined 20M...
The rest I do not know, but some thoughts...
Commenting the 2 I2C lines and recompile would give an indication of how much code is actually there (in I2C part)--and how that interface affects speed. The difference (between with no I2C and with I2C) should match pretty closely with datasheet transaction time for DAC chip?
Using the software implementations of i2c read/write are DREADFULLY SLOW. Yes, I am not surprised you get such a slow loop.
There are several ways to dramatically speed it up.
1. use the hardware i2c--this will speed it up by about 30-40x at least.
2. put the addressing with STARTs, etc, outside the loop, and just clock the data sequentially. This will get you almost 4x improvement.
3. Use a repeat until or do while instead of a for-loop. The For-loop is a lot slower than the other loops when timing is important...but it won't help nearly as much as 1 or 2.
4. Send 256 bytes instead of 255...that way it can init at 0 and loop until 0 again, and that's often a one-instruction savings, depending on the pic.
Thanks for the replies, and how to put the code in.
Amoque,
Thanks, a slip of the finger, I have now changed that with no change in speed.
Tenaja
I dont know the differerence between I2C hardware and I2C read write, can you enlighten me?
Addressing with STARTS etc outside the loop. A brief example would be great.
As you can no doubt tell this is all new to me.
There was a request from cncmachineguy for 'configs'.
I have a few books on programming PICs and they tell you 'to set it to this' or 'set it to that', but no real explanation of why you do it. Does anyoneone know of a book that has all the real basic info that the other books expect you to already know?
Any comment on the 9000+ lines of code assembled. does this seem resonable?
Thanks
aajgss
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.
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
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.
Bookmarks