| View previous topic :: View next topic |
| Author |
Message |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Tue Feb 28, 2006 6:10 pm Post subject: AVR ATmega8/168 OpenServo Port |
|
|
I just wanted to start a forum thread on the upcoming port of the OpenServo software to the ATmega8 and ATmega168. I have DIP and TQFP versions of these MCUs on order from Digikey and I'll hopefully have them in hand in the next day or two.
My initial priority will be to get the bootloader ported which should basically involve writing code for the TWI peripheral hardware on the ATmega rather than the USI on the ATtiny -- this code will also be directly applicable to the OpenServo software as well. Most of the rest of the bootloader code should come over pretty cleanly.
After that, I'll start on the OpenServo software itself. I'll follow a process very similar to my original ATtiny45 development where I get the software running on a DIP version of the chip running on the AVR STK500 dev kit. The STK500 will connect to a handmade H-Bridge circuit I used for my original development and drive a servo motor. My likely steps for software development will be: the TWI chip (mostly recycled from the bootloader above), the ADC/timer code, the PWM/timer code and finally any misc. stuff such as EEPROM code. Although the registers to control peripherals on the ATmega will be different from the ATtiny, hopefully I won't run into anything that requires significant redesign.
If everything goes smoothly and I have enough time in the evenings to work on this, I believe it should take about a week or two for the port. Some time may also be consumed restructuring the source tree to support the ATtiny45, ATmega8 and ATmega16 development branches of the code.
After the software port is complete I'll start in earnest on a redesign of the PCB to accommodate the ATmega8/168 MCUs.
I'll keep this thread updated as I make progress on this. Questions, comments or suggestions are always welcome.
-Mike |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Fri Mar 03, 2006 5:10 pm Post subject: |
|
|
OK, I received the ATmega8/168 parts yesterday from DigiKey and can finally get started on the software port.
-Mike |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Sun Mar 05, 2006 8:08 am Post subject: |
|
|
March 4th Status Update
Hmmm. Kinda quiet on the forum for the last few days.
I got about 90% of the bootloader ported to the ATmega8. I should be able to wrap up the rest of the work by the end of the weekend. The hardware TWI on the ATmega is much nicer than the USI and makes for more compact code.
At this point I'm not sure if I'll start on the ATmega8 version of the OpenServo or spend another day completing the ATmega168 bootloader while I'm working in this area anyway.
Can't wait to have 8K or 16K to start more OpenServo features.
I finally got a look at the ATmega8/168 TQFP packages. Not nearly as scary as I thought they would be. Many more pins than the ATtiny45, but definitely doable with a soldering iron. Hopefully the PCB rework won't be a major issue.
-Mike |
|
| Back to top |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1028 Location: Manchester, UK
|
Posted: Sun Mar 05, 2006 11:28 am Post subject: |
|
|
It is kinda quiet in the forums.
I think we are all waiting for the port of the Openservo to the new ATmega!
It would be good if you could finish the port of the 168, and then the 8.
If you could give me a heads up on what pins you are using, I could start to
whip up some prototype boards to get a feel for it.
Personally I can't wait for the port to the 168 to happen!
Baz |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Sun Mar 05, 2006 10:46 pm Post subject: |
|
|
Barry, I'm glad to hear that some are waiting for the port. Is there a specific interest of the ATmega168 over the ATmega8? It seems that some advocated the ATmega8 and some the ATmega168. My general plan is to code for the ATmega8, but simultaneously port to the ATmega168 as the two chips are very similar.
I'll post more information in the coming days that should help you get a head start on some prototype boards. I haven't yet looked at the pinouts, but I should have it sorted out in two to three days.
-Mike |
|
| Back to top |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1028 Location: Manchester, UK
|
Posted: Sun Mar 05, 2006 10:54 pm Post subject: |
|
|
Atmega168 gives me more scope to play with extras. I am looking at putting some external sensors on the servo board too.
Also... Atmega8 is out of stock most places here, so I suppose it's a logistical thing.
Keep up the good work!
Barry |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Mon Mar 06, 2006 8:08 am Post subject: |
|
|
March 5th Status
Completed the ATmega8 and ATmega168 bootloaders. They are now checked into CVS. I only did initial smoke testing, but they appear to be functioning reasonably well. The ATmega bootloader code is not merged with the ATtiny code at this time. I will likely decide to keep them separate for a number of reasons. Also, I modified TWIBootProg to include programming of the ATmega8 and ATmega168.
I'll do more extensive testing of the bootloaders over the next few days.
My next step is to examine the ATmega8 and ATmega168 in a bit more detail to determine which to port the OpenServo code to first. The ATmega168 looks a little more promising as it's 8-bit timers and PWM capabilities look to be nearly the same as those as the ATtiny45. I'll know a lot more in the next 24 to 48 hours.
-Mike |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Tue Mar 07, 2006 7:01 am Post subject: |
|
|
March 6th Status
Started port of the OpenServo to the ATmega168. It's peripheral features are more similar to the ATtiny45 than the ATmega8 so it will be easier to port to.
Completed the the ADC, TWI/I2C and watchdog modules. Like the ATtiny45, ADC is driven by Timer0 to drive ADC samples every 512 uSecs. ADC0 will be power feedback and ADC1 will be position feedback. The TWI/I2C module was brought over from the bootloader port I completed yesterday.
The PWM may take a day or two. The ATtiny45 uses the Timer1 module, but the remaining two timers on the ATmega128 operate differently. Shouldn't a big deal, but I'll want to verify proper PWM timing with a logic analyzer to make sure I get it right.
Everything else compiles cleanly. Hopefully I'll be driving hardware from the STK500 board within a few days.
-Mike |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Wed Mar 08, 2006 1:49 am Post subject: |
|
|
March 7th Status
Success!!! I completed the PWM module for the ATmega168 earlier today. Everything was wired up this afternoon using the original prototype H-bridge circuit and servo hardware stripped of a PCB. I fired it up and everything worked as expected. OpenServo is business with 16K of Flash!!!
The result can be seen below:
I still plan to to add support for the ATmega8 MCU as well, but it may take me a few days to get to.
I want to do a little code clean-up and I should have everything checked into CVS by Wednesday or Thursday.
The same code will compile for both the ATtiny45 and the ATmega168. However, I need to think about how best to arrange the code tree to support the ATtiny45. Any new code will break the 4K Flash limit and will no longer compile for the ATtiny45. Perhaps a CVS branch for continued ATtiny45 development? Does someone know how to do this? Any other ideas or suggestions?
Hmmm. Time to start thinking about a new PCB revision for the ATmega8/168.
-Mike |
|
| Back to top |
|
 |
andylippitt Site Admin
Joined: 02 Jan 2006 Posts: 155 Location: Denver, CO
|
Posted: Wed Mar 08, 2006 1:56 am Post subject: |
|
|
| Fantastic! I'm looking forward to building some new boards! |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Wed Mar 08, 2006 5:41 am Post subject: |
|
|
The ATmega168 code is checked in. However I found the following issue.
On the ATmega168 I chose to use timer/counter2 with PWM outputs to the motor on OC2A and OC2B. Unfortunately, the ATmega8 timer/counter2 is less sophisticated than the ATmega168 lacks OC2B. Instead, I should have chosen to use timer/counter1 on the ATmega168 which outputs on OC1A and OC1B. The ATmega8 supports OC1A and OC1B on the same pins. Making this change will allow both chips to use the same PCB.
Oh well, this change will take just a few more hours.
-Mike |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Wed Mar 08, 2006 7:01 am Post subject: |
|
|
One final update for today. Most of the ATmega8 port is complete. I just need to rework the ADC code as it is quite a bit different from the ATtiny45 and ATmega168.
Right now all the code is in the ATtinyX5_OpenServo directory in the source tree, but I'll work with Andy to rename this directory to something a little more generic.
OK, I need to get some sleep.
-Mike |
|
| Back to top |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1028 Location: Manchester, UK
|
Posted: Wed Mar 08, 2006 12:15 pm Post subject: |
|
|
Good work!
I will be playing later  |
|
| Back to top |
|
 |
prolinuxfan
Joined: 17 Feb 2006 Posts: 21
|
Posted: Wed Mar 08, 2006 5:50 pm Post subject: |
|
|
I'm looking forward to this port too, since I have now received my DigiKey order for a couple of ATMega168 TQFP packages, and some various support chips.
With my current workload, it will probably be better than the next 2 weeks before I can get a PCB designed around that chip. Until then, between the ""Honey do"" lists and the work, I will be pretty scarce.
Good luck with the port, hope all the bugs go running scared  _________________ Allen
(My R2 *WILL* climb stairs when I'm done) |
|
| Back to top |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Wed Mar 08, 2006 10:41 pm Post subject: |
|
|
I completed the port of the ATmega8 and it passed the initial smoke testing. The nice thing is that the differences between the ATmega8 and the ATmega168 are isolated to adc.c and watchdog.c. All the other code should be portable between the two devices.
Because the Analog/Digital Conversion in the ATmega8 cannot be directly driven by a timer, I had to have the timer interrupt routines initiate the A/D conversion. Not as elegant as the other MCUs, but should work fine.
I guess it's time to start looking at what the PCB will look like for the TQFP packages for the ATmeg8 and ATmega168.
Some early details on the ATmega8/168 pinouts to the servo are:
| Code: |
ADC
AVCC - Pin 18 - ADC 5V reference
ADC0 (PC0) - Pin 23 - Power input
ADC1 (PC1) - Pin 24 - Position input
PWM
OC1A (PB1) - Pin 13 - Motor counter-clockwise output
OC1B (PB2) - Pin 14 - Motor clockwise output
TWI/I2C
SDA (PC4) - Pin 27 - TWI/I2C data
SCL (PC5) - Pin 28 - TWI/I2C clock
|
-Mike |
|
| Back to top |
|
 |
|