About this Blog

This blog is an engineering log book; for me to record the progress on my many projects and hopefully to inspire you.

Some projects do not get off the ground, they remain as interesting thoughts, a select few get some work done on them, even fewer get close to completion, and none get completed because unfortunately I subscribe to the theory: "If something ain't broke then it doesn't have enough features". If you'd like to collaborate on some work to get something to a useable state then send me some communications.

Being a blog, posts are listed in chronological order. However I usually have multiple projects on the go and will try to post some of my earlier work. With this in mind I'll try to add labels to each post so all posts relevant to one project can be easily extracted.

Enjoy and happy hacking.

Wednesday, October 15, 2008

Waving Hello World

We have servo action as can be seen in the video above. I have written some code to read the ADC, calculate a PID control and provide a PWM signal to the motor. This all comes together to move the position read by the ADC to the set-point, which is moved backwards and forwards to make the servo wave. This is all done with 8-bit integers, however the ADC gives a 10-bit result, so next task will be to make it work with 16-bit integers - giving it 4-times the accuracy.

I've had a few hiccups along the way.
The first was a problem with the piklab-prog program that loads the PIC through the ICD2 programmer. In short it was writing the contents of the last memory address 0x3FF(the oscillator calibration word) back to the memory location 0xFF, overwriting what was there. So I filed a bug report and reluctantly moved development to a windows machine.

The second is choosing a C compiler for the PIC. Hitech is a commertial compiler company that write compilers for the PIC. They seem like they should work well. They provide a free compiler PICC lite, but this doesn't do any optimisation - you have to pay for that. Buy you can use a 45 day trial of the optimisang standard version PICC std. It is also available for linux which is nice.

Third problem is one that had me bamboozled for a couple of days. I was working on the PWM H-bridge control. The left side is controlled by one GPIO1 and the right by GPIO2. The motor would spin fine in one direction but not in the other and causing the MOSFETS to heat up quickly. Having a look at the signals on an oscilloscope revealed that when GPIO1 was written high, it would go high for one instruction cycle but not stay high. This had the effect of making the mosfet switch on and off very quickly and hence the heat. After talking to Phil at uni he suggested that I was writing to the second pin too quickly (which I was - in the next instruction in fact). The problem is that the PIC operates with a read of the port, modification of the pins, and a write back. The read of the next instruction occurs just after the write of the last instruction. The write is delayed by the capcitance on the pin or other factors so the read of the port (which read the values of the pins) got the wrong value (one without the recently modified pin). This is called a RAW (Read after Write) hazard. To fix this you need to do something in between or modify both at the same time.

And finally I'll end with the question of using a sigma-delta modulated output for control? Since the PWM at best runs at only 100Hz, not giving very precise control of the motor, maybe a sigma-delta type control would be better. It would have a "variable frequency" higher than 100Hz, fast response to a change in the servo position. It would also be smoother on the powersupply with several servos on the same bus with synchronised PWM.