EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / That delay i am introducing

That delay i am introducing

|

Microcontroller › AVR › PROBLEM IN USING FLEX SENSOR › That delay i am introducing

October 6, 2014 at 4:53 pm #12265
himanshu mittal
Participant

That 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 red
lcd_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==3)
{
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==3)
 {
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);
}
}
 

RSS Recent Posts

  • Trail camera May 20, 2025
  • how to work on pcbs that are thick May 20, 2025
  • can a AT89C51 be used as a rom? May 20, 2025
  • Telegram Based Alarm - Sensor cable protection May 20, 2025
  • using a RTC in SF basic May 19, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise