| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| akay 
 
 
 Joined: 29 Sep 2020
 Posts: 17
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Sep 30, 2020 3:13 pm |   |  
				| 
 |  
				| Which one is the calculated filtered integer, i don't understand it. i mean What integer is the result assigned to when all filtering processes are finished? i? because, i will print the filtered integer to my lcd screen.i hope to understand me. .
  	  | asmboy wrote: |  	  | Not sure what you are getting at. 
 The result is implied in the function call.
 I did not mention an LCD display -
 
 unsigned int16 adchlx(void)
 It returns an unsigned int16 on exit as in
 
  	  | Code: |  	  | unsigned int16 myanswer,
 
 myanswer=adchlx(); // myanswer has the function result
 
 
 | 
 | 
 |  | 
	
		|  | 
	
		| asmboy 
 
 
 Joined: 20 Nov 2007
 Posts: 2128
 Location: albany ny
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Wed Sep 30, 2020 3:32 pm |   |  
				| 
 |  
				| This is very very basic 'C 
 the result is passed by the function on exit .
 look at the definition:
 then the last line of the code
 ------------------------------------
 
 unsigned int16 adchlx(void){
 
 // the guts are here
 // then we return the value on exit
 
 return(accum>>3);
 }
 
 what is it that is confusing you here ?
 
 is  this a homework assignment in your first
 week   of 'C programming  class ?
 this is when  I learned  about it,
 in my first day of C functions education ,
 about a thousand years ago.
 |  | 
	
		|  | 
	
		| akay 
 
 
 Joined: 29 Sep 2020
 Posts: 17
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Sep 30, 2020 6:38 pm |   |  
				| 
 |  
				|  	  | asmboy wrote: |  	  | Not sure what you are getting at. 
 The result is implied in the function call.
 I did not mention an LCD display -
 
 unsigned int16 adchlx(void)
 It returns an unsigned int16 on exit as in
 
  	  | Code: |  	  | 
 unsigned int16 adchlx(void)
 {
 unsigned int8 i;  unsigned int16 accum=0;
 unsigned int16 s, b[16]; int1 didswap=1;
 
 for ( i = 0 ; i < 16;  i++ ) {
 b[i]= read_analog(0); // ADC set for 10 or 12 bits
 delay_us(8);
 } //    end of for loop for multi sample
 while(didswap){  // bubble sort
 didswap=0;
 for (i=0; i<15; i++){ // i 0-15
 if(b[(i)]>b[(i+1)]){ // if low element greater than next  -do  swap
 s=b[i]; // hold upper
 b[i]=b[(1+i)];
 b[(1+i)]=s;
 didswap=1;
 } // ~if
 } // ~for
 } // ~while
 // now sort and keep middle 8 values
 for (i=4; i<12; i++){  accum +=b[i];  }
 return(accum>>3);
 }
 
 
 //my ex code
 
 #include <16F877a.h>
 #fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NODEBUG
 #define use_portb_lcd TRUE
 #use delay(clock = 4000000)
 #use i2c(master, sda=PIN_C4, scl=PIN_C3, FAST, FORCE_HW)
 #include <lcd.c>
 #include <MCP3208.c>
 
 float mcpgelenfloat;
 UNSIGNED long int mcp3208gelen;
 INT32 TOPLAM;
 INT32 ORT;
 FLOAT ortsonhesap;
 void main();
 .
 .
 .
 white(1)
 .
 .
 mcp3208gelen=read_analog(0);
 
 for(j=0; j<50; j++)
 {
 toplam = toplam + mcp3208gelen;
 delay_ms(5);
 }
 ort = toplam / 50;
 Toplam=0;
 
 mcpgelenfloat=(FLOAT)ORT/13176;
 ortsonhesap=(mcpgelenfloat*100)-273.15;
 
 lcd_gotoxy(1,1);
 printf(lcd_putc,"\%2.1F%CC",ortsonhesap,0xdf);
 
 
 | 
 | 
 
 now maybe you can understand me. i can see your void function but which one of the integer i can read i dont know my friend..
 Can you edit according to the code I showed above?
 |  | 
	
		|  | 
	
		| asmboy 
 
 
 Joined: 20 Nov 2007
 Posts: 2128
 Location: albany ny
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Wed Sep 30, 2020 7:28 pm |   |  
				| 
 |  
				| the function is not "void"  - it merely requires no  data to be passed to it.
 Surely you understand that, right?
 
 it returns the value of the processed a/d readings,
 following the 'olympic sort'  rules of the function
 
 just as declared in it's first line of definition ,
 with the result  as a long integer with the same number of bits as a  single reading of the A/d hardware would . If used with a 10 bit A/d converter ie-  the 16f887 - then the final value passed back will  the statistical "best" 10 bit value over the number of samples processed by the function.
 i can't make it any simpler to understand than that.
 |  | 
	
		|  | 
	
		| akay 
 
 
 Joined: 29 Sep 2020
 Posts: 17
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Oct 01, 2020 1:27 am |   |  
				| 
 |  
				|  	  | asmboy wrote: |  	  | the function is not "void"  - it merely requires no  data to be passed to it.
 Surely you understand that, right?
 
 it returns the value of the processed a/d readings,
 following the 'olympic sort'  rules of the function
 
 just as declared in it's first line of definition ,
 with the result  as a long integer with the same number of bits as a  single reading of the A/d hardware would . If used with a 10 bit A/d converter ie-  the 16f887 - then the final value passed back will  the statistical "best" 10 bit value over the number of samples processed by the function.
 i can't make it any simpler to understand than that.
 | 
 
 first of all thank you for everything.. i almost understand you.. the question i ask is the last part you say.. ~~the final value~~ what s the final value ?
   because i try many integer in your code.. but it couldnt work.. for explain i ll show u in this code
 
  	  | Code: |  	  | 
 unsigned int16 adchlx(void)
 {
 unsigned int8 i;  unsigned int16 accum=0;
 unsigned int16 s, b[16]; int1 didswap=1;
 
 for ( i = 0 ; i < 16;  i++ ) {
 b[i]= read_analog(0); //
 delay_us(8);
 } //    end of for loop for multi sample
 while(didswap){  // bubble sort
 didswap=0;
 for (i=0; i<15; i++){ // i 0-15
 if(b[(i)]>b[(i+1)]){ // if low element greater than next  -do  swap
 s=b[i]; // hold upper
 b[i]=b[(1+i)];
 b[(1+i)]=s;
 didswap=1;
 } // ~if
 } // ~for
 } // ~while
 // now sort and keep middle 8 values
 for (i=4; i<12; i++){  accum +=b[i];  }
 return(accum>>3);
 }
 // so our olympic sort finished in this line and i want write our final value
 // which is the final value??
 // acumm?  b[i]? or ?
 
 lcd_gotoxy(1,1);
 printf(lcd_putc,"\%2.1F%CC",accum,0xdf);
 
 | 
 |  | 
	
		|  | 
	
		| asmboy 
 
 
 Joined: 20 Nov 2007
 Posts: 2128
 Location: albany ny
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Thu Oct 01, 2020 4:47 am |   |  
				| 
 |  
				| this is fundamental C programming it self that you don't understand ! 
 accum is  local to the function -so
 did you not notice that you cant compile as you used it ?
 
 WOW
 
 printf(lcd_putc,"\%2.1F%CC",adchlx(),0xdf);
 
 
 good luck with that class assignment
 |  | 
	
		|  | 
	
		| MotoDan 
 
 
 Joined: 30 Dec 2011
 Posts: 55
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 15, 2021 3:37 pm |   |  
				| 
 |  
				| Great routine asmboy! 
 I think there may be a typo in the sort loop upper limit. Orig code shows <15, but it should probably be <16. Corrected code below.
 
 Thanks for the great job. It was just what I needed to clean up some noise that is in my system.
 
 Cheers!
 
 
  	  | Code: |  	  | for (i=0; i<16; i++){ // i 0-15
 
 | 
 |  | 
	
		|  | 
	
		| asmboy 
 
 
 Joined: 20 Nov 2007
 Posts: 2128
 Location: albany ny
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Fri Apr 16, 2021 6:54 am |   |  
				| 
 |  
				| Moto dan - 
 no actually you broke it.
 badly
 you really don't understand the
 compare-sort-swap loop at all .
 
 array elements are numbered 0-15 // 16 values
 but we are comparing and swapping( or NOT swapping)
 as high as element  i+1
 ie elements 0-15
 
 think about what happens on a compare for i=14  ie "<15"
 for the compare and swap , of  1+i
 
 worse think of what elements you access if you
 change the loop to be "<16"
 
 for all those i+1 element accesses
 when you allow i=15 to be used
 what are you planning to store in the 17th element
 ie  1+i ???
 of a 16 element array indexed as 0-15 ?
 
 feel free to make any change you want but don't post it as "fixed" unless you want to embarrass yourself further.
 |  | 
	
		|  | 
	
		| MotoDan 
 
 
 Joined: 30 Dec 2011
 Posts: 55
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Apr 16, 2021 8:50 am |   |  
				| 
 |  
				| asmboy, 
 I see your point. Didn't study the sort closely enough before making the assumption that the loop limit was incorrect. I revised your comment on that line to read "i 0-14" instead of 0-15.
 |  | 
	
		|  | 
	
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Nov 20, 2021 8:35 am |   |  
				| 
 |  
				| Without detracting the contributions related to the filtering and averaging system proposed in this thread, I think it is pertinent to give credit to
 Sherpa Doug who posted his "Olympic scoring" filtering method for
 smoothing/averaging ADC reads posted in this forum on: Fri Mar 28, 2003
 
 http://www.ccsinfo.com/forum/viewtopic.php?t=3462
 
 best wishes
 _________________
 Humber
 |  | 
	
		|  | 
	
		| asmboy 
 
 
 Joined: 20 Nov 2007
 Posts: 2128
 Location: albany ny
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Nov 20, 2021 9:14 am |   |  
				| 
 |  
				| I did not know this post you refer to existed when I wrote this original, much simpler routine.  They are not at all the same - if you bother to look carefully.  If you want to credit and crib that one- why it's all the same to me, but the earlier vaguely similar code is inferior in multiple ways if you examine it closely enough. Execution time heading the list. |  | 
	
		|  | 
	
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Nov 23, 2021 9:35 am |   |  
				| 
 |  
				| I was very careful in my opinion with respect to the originality of the procedure, I did not make an assessment judgment regarding any one in particular, but what I
 think is necessary to highlight is that the concept of "Olympic Score" used in the
 method corresponds to Sherpa Doug.
 Surely there are hundreds of ways to implement it in different codes and languages,
 I already have my own code, but the originality of the concept belongs to him.
 _________________
 Humber
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19967
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Jan 10, 2022 8:51 am |   |  
				| 
 |  
				| I have to pick up here. The concept of 'Olympic sorting', comes from the Olympic games, not sherpa dog. The implementation here is his, but this is
 the way that scoring is done in a lot of Olympic events. Normally with
 something like five or six judges scores, and the highest and lowest are
 rejected (basically in case these might be a little 'biased'). The remaining
 scores are then simply averaged.
 Hence the name!....
 So the 'originality' of the concept does not belong to him....
 It is actually mathematically called a 'trimmed mean' sort, and has been
 around for ages.
 
 [url]
 https://en.wikipedia.org/wiki/Truncated_mean
 [/url]
 |  | 
	
		|  | 
	
		| Humberto 
 
 
 Joined: 08 Sep 2003
 Posts: 1215
 Location: Buenos Aires, La Reina del Plata
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Jan 10, 2022 11:44 am |   |  
				| 
 |  
				|  	  | Quote: |  	  | "The concept of 'Olympic qualification' comes from the Olympics, not from the Sherpa dog" | 
 
 Wikipedia it is not necessary in order to know what the concept of Olympic classification is about,
 is self-defined by the expression itself.
 On the other hand -as far as I know- this is not a forum of language, literature or idiomatic expressions,
 therefore when the concept "Olympic Classification" is mentioned, it refer to the way of writing a code to
 obtain an average value discarding outliers (maximum and minimum)
 When I credit Sherpa Doug, (not Dog) clearly I'm referring to someone who linked -for the first time in my
 humble opinion- this expression to exemplify a procedure or technique applied to solving this algorithm.
 Of course, this will be true unless somebody will show the evidence of  a previous piece of coding with the
 same concept as I did.
 _________________
 Humber
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19967
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Jan 17, 2022 2:25 am |   |  
				| 
 |  
				| I used Olympic averaging in the early 70's, when handling results from surveyors. Was written at that time in Fortran. Was standard practice
 and code.
 Sherpa Doug was one of the first people to talk about this on this forum,
 I remember threads nearly 20 years ago where we were talking about this
 and variants on this.
  |  | 
	
		|  | 
	
		|  |