Baby o pwm project


I want to upload code to my baby o board that will pulse PB3 with 5 volts, immediately upon completion of the upload, via the pololu usb programmer.

Will this damage anything, in that the ribbon connector will still be connected?

I’ve read the cautions about PB4 and PB5, but there is no mention of PB3


Project details:

I have several baby o boards w/328p chip and usb programmer that I am using for a combat robot project. Initially, all I needed to do is wire the board, upload code and life was good.

The code uses the M1 outputs to simply pulse a large LED. Timer1 isconstantly being reset and interrupts are constantly being toggled (off during math calculations).

The code toggles pins PD2 & PD4, which simply turn brushed motors on/off via mosfets.
In this application, variable speed is not needed.

I am trying to convert this to brushless control. In that the timer0 outs are already occupied and timer1 is controlling timing, I think that it would be best to use timer2 to send phase correct fast pwm pulses to outputs PB3 and PD3.

I will need to tap into the board between these pins and the h bridge in order to do this.


What programmer are you using? It should be safe to do what you’re describing if you are using a Pololu programmer, such as the USB AVR programmer, because they keep the programming lines as high-impedance inputs whenever they let the target AVR run. If you have a different programmer, you should verify that it also behaves this way, or at least verify that it has current limiting resistors on its programming lines.

The main reason for the warnings in the user’s guide is that connecting external components to PB4 and PB5 could interfere with programming. Since PB3 is not accessable on the Baby Orangutan, there is no reason to warn people about external connections on this line interfering with programming.

- Ben

Hi Ben and thanks for the quick response :slight_smile:

I am using the usb avr programmer from pololu.

In reading some of your docs, I noticed that it is possible to set both PD3 and PB3 high at the same time. Does this mean that I could use the M2A and B outputs for pwm, or do I have to tap into the actal PD3 and PB3 pins?

and if so, will I be able to send different pulse widths to each?

I wouldn’t recommend using the motor driver outputs as PWM inputs to another device if you need precision pulses, but you could try it and see if you get results that work for your application. Note that the output voltage of the motor driver will be between VIN (not necessarily 5V) and ground. You can make the two motor drivers output the different duty cycles (pulse widths).

- Ben

Well here is my first attempt to see if I can get phase correct pwm out this board.

Eureka!! It actually seems to work !!!

If you guys could look at this and tell me where I might improve upon it or if there are any problems with it, it wold be deeply appreciated

I’m not 100% sure how it all works, but this iswhat I was trying to do…I guess that uou guys call it pseudo code or whatever…



Upon first glance, I don’t see any problems with your code. I didn’t look at the datasheet to verify your register values are correct, but if you’re seeing the proper PWM frequency and duty cycle on your scope, then your settings are probably right.

If all you need are 1ms and 2ms signals, the output of the H-bridge might do the trick. I think you should try it, but as I said in my previous post, make sure your VIN isn’t too high for the device receiving the PWM signal, and you should check the motor driver truth table to make sure the output you’re using is alternating between VIN and ground (rather than VIN and high-impedance).

If you want to access PD3 itself, you might be able to solder a small wire to the appropriate leg of the H-bridge IC (be careful not to short to adjacent legs). Desoldering the H-bridge legs isn’t necessary (the H-bridge won’t interfere with the signal) and sounds like it could be a lot of work.

Setting the output value of the pins using the PORT register will have no effect when the PWM module is enabled. If you want to change the value of OCR2A and OCR2B on the fly, just set them to their new values. The OCRx registers are double buffered, so the new value won’t take effect until timer 2 reaches its TOP value (or maybe BOTTOM, you’d need to verify by checking the datasheet). This double-buffering means that setting OCR2x won’t produce a glitch as could happen if the change took effect immediately.

- Ben

How are you powering your Baby Orangutan? I’m surprised your pulses aren’t 5V peak-to-peak. You should only be concerned if the device you’re sending signals too cannot handle 5V logic. If it’s a 3.3V device without 5V-tolerant pins, then you should use a voltage divider to drop the pulse voltage.

- Ben

Typo error it is 5v peak to peak

it’s all working fine, sofar. Signal out of the H bridge is too jittery and not really a square wave, so I soldered to the board and things look good!!

Thanks for all your help

I’m glad to hear things are working well so far. We’d love to hear more about it as it progresses. Good luck with your project!

- Ben

I should have my test platform up and running very soon.

I will post the results then.

Thanks again for your patience!!

Baby O controlled combat robot

Ok…not a perfect test platform and floor conditions have deteriorated, but here is the sneak preview…

It looks to me like the typical melty wobble is all but gone??

over 9 minutes runtime on 2S Lipo…calibration mode speed is 1400 rpm, current top speed of 3500 rpm and it still translates at speed!

Let me know what you think

That looks great! I’m glad to see you got it working so well.

- Ben

Seems to work well, but needs a few tweaks