Diagnostic C Program for Baby Orangutan

I have checked out the C++ example referenced in other threads, but was hoping to see an example in C.

When learning the specific initializations/ports/etc it is nice to see it all in one declaration in one file.

Does anyone have such a program? I am looking to get the motor control sorted first.

Pololu folks,
Don’t you have a test program that you use to verify that the board with hbridge is functioning before you ship them out? I really want to be sure that board is not defective, specifically the hbridge.



To test the motor driver, you can make one control line high and the other low (per H-bridge) and see if the motor runs.

- Candice

Can you take a quick look at this program and let me know what I am doing wrong setting up the pwm?

This is with the mega48, so it is slightly different than the mega8. It is using 20mhz external osc.

The motors run full on/off, but no pwm that I can tell. I think I am missing a pwm register setting.


#include <avr/interrupt.h>

#define SetBit(x,y) (x|=(1<<y))
#define ClrBit(x,y) (x&=~(1<<y))
#define ToggleBit(x,y) (x^=(1<<y))
#define Testbit(x,y) (x&(1<<y)) // Returns 0 if clear, Bit value if set.

void init_motor(void);
void sleep(long);
void init(void);
void test_motor(void);
void blink_led(void);

int main(void) {
	while(1) {
	return 0;

void init() {
	PORTB = 0x00;
	DDRB  = 0x00;
	PORTD = 0x00;
	DDRD  = 0x00;

	MCUCR = 0x00;
	EICRA = 0x00; //extended ext ints
	EIMSK = 0x00;
	TIMSK0 = 0x00; //timer 0 interrupt sources
	TIMSK1 = 0x00; //timer 1 interrupt sources
	TIMSK2 = 0x00; //timer 2 interrupt sources
	PCMSK0 = 0x00; //pin change mask 0 
	PCMSK1 = 0x00; //pin change mask 1 
	PCMSK2 = 0x00; //pin change mask 2
	PCICR = 0x00; //pin change enable 
	PRR = 0x00; //power controller
	sei(); //re-enable interrupts


void init_motor() {
    TCNT1H = 0x00; //setup
    TCNT1L = 0x00;
	TCCR1A = 0x01;
	TCCR1B = 0x0F;

void test_motor() {
	TCCR1A = 0xD1;
	OCR1AL = 100;
	OCR1BL = 100;
	TCCR1A = 0xB1;
	OCR1AL = 100;
	OCR1BL = 100;

void blink_led() {
	ClrBit(PORTD,PD1);	// LED off

void sleep(long msecs) {
	long i;
	for(i=0; i<(msecs*2000);i++);

Wow, is anyone home on these forums?

The problem is that PB1 and PB2 need to be set as outputs.


Does anyone from Pololu monitor these newsgroups?


It’s good to hear that you solved your problem. Someone here (usually me) looks at the forum once in a while. Easy questions get answered more quickly; debugging someone else’s code can take a lot of time. In general, you’re more likely to get a good response if you trim your code to the minimal case that demonstrates the problem.

- Jan

My original question had nothing to do with debugging code. A simple, “no, we don’t have any C based test programs” would have been sufficient. Even now I have not received a reply to that question…

I wouldn’t even mind an assembler example.

It is odd that you sell a controller board with basic features, yet you don’t provide a simple program to explain how it is used to help speed the use of the board. The C++ example is cool, but I find it is not the best language to understand the registers, as everything is so indirect.

I think your customers will have more success if you go a little farther and help them start using your orangutan controller boards.

I find the manufacturing quality excellent, the price great, but the support lacking.

Thanks for listening,


Thanks for your feedback; we know the Orangutan support needs to improve, and we are working on it.

(Given your original post, I feel that my reply was reasonable. “No, we don’t have any C-based test programs” would not have helped at all on what looked like your bigger concern regarding an H-bridge failure. Even if the test program used PWM (it doesn’t, and I didn’t have access to the source code at the time), testing full on power is a good first step.)

When you do finish a project using the Baby Orangutan, it would be great if you could post a link!

- Candice