Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
1-make an array ,the number of the elements is the number of servos you have2-set each element in the array as it is a number == how many microseconds is the high pulse - 1000 3-set all ports to logic high (here the high pulse starts)4-delay for 1ms (this is the minimum pulse width, suppose servo range is 1ms>>2ms)5-run the timer1 (make it run at 1MHZ,you can have it by using the timer prescaler,this way you have 1us each count)6- while( timer1 <= 1000 ){if ( x1 >= timer1 ){ turn off pin that goes to servo x1} if ( x2 >= timer1 ){ turn off pin that goes to servo x2} if ( x3 >= timer1 ){ turn off pin that goes to servo x3} . . . if ( xn >= timer1 ){ turn off pin that goes to servo xn}}while loop ends here7-turn off timer18-delay 20msnow all the servos have got 1 pwm clockjust make a jump back to the step 3 to make the pwm continue
1/because you actually keep interupting the main flow each 10us (0>>20ms) which is not enough to do anything in the main program so your mcu is mostly stuck in the interupt routine
But you don't have to listen to me, I was just telling you what is typically done in the industry and that microcontrollers are designed with this in mind for better throughput, other wise there wouldn't be such a demand for it, and it wouldn't be on micros like the ATmega.
you might "waste" a whole ms worst case (if all servos are at 2ms)
The problem is you are making the assumption that all the servo's have to be sync'd so that they all roll over at the same point in time.
QuoteThe problem is you are making the assumption that all the servo's have to be sync'd so that they all roll over at the same point in time.For me that's not the case. But if you are to control 20 servos, each with it's own interrupt, 40hz is going to mean 40x20= 800 interrupts per second. If you divide these evenly over that second it would mean 1/800 = 1,25 ms between interrupting your other algorithms. Maybe not that much when you're talking mcu:s, but still. And this is if you manage to have just a single interrupt per servo. You must also make sure none of these interrupts try to interrupt each other which also causes some concern. Just seems easier to know that during 1ms every 30ms or so, ALL the servos get served and the rest of the time is for other algorithms. Well, I'm certainly not sure about this, and I'm no professional programmer either. But I sure want to be, and that is why this is such an interresting topic. Please more input! PS. I'm in no way anti-interrupt. My University real-time software teacher was very pro interrupt!