Shop OBEX P1 Docs P2 Docs Learn Events
SXB and an ADC0831 a/d converter — Parallax Forums

SXB and an ADC0831 a/d converter

RS_JimRS_Jim Posts: 1,771
edited 2008-07-26 05:02 in General Discussion
Good Morning all,
I have been attempting get a reading from an ADC0831 adc converter with SXB.· It appears that with a 50_000_000 clock the clock stream from SHIFTIN is too fast.· when I add a parameter to SpeedMult it gets even faster. I have run it under debug and walked through the subroutine and it seems to be reading the chip OK but when I run it in realtime the results are 0 regardless of the input voltage.·

DEVICE········· SX48, OSCXT2,' TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
Adc_clk·PIN·RD.4·Output
Adc_Dio PIN·RD.3·Input
Adc_CS·PIN·RD.5·Output
··org···· bank4_org
bank4··=·$
adc_bank·=·bank4
ENDASM
ADC_RESULTS·VAR·Byte(16)
Adc_Result ·Var·ADC_RESULTS(0)
Adc_Resultw·VAR·ADC_RESULTS(1)
Adc_resultw_lo·VAR·ADC_resultw
Adc_resultw_hi·VAR·ADC_RESULTS(2)
Timer1_R1·VAR·ADC_RESULTS(3)
Timer1_R1W· ·VAR·word· ···'ADC_RESULTS (3)
Timer1_R1_lo·VAR·ADC_RESULTS(3)·· ·'Timer_R1
Timer1_r1_hi·VAR·ADC_RESULTS(4)
Timer1_R2·VAR·ADC_RESULTS(5)
Timer1_R2w· ·Var·ADC_RESULTS(5)
Timer1_R2_lo·VAR·ADC_RESULTS(5)··'Timer1_R2
Timer1_r2_hi·VAR·ADC_RESULTS(6) ··'Timer1_R2 + 1··
Freq_Set·Var·ADC_RESULTS(7)
Freq_Set_lo·VAR·Freq_Set
Freq_Set_hi·Var·ADC_RESULTS(8)··'Freq_Set + 1
'Subroutines
Read_Adc ·Func·2,0

Start:
a bunch of port set up code in ASM
·high ADC_CS
GOTO Main
Page_1:
· ADDRESS $200
Func READ_ADC
·low·ADC_CS
··SHIFTIN·ADC_DIO,ADC_CLK,MSBPOST, adc_Result\8

·high·ADC_CS
·'__wparam12= adc_Result */ Scale·'scale ADC result to 0-100
·Return·· 'adc_result
ENDFUNC
MAIN:
Page_2:
· ADDRESS $400
MAIN:
do
·adc_Result = Read_ADC
\Watch adc_Result,8,UBIN
loop

I haven't tracked every step of the assembly code, but as it is leaving the func it seams to be changing the value of the result in __param1 before copying it to adc_result.· I run mode I always get 0 as the result. Walking thru the program I get results that change with the changing voltage on the input to the ADC.
Is my clock really too fast and how do I slow it down? I have commented out the scaling instruction for now until I find the cause of the 0 result.

Jim

Comments

  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-07-25 16:35
    I've use the ADC083x family at every possible clock frequency and have never had a problem -- and I always crank up the clock rate with the multiplier. The SX/B compiler creates a clock rate (~83 kb/s) so your OSC setting is actually not the issue, I'm suspecting it's a connection or how you're interfacing. Give the attached program a try; I've used this code in many projects.
  • RS_JimRS_Jim Posts: 1,771
    edited 2008-07-26 05:02
    Jonny Mac,
    Thanks for the code assist.· The clock=0 was appearently my problem.· I got it running fine after looking at your code. Also I had 1 too few bits in my input.· I forgot the start bit! It does run at 50_000_000 OK!
    Thanks again
    Jim
Sign In or Register to comment.