Well that does seem really Slloooooowwwww. but maybe a little more info please. code and configs would go a long way here.
Well that does seem really Slloooooowwwww. but maybe a little more info please. code and configs would go a long way here.
-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!
Bert,
Thanks for the quick reply
OK more info - one other question how do I get my code into the scrolling window?
I have a line in there :- i2cread DPin,CPin,$90,1,[c], if I take it out the code doesnt work.
Code
DEFINE osc 20
DEFINE LOADER_USED 1
INCLUDE "MODEDEFS.BAS"
DEFINE I2C_SLOUT
ANSEL =%00000001 ' Enable ADC channel-AN0
ANSELH =%0000
'ADCON0.7 = 1
SSPCON =%00101011
TRISB.4 =0
TRISB.6 =0
TRISA =%00001111
TRISC =%00000000
CPin VAR PORTB.6
DPin VAR PORTB.4
a var word
c var byte
MAINLOOP
for a = 1 to 255
I2Cwrite DPin,CPin,$90,a
i2cread DPin,CPin,$90,1,[c]
next
goto Mainloop
Add code tags - select the text and then click on # above the edit window.
Code:DEFINE osc 20 DEFINE LOADER_USED 1 INCLUDE "MODEDEFS.BAS" DEFINE I2C_SLOUT ANSEL =%00000001 ' Enable ADC channel-AN0 ANSELH =%0000 'ADCON0.7 = 1 SSPCON =%00101011 TRISB.4 =0 TRISB.6 =0 TRISA =%00001111 TRISC =%00000000 CPin VAR PORTB.6 DPin VAR PORTB.4 a var word c var byte MAINLOOP for a = 1 to 255 I2Cwrite DPin,CPin,$90,a i2cread DPin,CPin,$90,1,[c] next goto Mainloop
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.
Bookmarks