Microcontroller › AVR › PROBLEM IN USING FLEX SENSOR
- This topic has 3 replies, 2 voices, and was last updated 10 years, 3 months ago by Ashutosh Bhatt.
-
AuthorPosts
-
October 2, 2014 at 9:10 am #3283himanshu mittalParticipant
sir/mam
I am getting problem in interfacing 5 flex sensors at a time . i am using flex sensors as fingers and want to control motion of motors with respect to flex sensors. But when i am using 5 flex sensors at a time the delay i introduced in setting motors on , that is creating problem for me . please help
October 5, 2014 at 5:52 pm #12264Ashutosh BhattParticipantat the same time you can not get input from all 5 sensors.
you have to use TDM technique. means one by one take input from all 5 sensors so fast that it feels like you are getting data at the same time.
to rotate motor you have to apply some delay to let the motor rotate
October 6, 2014 at 4:53 pm #12265himanshu mittalParticipantThat delay i am introducing in rotating motors is causing problem for me.when my function is in delay loops obeviously it will not in read ADC value from all five sensors. I can’t understand how to program such that my program reads all ADC value continouly and my motors respond to quickly to ADC value without facing the problem of delay.
This is my program for two flex sensors ..
That delay is main rival..#include <avr/io.h>#include <avr/LCD2014.h>delay(unsigned int d){int i,j;for (i=0;i<d;i++){for (j=0;j<1000;j++){}}}int main(void){int x=0,y=0; // x for green, y for redlcd_init();DDRB=0xff;ADCSRA=0x87;int a=0,b=0;while (1){ADMUX=0x20;ADCSRA|=(1<<ADSC);while((ADCSRA&(1<<ADIF))==0);x=ADCH;ADMUX=0x20;ADCSRA|=(1<<ADSC);while((ADCSRA&(1<<ADIF))==0);y=ADCH;if (x>=180 && x<=192 && a==0){a=1;CLEARBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);}if (x>=197 && x<=207 && a==1){a=2;SETBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);delay(150);CLEARBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);}if (x>=212 && a==2){a=3;SETBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);delay(150);CLEARBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);}if (x<=208 && x>=200 && a=){a=4;CLEARBIT(PORTB,BIT0);SETBIT(PORTB,BIT1);delay(150);CLEARBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);}if (x<=196 && x>=188 && a==4){a=0;CLEARBIT(PORTB,BIT0);SETBIT(PORTB,BIT1);delay(150);CLEARBIT(PORTB,BIT0);CLEARBIT(PORTB,BIT1);}if (y>=190 && y<=202 && b==0){b=1;CLEARBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);}if (y>=207 && y<=217 && b==1){b=2;SETBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);delay(1500);CLEARBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);}if (y>=222 && b==2){b=3;SETBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);delay(1500);CLEARBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);}if (y<=218 && y>=210 && b=){b=4;CLEARBIT(PORTB,BIT2);SETBIT(PORTB,BIT3);delay(1500);CLEARBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);}if (y<=206 && y>=198 && b==4){b=0;CLEARBIT(PORTB,BIT2);SETBIT(PORTB,BIT3);delay(1500);CLEARBIT(PORTB,BIT2);CLEARBIT(PORTB,BIT3);}lcd_value(x);lcd_cmd(LINE2);lcd_showvalue(y);delay(10);}}October 8, 2014 at 6:28 pm #12269Ashutosh BhattParticipantI told you TDM technique. that means you have to use timer interrupt.
say after every 200 ms timer interrupt generated and it reads 1st flex sensor value
after another 200 ms (means 400 ms) again interrupt generated and it reads 2nd flex sensor value
like wise in every 1 sec you can read values from all 5 sensors.
meanwhile in continuous loop you just keep on rotating motors with new updated values of sensor
-
AuthorPosts
- You must be logged in to reply to this topic.