Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Servo movement manually

2 posters

Go down  Message [Page 1 of 1]

1Servo movement manually Empty Servo movement manually Mon Sep 06, 2021 3:51 pm

Furk



Hello,

I have a programm in where a servo moves periodically and after reaching a certain position it should stop and wait till PIND4 is pressed. In the meantime it should be possible to move it manually through pushing the buttons PIN1 and PIN0. In my example after reaching that position it stops but cant be moved through the pushing of the buttons PD0 and PD1.

Code:

PIND1,PIND0 and PIND4 are set high

   OCR1B = ICR1 - (1000+pos*100);
      
      while((PIND & (1<<4))); // Wait till   PIND4 is pressed
      {
         if(!(PIND & (1<<0)))
         {
            
             OCR1B=OCR1B-100;
            _delay_ms(10);
            
         }
            if(!(PIND & (1<<1)))
            {
                OCR1B=OCR1B+100;
               _delay_ms(10);
            
            }
         
         
         
      }




I would be grateful for any help.

2Servo movement manually Empty Re: Servo movement manually Mon Sep 06, 2021 10:31 pm

arcachofo

arcachofo

Hi.

As I understand your code, you can use PD0 and PD1 while PD4 is High.
Once PD4 is low, it exits the while loop and you no longer can use PD0 and PD1.

3Servo movement manually Empty Re: Servo movement manually Tue Sep 07, 2021 2:32 am

Furk



Hi arcachofo,

While PD4 is High and the servo is on a fix position. I want the servo to move by pushing the buttons on PD0 or PD1, but unfortunately the servo does not act by it. The code seems to be correct

4Servo movement manually Empty here the complete code Tue Sep 07, 2021 2:43 am

Furk



Code:
#define  F_CPU 1000000UL

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
   DDRB |= 0xFF;
   DDRB |= 0x00;

   ICR1 = 19999;
   TCCR1A |= 1<<WGM11 | 1<<COM1A1 | 1<<COM1A0 | 1<<COM1B1 | 1<<COM1B0;
   TCCR1B |= 1<<WGM13 | 1<<WGM12 | 1<<CS10; //Prescaler=1,inverted, fast PWM,Mode 14
   
            OCR1A = ICR1 - 1000;
            OCR1B = ICR1 - 1000;
            PORTD |= (1<<4)|(1<<1)|(1<<0);
   

while(1)
{
   pos=100;
OCR1A = ICR1 - (1000+pos*100);
OCR1B = ICR1 - (1000+pos*100);
      
      while((PIND & (1<<4)));
      {
         if(!(PIND & (1<<0)))
         {
            OCR1B=OCR1B+10;
            _delay_ms(1000);
            
         }
         
            if(!(PIND & (1<<1)))
            {
                OCR1B=OCR1B-10;
               _delay_ms(1000);
            
            }
         
         
         
         
      }
      
      
      
   }
   
   
   
}
maybe you can try it

5Servo movement manually Empty Re: Servo movement manually Tue Sep 07, 2021 9:00 am

arcachofo

arcachofo

Hi Furk.

The code seems to be correct
Sorry but the code is not correct.
Check it line by line carefully.

Furk likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum