Try this.· Cleaned up the code - its force to channel 7 at present for testing.· You had a few errors that I found on close inspection and reading the datasheet.
I've set it up (so i can compile it) to use a serial debug object on the programming pins at 115_200 baud.
See how you get on - if it works it'll save the postage!
Spent yesterday chainsawing trees that fell in my garden this winter. I'll try to give it a shot this morning, but I have another chainsaw day ahead. Thanks a TON for taking the time, and I'll let you know.
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
in my code, but I still get a 0. I tried using my equivilent code snip in your code, still reads a 0. So, your init/address/command code won't load the variable my way. My init/address/command code won't load the variable your way. So at a guess, there are issues in both the init/address/command delivery and the receiving code.
Didn't have time to look at it on the scope. My buddy just arrived with his chainsaw, so it's time to get bucking firewood for next winter.
Thanks so much for the help!!! I'll get back to it this evening.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Still no joy. I have yet another long day ahead, I was too beat to play last night. I wonder why it doesn't work at all. I'll take a look this evening, I shouldn't (hopefully) be so beat.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Muhahaha! Got it working!
It was indeed in the software. I obviously needed to take a few days off it. I just started again this morning from scratch and now it works. The readins are very stable, even on a breadboard. I am using Beau's i2c level shifter circuit (transistor/diode). Here is the code that did it.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' PropTerm
#0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY
' ADC
adcCLK = 4 ' adcData = 7
adcAddr = %0110 ' Address pins both pulled high
adcAddrMask = %1001
adcCmdMask = %0111
VAR
long adcResult
long adcACK
byte adcChan
OBJ
term : "PC_Interface"
adc : "Basic_I2C_Driver"
PUB init
term.start(31,30) ' Start Propterm object
term.out(0)
term.str(string("ADS7828 test...")) 'Splash screen
wait_ms(1000)
term.out(0) ' Clear screen
adcChan := 7 ' Select adc channel to be read (0-7)
adc.initialize(adcClK) ' Init adc
repeat ' Read channel and display results
read_adc(adcChan)
term.str(string("ADC result: "))
term.dec(adcResult)
wait_ms(1000)
term.out(0)
pub read_adc(channel) | adcByte
' Take channel and translate to the ADS7828 address code
channel := lookupz(channel:%1000,%1001,%1010,%1011,%1100,%1101,%1110,%1111) << 4 | adcCmdMask
adcByte :=adcAddrMask << 4 | adcAddr
adc.initialize(adcClK)
adc.start(adcClK)
adc.write(adcClK,adcByte) ' Send address and write bit
adcByte := adcCmdMask << 4 | channel
adc.write(adcClK,adcByte) ' Send channel and adc config
adc.start(adcClK)
adcByte := adcAddrMask <<4 | adcAddr | 1
adc.write(adcClK,adcByte) ' Send address and read bit
adcresult.byte[noparse][[/noparse]1] := adc.read(adcClK,adcAck) ' Get result
adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adcAck)
adc.stop(adcClK)
return
James, thanks so much for all your help. I would have thrown my hands up and given up in disgust. Would you still like an ADC? I would be very happy to mail you one for all your efforts. I got 'em as samples, so dont be shy. [noparse]:)[/noparse]
Thanks to evryone else as well. I had given up on this device.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Hmm, so many mistakes it will take me over the 10 word limit. [noparse]:)[/noparse]
Read bit not in the right place and single/differential mode not being set right. The channel bits were not being masked and shifted correctly. There may have been other errors as well, I went through so many changes I lost track. Not all of the errors were present at once, but looking through all my differnt version I found all these errors at one time or another. I was also putting in an extra "stop" command that wasn't needed, but doesn't seem to matter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Hehe, add two more errors. [noparse]:)[/noparse]
Had an error in the channel lookup code, as well as an extra and erronous bit shift. It really works now, on all channels as it should. [noparse]:)[/noparse] Just thought I'd update the code here in case some poor soul was foolish enough to try my code. [noparse]:)[/noparse]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' PropTerm
#0, WHITE,CYAN,RED,PINK,BLUE,GREEN,YELLOW,GRAY
' ADC
adcCLK = 4 ' adcData = 7
adcAddr = %0110 ' Address pins both pulled high
adcAddrMask = %1001
adcCmdMask = %0100
VAR
long adcResult
long adcACK
byte adcChan, byte1,byte2,byte3
OBJ
term : "PC_Interface"
adc : "Basic_I2C_Driver"
PUB init
term.start(31,30) ' Start Propterm object
term.out(0)
term.str(string("ADS7828 test...")) 'Splash screen
wait_ms(1000)
term.out(0) ' Clear screen
adcChan := 6 ' Select adc channel to be read (0-7)
'adc.initialize(adcClK) ' Init adc
repeat ' Read channel and display results
read_adc(adcChan)
term.str(string("ADC result: "))
term.dec(adcResult)
set_pos(0,1)
term.bin(byte2,8)
wait_ms(1000)
term.out(0)
pub read_adc(channel) | adcByte
' Take channel and translate to the ADS7828 address code
channel := lookupz(channel:%1000,%1100,%1001,%1101,%1010,%1110,%1011,%1111) << 4 | adcCmdMask
adcByte :=adcAddrMask << 4 | adcAddr
adc.initialize(adcClK)
adc.start(adcClK)
adc.write(adcClK,adcByte) ' Send address and write bit
adcByte := channel << 4 | adcCmdMask
adc.write(adcClK,channel) ' Send channel and adc config
adc.start(adcClK)
adcByte := adcAddrMask <<4 | adcAddr | 1
adc.write(adcClK,adcByte) ' Send address and read bit
adcresult.byte[noparse][[/noparse]1] := adc.read(adcClK,adcAck) ' Get result
adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adcAck)
adc.stop(adcClK)
return
PUB wait_ms(ms) ' Pause routine
waitcnt(cnt+(clkfreq / 1_000) * ms)
RETURN
PUB wait_us(us)
waitcnt(cnt+(clkfreq / 1_000_000) * us)
RETURN
PRI set_pos(px, py)
term.out(10)
term.out(px)
term.out(11)
term.out(py)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
I'll mail it out this week. And Luke, yeah it is nice when it works out. [noparse]:)[/noparse] I'm quite pleased the the performance of this device now, it is reading my barometric pressure sensor very nicely.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Holy cow! I just sent it a few days ago, it made a quck journey across the pond! You are very welcome, and I thank you for your help in mastering the chip. Let us know how you like it when you try it. Mine is integrated into my project and using the dedicated i2c pins of the protoboard, and working very nicely.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
I had a play at the weekend with the i2c ADC you sent me.· I thought - Ah this will only take 30mins to adapt your code and include a "james's" version in the i2cObjectv2 library.
I couldn't get the chip working - I seem to get all high results.· i.e. 3000, there is some variation as pulling the adc inputs to 5v shows 4096 sometimes.
Attached JPG of the connections I think I am using - I will double check at home.
I've tried your code too and I don't get any more success.· I think its a hardware issue at present....· Might be an i2c clock-stretching jobby thou - but attacking the easiest bits first....
In my code the address pins are set high. As well, the VREF pin has 5V on it. I am using Beau's level shifter circuit. Are you using the dedicated I2C pins from the Prop? If not, you don't need the level shifter.
[size=2][code]
adcCLK = 28
adcAddr = %0110 ' Address pins both pulled high
adcAddrMask = %1001 ' First four bits always 1001
adcCmdMask = %0100 ' Use +vref, converter left on
pub read_adc(channel) | adcByte
' Take channel and translate to the ADS7828 address code
channel := lookupz(channel:%1000,%1100,%1001,%1101,%1010,%1110,%1011,%1111) << 4 | adcCmdMask
adcByte :=adcAddrMask << 4 | adcAddr | 0 ' load address and write bit
adc.initialize(adcClK)' Init adc
adc.start(adcClK)
adc.write(adcClK,adcByte) ' Send address and write bit
adc.write(adcClK,channel) ' Send channel and adc config
adc.start(adcClK)
adcByte := adcAddrMask <<4 | adcAddr | 1
adc.write(adcClK,adcByte) ' Send address and read bit
adcresult.byte[noparse][[/noparse]1] := adc.read(adcClK,adcAck) ' Get result
adcresult.byte[noparse][[/noparse]0] := adc.read(adcClK,adcAck)
adc.stop(adcClK)
return
[/code][/size]
The above code has been chugging along and working fine for the last couple of weeks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Comments
Jonathan - Im game. If I can get it to play i'll add to the i2cObjectv2 library!
Im in the UK so shipping costs (assuming your USA) might make this unworkable...
Still - PM me if you want.
J
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Try this.· Cleaned up the code - its force to channel 7 at present for testing.· You had a few errors that I found on close inspection and reading the datasheet.
I've set it up (so i can compile it) to use a serial debug object on the programming pins at 115_200 baud.
See how you get on - if it works it'll save the postage!
James
edit -> ZIP updated with *working* code.
Post Edited (Javalin) : 4/16/2008 3:21:28 PM GMT
Spent yesterday chainsawing trees that fell in my garden this winter. I'll try to give it a shot this morning, but I have another chainsaw day ahead. Thanks a TON for taking the time, and I'll let you know.
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Yook a quick shot at using your code. It doesn't work right off the bat. It always returns 0. I tried using your:
adcresult := i2cObject.read(i2cClK,i2cObject#Ack) << 8
adcresult &= i2cObject.read(i2cClK,i2cObject#Nak)
in my code, but I still get a 0. I tried using my equivilent code snip in your code, still reads a 0. So, your init/address/command code won't load the variable my way. My init/address/command code won't load the variable your way. So at a guess, there are issues in both the init/address/command delivery and the receiving code.
Didn't have time to look at it on the scope. My buddy just arrived with his chainsaw, so it's time to get bucking firewood for next winter.
Thanks so much for the help!!! I'll get back to it this evening.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Minor mistake in the previous zip file....· The function passes back a 0 into the variable it sets. Oops.
Corrected in the attached.
Let me know how you get on
James
Post Edited (Javalin) : 4/16/2008 10:23:39 AM GMT
Still no joy. I have yet another long day ahead, I was too beat to play last night. I wonder why it doesn't work at all. I'll take a look this evening, I shouldn't (hopefully) be so beat.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
It was indeed in the software. I obviously needed to take a few days off it. I just started again this morning from scratch and now it works. The readins are very stable, even on a breadboard. I am using Beau's i2c level shifter circuit (transistor/diode). Here is the code that did it.
James, thanks so much for all your help. I would have thrown my hands up and given up in disgust. Would you still like an ADC? I would be very happy to mail you one for all your efforts. I got 'em as samples, so dont be shy. [noparse]:)[/noparse]
Thanks to evryone else as well. I had given up on this device.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Hmm, so many mistakes it will take me over the 10 word limit. [noparse]:)[/noparse]
Read bit not in the right place and single/differential mode not being set right. The channel bits were not being masked and shifted correctly. There may have been other errors as well, I went through so many changes I lost track. Not all of the errors were present at once, but looking through all my differnt version I found all these errors at one time or another. I was also putting in an extra "stop" command that wasn't needed, but doesn't seem to matter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Had an error in the channel lookup code, as well as an extra and erronous bit shift. It really works now, on all channels as it should. [noparse]:)[/noparse] Just thought I'd update the code here in case some poor soul was foolish enough to try my code. [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
thanks for the update. It's nice to know what was done to fix the problem.
It's nice when it works the way you want it, right?!?!
-Luke
Yeah if you don't mind. Might be useful on a future toy to have an i2c adc.
Glad you got it working..!
J
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Recieved the chip today - many thanks!
James
Holy cow! I just sent it a few days ago, it made a quck journey across the pond! You are very welcome, and I thank you for your help in mastering the chip. Let us know how you like it when you try it. Mine is integrated into my project and using the dedicated i2c pins of the protoboard, and working very nicely.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
I had a play at the weekend with the i2c ADC you sent me.· I thought - Ah this will only take 30mins to adapt your code and include a "james's" version in the i2cObjectv2 library.
I couldn't get the chip working - I seem to get all high results.· i.e. 3000, there is some variation as pulling the adc inputs to 5v shows 4096 sometimes.
Attached JPG of the connections I think I am using - I will double check at home.
I've tried your code too and I don't get any more success.· I think its a hardware issue at present....· Might be an i2c clock-stretching jobby thou - but attacking the easiest bits first....
Any thoughts?
Cheers,
James
edit -> updated the schematic.
Post Edited (Javalin) : 5/7/2008 11:28:51 AM GMT
These are probably part of the slave address.
regards peter
Not shown in the diagram, but A0 is pulled to VDD (im using a changed address) but A1 is floating. I'll try pulling A1 to GND.
Cheers,
James
In my code the address pins are set high. As well, the VREF pin has 5V on it. I am using Beau's level shifter circuit. Are you using the dedicated I2C pins from the Prop? If not, you don't need the level shifter.
[/code][/size]
The above code has been chugging along and working fine for the last couple of weeks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Odd, I made a post in reply to the above days ago, and I have it in my inbox but I don't see it here. Any progress?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
No - been busy in the end of this week.
I'll try this week to get it working...
J