Harold, thanks for your replay. Your brought interesting point on ADC conversion. suppose I am looking for 951 I better test for 949-953 if ((adc_x>948)&&(adc_x<954)) // looking for 951 do you think above example will work? thanks for your help Andre Harold Hallikainen wrote: >Without all the elses, the if's after the successful test will continue to >run. That is, every test will be run every time. With the elses, tests >after the success will be skipped. Another way to do this, which is, I >believe, more readable, is to use the switch-case statement. > >I am surprised that you are testing for 10 specific ADC values. It is >unlikey that successive ADC readings will land on exactly a particular >number. More likely they will be one count higher or lower, perhaps more >variation depending on circuit stability. Do yo want to test the ADC for a >range of values? If so, the if, or if else if test seem to be he only way >to go (or a very large switch-case statement or a large array where the >ADC indexes into it). > >Harold > > > > >>Hi to all engineers, >> >>I am reading ADC to compare 10 different values if they are matched >>then each match >>has it's own set value. my question is. >> >>1. what is the different between if else if for example >> >> if (adc_x==1023) // 5v 1023 >> { >> xbyte_lsb=0xff ; >> xbyte_msb=0x01 ; >> } >> else if (adc_x==921) // 4,5v 921 >> { >> xbyte_lsb=0x9A ; >> xbyte_msb=0x01 ; >> } >> >>or without else if >> >> if (adc_x==1023) // 5v 1023 >> { >> xbyte_lsb=0xff ; >> xbyte_msb=0x01 ; >> } >> if (adc_x==921) // 4,5v 921 >> { >> xbyte_lsb=0x9A ; >> xbyte_msb=0x01 ; >> } >> >>I do not clearly understand what does "else if" do? >> >>is there better way of testing ADC ? >> >>Any feedback will appreciate. >> >>Andre >>-- >>http://www.piclist.com PIC/SX FAQ & list archive >>View/change your membership options at >>http://mailman.mit.edu/mailman/listinfo/piclist >> >> >> > > > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist