In SX Microcontrollers, SX/B Compiler and SX-Key Tool, RS_Jim wrote: 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 ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=281318 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)