Interfacing the MAX1270 ADC - Newb SX'er
hey all, im a fairly proficient stamper, and i have finally made the leap to the sx, im still a little overwhelmed, but i thin im wrapping my head around it all.
I am trying to read the max1270 ADC with the following code that doesn't seem to work... has anyone used this chip with the sx before, might you see anything wrong with this code?
thanks to all in advance!
I am trying to read the max1270 ADC with the following code that doesn't seem to work... has anyone used this chip with the sx before, might you see anything wrong with this code?
' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "Max1270" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- SClock VAR RA.0 ' shift clock SIn VAR RA.1 ' shiftin data Sout VAR RA.2 ' shiftout data CS1270 var RA.3 ' max1270 chip select ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- ADChan var byte ADRaw var byte config var byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- GET_ADC SUB 1 ' get value from ADC ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: Low sclock high cs1270 Main: get_adc 0 ' get adc channel 1 watch adraw 'debug adc goto main 'loop ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ' Use: aVar = GET_ADC ' -- reads ADC0831 and places value into 'aVar' GET_ADC: ADChan = __Param1 READ AdcCfg + ADchan, config ' read config... maybe config = %11110000 ' set config t +5chanel 0 low cs1270 SHIFTOUT SOut, SClock, MSBFIRST, config 'set config and channel High Cs1270 adRaw = 0 low cs1270 SHIFTIN Sin, sClock, MSBPRE, adRaw\12 ' deactivate ADC0831 high cs1270 RETURN ADRaw AdcCfg: DATA %11110000, %11100000, %11010000, %11000000, %10110000, %10100000, %10010000, %10000000 ' 0-5
thanks to all in advance!
Comments
how in sx/b do you handle multiplying a variable by 1.2207?
in stamp basic i would do
mVolts = adcLevel + (adcLevel ** $3880)
thanks!
You could also use */ like this:
...with a little less resolution, but it may be adequate for your needs.
This sx/b is pritty fun. though i did spend a good day thinking my key was broke, till i realized you have to pull the local oscillator in debug mode cant wait to learn all the neat math quirks:>
Be sure to read through the SX/B help file and the "What's New" file for SX/B 2.0.
chlevel = 852 in debug when im expecting like 4_950..
without the math it works ok.
danke very much
debug results
chan = 8
chlevel= 4_054
mvolts= 852