Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
wouldn't it be better if u just look at the sharp ir tutorial
but I'm thinking a cap across ground and output might fix it.
try to make an eqn urself by taking the digital readings and plotting them in excel
# include<stdio.h># include<avr/io.h># include<util/delay.h># include<avr/interrupt.h># include<stdlib.h># include<string.h># include<avr/pgmspace.h>#define USART_BAUDRATE 38400 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL)))- 1) char u[11]="adcvalue\r\n"; char *d; char b[10]; char *p; unsigned int a;void adcinitialize();void uartinitialize();void adcgetvalue();void transferusart();void printvalue(char *); int main(void) { adcinitialize(); uartinitialize(); while(1) { adcgetvalue(); p=itoa(a,b,10); strcat_P(b,PSTR("\r\n")); d=&u[0]; transferusart(); } return(0); } void adcinitialize() { ADCSRA|=_BV(7)|_BV(ADPS2)|_BV(ADPS1); ADMUX=0x60; ADCSRA|=(1<<ADSC); while(!(ADCSRA & (1<<ADIF))); ADCSRA|=(1<<ADIF); TCCR1B|=(1<<CS12); } void uartinitialize() { UCSRB= (1<<RXEN) | (1<<TXEN); UCSRC= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); UBRRL=BAUD_PRESCALE; UBRRH=(BAUD_PRESCALE>>8); } void adcgetvalue() { ADMUX=0x61; ADCSRA|=(1<<ADSC); while(!(ADCSRA & (1<<ADIF))); ADCSRA|=(1<<ADIF); a=ADCH; } void transferusart() { while (*d != '\0') { while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR =*d ; // Echo back the received byte back to the computer d++; } TCNT1=0; while(TCNT1<=60000){}; TCNT1=0; printvalue(p); } void printvalue(char *l) { while (*l != 0x00) { while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it UDR =*l ; // send out each bit of charcter to your computer l++; } TCNT1=0; while(TCNT1<=60000){}; TCNT1=0; }
but I'm thinking a cap across ground and output might fix it. An averaging algorithm won't work - the nose is too high and throws the average off.
The sharp IR is VERY noisy as a sensor.Hook it up to an oscope and you will see. You need to put a noise filter to make it useful. I haven't had time to experiment, but I'm thinking a cap across ground and output might fix it. An averaging algorithm won't work - the nose is too high and throws the average off.
I don't have excel.
Do you think a 0.1 uF capacitor would be enough (or too much) to smooth out the noise from what you saw on the oscope?
I could avoid hours of trial and error
i would never buy a scope, i go to the college to try my stuff
But if you happen to have a sharp ir with you next trip to the electronics lab, please let me know what freq and voltage you see any noise at. Or even the rate of change for normal detection. I know all the sharp irs are going to be different,e specially between models, but a good ball park to base my guessing off would be helpful.
I have noticed though that when i increase the adc aquisition time, I get barely no spikes whatsoever. It just takes longer to take a reading.
Quote from: superchiku on April 12, 2008, 02:05:41 AMtry to make an eqn urself by taking the digital readings and plotting them in excelI don't have excel.