View previous topic :: View next topic |
Author |
Message |
dr.sjajko
Joined: 11 Sep 2009 Posts: 35
|
Posted: Fri Dec 09, 2011 10:33 am Post subject: ADS1230 communication with mega8 |
|
|
Could someone help me with AD converter ADS1230 source code in BASCOM?
I need some simple example of communication between mega8 and ADS1230.
Thanks in advance |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sun Dec 11, 2011 1:19 am Post subject: |
|
|
I never actually used that device, and TI are renowned for making odd interfaces which are sort of SPI, but not quite.
Because you need to monitor the DATA OUT line directly, hardware SPI is a bit of a problem, since to monitor the line, you need to switch off the SPI mode. But Bascom provides a good solution using the SHIFTIN command. Look in the Help and samples to see how to use it.
Very roughly, you sit in a fast loop waiting for DOUT to go low ( ie read the the processor port PIN ), indicating the device is ready to send data, then go into SHIFTIN to get 20 bits of data into 3 bytes. Process the bytes how you want. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
dr.sjajko
Joined: 11 Sep 2009 Posts: 35
|
Posted: Sun Dec 11, 2011 10:37 pm Post subject: |
|
|
Thank you Adrian
I looked SHIFTIN example and understand that but I did not understand how to make a quick loop.
Should I use BITWAIT?
My hardware is still not finished, so for now I can not try your suggestion.
If anyone has experience with the ADS1230 I prayed for the source code. |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sun Dec 11, 2011 11:13 pm Post subject: |
|
|
You could use bitwait, but I tend to avoid things which hold up the processor until something happens. If it never happens, you end up stuck forever.
If the ADS data line is on portx, bit y, then
Code: |
ADSDATA alias pinx.y
do 'main loop
do 'loop waiting for data ready
if escape= 1 then
exit do
end if
loop until ADSDATA = 0 'jump out when line low
'use SHIFTIN here to get the data
'process it how you want
loop 'end of main loop
|
That gives you a chance to detect 'escape' in the loop, and jump out if its true. Could be a button press, timer, or anything else you want. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Dec 12, 2011 2:49 am Post subject: |
|
|
I happened to be looking through some old code, and found I had done some testing on the ADC1232, which is the 24 bit version of the ADS1230.
Here is a raw read of the converter:
Code: |
'setup for ADS1232 24 bit ADC converter
ADSclk alias porta.4 'adjust port and pins to suit your hardware
ADSdata alias pina.5
Const DataOrder = 0 'MSB first
Const BitsToShift = 24
adcport alias porta
dim lADC as long
'**************** setup ports **********************
config adcport = input
config ADSClk = output 'clock pin out
'the actual read loop:
'this initiates a first conversion
'which will be valid when DATA goes lo
while ADSData = 0 'wait for data lo
'then read the ADC
shiftin ADSData , ADSClk , lADC , DataOrder , BitsToShift
'set 1 more clock cycle, to allow data to go hi again
set ADSClk
reset ADSClk
lADC = lADC / 256 'move down to 24 bits, preserving sign
'print lADC 'send result for test
wend
|
This should work on the ADS1230 as well. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
dr.sjajko
Joined: 11 Sep 2009 Posts: 35
|
Posted: Mon Dec 12, 2011 10:53 am Post subject: |
|
|
Dear Adrian,
Thanks for examples you sent me. I haven t tested code yet, but when I do that, I will let you know about outcome.
regards
Sjajko. |
|
Back to top |
|
|
dr.sjajko
Joined: 11 Sep 2009 Posts: 35
|
Posted: Fri Jan 10, 2014 9:43 pm Post subject: |
|
|
Andrian I would like to confirm that the example that you showed works well with small changes in ADS 1230th.
This is the code that I aborted the finished hardware.
thank you for your help.
Code: |
'***************************************************************************
'Test ADS-1230 its OK.
'03.01.2014
'Petrovic Nebojsa " SJAJKO "
$regfile = "m16def.dat" ' chip used
$crystal = 8000000 ' xtal used
$baud = 19200 ' baudrate N,8,1
'****************************************************************
' MCU hardware configuration
'****************************************************************
'setup for ADS1230 20 bit ADC converter
Adsclk Alias Porta.1 'adjust port and pins to suit your hardware
Adsdata Alias Pina.0
Const Dataorder = 0 'MSB first
Const Bitstoshift = 20
'**************** setup ports **********************
Config Adsdata = Input
Config Adsclk = Output 'clock pin out
'Declare LCD-a: 20*4 ili 16*1a
Config Lcd = 20 * 4
Config Lcdbus = 4
Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.5 , Db5 = Portb.4 , Db4 = Portb.3 , E = Portb.2 , Rs = Portb.1
Cursor Off
Cls
Lcd "PROBA ADS-1230"
Wait 2
Cls
Dim Ladc As Long
Do
'the actual read loop:
'this initiates a first conversion
'which will be valid when DATA goes lo
While Adsdata = 0 'wait for data low
'then read the ADC
Shiftin Adsdata , Adsclk , Ladc , Dataorder , Bitstoshift
'Set 1 More Clock Cycle , To Allow Data To Go Hi Again
Set Adsclk
Reset Adsclk
Ladc = Ladc / 4098 'move down to 20 bits, za ADS 1230
'Ladc = Ladc / 256 'move down to 24 bits, za ADS 1234
'Shift Ladc , Right , 12 'move to rigut 12 bit + 20 bit = long variable
Wend
Home U
Lcd "ADC= " ; Ladc
Lcd " "
Lowerline
Lcd "ADS 1230 acp units"
Loop
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|