Servo code didn't work...

Go To Last Post
57 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, Andy. May I ask you how you are processing the picture, mean- adding such a cute red, please.

Last Edited: Fri. Dec 3, 2021 - 01:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


grohote wrote:
how you are processing the picture, mean- adding such a cute red

 

 

it has since been acquired by Corel, and is now: https://www.paintshoppro.com/en/

 

This 21 year old version does all I need - so I see no reason to "upgrade".

 

(the joys of software you actually get on physical media - not tied to some cloud subscription)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It was shown rightly here:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Servos work, so it’s time for summary.

 

I started this thread from one of my projects - 3Servos + 2Potentiomwters + 1Pushbutton:

 

 

My MCU is ATmega328p, and my project used 4 cases of 2 peripherals – Time/Counter and ADC:

Time/Count_0 for 1 servo, Timer/Counter_1 for 2 servos;

ADC channel 0 and 1 for 2 potentiometers.

 

At first, only servo used Timer/Counter_0 worked correctly, so I opened this thread. Inspired by the comments here, I modified my code, and tested it by example in Arduino IDE, I’m sure configuration for Timer/Counter_1 was OK, then is the ADC.

 

I listed the suggestions valuable here, the ones with flag “(Tested)” were tested and adopted in my project, the ones without it haven’t been tested and accepted due to the lower requirements and primitive components.

 

1. Software

* use “=” instead of “|=” (Tested)

* read the entire ADC value all at once into an integer variable (Tested)

* starting the ADC conversion and waiting for it to finish before reading the ADC results (half Tested)

*

 

2. Hardware

* power supply goes directly to the servos 

* Remove any connections shared between the pots & the motors

* (do not)use such(22kΩ) a weak switch pullup in a noisy motor situation

* POWER CAPACITORS FOR MOTORS(should be large like 330uF, 470uF, 1000uF, etc)

 

You see, I have just used suggestions for software and the motors run rightly, avrfreaks.net is really a website could get some solutions, I appreciate all the responses for this post.

 

Special thanks to david.prentice and avrcandies:

 

I have to say:

    You know ADC

        You know AVR

            You know Servo

The last and the first,

You know “|=”.

Last Edited: Wed. Dec 8, 2021 - 01:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jolly good.   You have addressed all the important lessons.

 

Regarding starting the ADC conversion and waiting for it to finish.   You can either wait for ADSC to clear or for ADIF to set.

 

ADSC is easier because it just reflects the conversion state.

ADIF sets when conversion has completed but you must clear ADIF manually.   (read the note in the datasheet)

 

It is reasonable to just poll for completion.   You might use interrupts in busy applications.

 

David.

Last Edited: Mon. Dec 6, 2021 - 12:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
use interrupts in busy applications.

OK, I will try interrupt in this project, and I would ask you for break through when I met blocks.

Pages