baby0168 program code help for servo and cut off

The ATmega168/328p on the Baby Orangutan has three timers: Timer 0, Timer 1, and Timer 2. You are using Timers 0 and 2 for motor control, so you can’t do much else with them.

Since you’re already using Timer 1 to measure time periods, and you only need to control one servo, and you don’t care about your processor doing other things during that time, you should probably just follow the advice I gave you in the second paragraph of my first post in this thread.

If you want to use OrangutanServos instead, then you’ll first need to free up Timer 1.

One way to free up Timer 1 would be to re-write your pulse measuring code to use OrangutanPulseIn, which is not officially document yet but you can read about it at that link. EDIT: Never mind, this paragraph is wrong, sorry!

But I noticed that you’re only actually doing a 1-bit pulse reading: you don’t care about the length of the pulse in microseconds, you just care about which side of the threshold it was on. So you could free up Timer 1 by simplifying your measurement code like so:

while (!(PINC & (1 << PC3)));    // Wait for PC3 to go high.
delay_us(1450);
if ((PINC & (1 << PC3)))          // Test to see if PC3 is still high
{
    // The pulse is longer than 1.45 ms
}
else
{
    // The pulse was shorter than 1.45 ms
}

Either way, once you free Timer 1, you can use OrangutanServos.

Were you looking at these example programs? Those are all written for the Orangutan SVP, which does servo control differently than all the other Orangutans because it has a hardware demultiplexer for that purpose. We currently have no OrangutanServos examples for the other Orangutans. But you would only need to change the call to servos_init() to get those examples working on the Baby Orangutan.

-David