Scratch building altimeters

The Rocketry Forum

Help Support The Rocketry Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

ghost

Well-Known Member
Joined
Aug 1, 2011
Messages
900
Reaction score
1
Any suggestions/tutorials?
I know how to solder, but I'm trying (and so far failing) to learn PIC programming.
For now, is there a simple tutorial to scratch build an altimeter (just to record max. altitude).

Also, back on the topic of PIC programming, why does it seem so complicated. I've gotten a couple of books, and they all talk about weird binary programming. Why can't you simply say something like "If there is current coming from port A, send current to port B?"
Am I missing something? :confused:

THANKS!!!!!! :D
 
Originally posted by ghost

Also, back on the topic of PIC programming, why does it seem so complicated. I've gotten a couple of books, and they all talk about weird binary programming. Why can't you simply say something like "If there is current coming from port A, send current to port B?"
Am I missing something? :confused:

Wow, I remember IBM card deck programming in college and moving to an Intel 8049 compiler at my first job. I thought I'd died and gone to heaven. At that time you didn't do programming unless you could do binary calculations.

Geez, these youngsters have it too easy these days!!!
 
Actually, I don't know how to program PICs the simplified way. :(

Any advice? :confused:

BTW, I sorta do want to learn binary programming. I know Java very well, and I think it would be cool to learn how to program w/ binary.
 
Originally posted by ghost
Actually, I don't know how to program PICs the simplified way. :(

Any advice? :confused:

BTW, I sorta do want to learn binary programming. I know Java very well, and I think it would be cool to learn how to program w/ binary.

You want to program in assembly language rather than binary, I suspect, though I think Microchip might offer a free C compiler for some of their PIC products. I would poke around on the microchip website and see if they've got a tutorial. Unfortunately it's been many moons since I did PIC programming (and was the lab TA for the PIC class at GT), so I don't have any good book recommendations. I suspect there are several good ones out there though.

You have to sort of turn your brain sideways to get good at writing PIC assembly code, since they've got the funny instruction word that can only specify 2 registers rather than the usual 3 (A = A + B, for instance, isntead of A = B + C). Once you've got it turned appropriately though it all clicks and you'll start banging out code!

-Rick
 
I ditched PICs a while ago. The assembly sucks, and only a few of their upper-tier controllers support C compilers. I'm all about AVRs now. The assembly language is powerful by itself (120-135 instructions as opposed to 35) and they have incredible support for C and C++. I program in assembly, but if you know Java well then jumping to C shouldn't be too hard. They're cheap too.
 
I have programmed in PIC Assembly for 10 years now. Be careful about saying something "sucks". I find the limited number of instructions refreshing compared to the CISC environment I programed in during the CPM days (I long for the days when one could write their own BIOS in 16K, this Windows stuff just ties me up in knots). As to tutorials and such, start with one of the sample programs on the microchip website with a simple breadboard circuit. The IDE environment isn't perfect but it does work. What sort of programmer are you using and what is your target chip?
 
Hi :)

I too have used PIC's for at least 6 years now. I found the assembler a bit hard to begin with but easy enough to pick up.
Im self taught so it can't have been too hard! :)

Something to look at if you want to play around is PicBasic Lite (I think thats what its called...)

You program in Basic which is very easy, and it complies your code in assembler code ready to program.
Though the lite version is fairly limited, it does allow you to get your head around micro's pretty well, and you can purchase the full version if you fall in love ;) (Or just move on to assembler...)

Have fun!
 
Originally posted by ghost
Any suggestions/tutorials?
I know how to solder, but I'm trying (and so far failing) to learn PIC programming.
For now, is there a simple tutorial to scratch build an altimeter (just to record max. altitude).

Here's mine:

https://reality.sgiweb.org/overby/rockets/Simple_Altimeter/index.html

There are a lot of these sorts of projects on the web.

I don't think the PIC assembly is any weirder than any other microprocessor. The only microprocessor I've used that could do memory-to-memory addressing was the PDP-11 (I was on an LSI-11/23 so I'll twist terms a little bit and call it a microprocessor -- I could lift the computer by myself).

I found that life was too short to spend writing PIC assembly code, so I switched to C and at the same time switched to the Atmel AVR series. For my next device (combined pressure & accelerometer), I plan to use a MegaAVR 168.

Glen
 
AVR's are nice - I have a little robot that uses them, and they are really easy to use. I program it in basic with Bascom AVR as a compiler.
 
I just started with microcontrollers last summer, and I had a successful project on my first try without a lot of headaches, using Zilog microcontrollers. When I was researching microcontrollers on Digi-key you could get a basic stamp microcontroller for $$ per controller, or use a much cheaper microcontroller like a PIC or ATMEL and program it in assembly, or get a C library and compiler to go with it for hundreds of dollars. But Zilog offers a development kit, including a PC interface, C library and a complete integrated development environment, for $40. The debugging is on-chip, so you can debug and get insight into all the variables and registers with the microcontroller when it's in your final board. The XP series also has a 13-bit A/D, differential inputs, internal voltage reference, input buffering, a separate op-amp, and a temperature sensor, so you can do all your analog conditioning and even temperature compensation with little or no external components, for about $4.00 per part.
 
Originally posted by Adrian A
or get a C library and compiler to go with it for hundreds of dollars.
I never paid a cent for my C compilers or libraries. I'm not sure about microchip, but I've there's a ton of free Atmel compilers and libraries sitting out there. The only thing I ever paid for was an STK500 (79$) to program them with. In hindsight, I could have settled for a homebrew programmer for much less.
But Zilog offers a development kit, including a PC interface, C library and a complete integrated development environment, for $40. The debugging is on-chip, so you can debug and get insight into all the variables and registers with the microcontroller when it's in your final board. The XP series also has a 13-bit A/D, differential inputs, internal voltage reference, input buffering, a separate op-amp, and a temperature sensor, so you can do all your analog conditioning and even temperature compensation with little or no external components, for about $4.00 per part.
That sounds cool. When you say debugging is on chip, do you mean it has a built in JTAG type debugger that lets you set break points, step through code, and look up registers?
 
Originally posted by Adrian A
I just started with microcontrollers last summer, and I had a successful project on my first try without a lot of headaches, using Zilog microcontrollers. When I was researching microcontrollers on Digi-key you could get a basic stamp microcontroller for $$ per controller, or use a much cheaper microcontroller like a PIC or ATMEL and program it in assembly, or get a C library and compiler to go with it for hundreds of dollars. But Zilog offers a development kit, including a PC interface, C library and a complete integrated development environment, for $40. The debugging is on-chip, so you can debug and get insight into all the variables and registers with the microcontroller when it's in your final board. The XP series also has a 13-bit A/D, differential inputs, internal voltage reference, input buffering, a separate op-amp, and a temperature sensor, so you can do all your analog conditioning and even temperature compensation with little or no external components, for about $4.00 per part.

Wow, the Zilog XP Encore line is very nice and the development kit has a lot going for it.

However I think for most hobbiest DIY altimeter projects the MCU is usually not the limiting factor and other things take priority like:

1. What system am I used to or have used before? It is common for people to select the mcu family they used in thier last project for their new project. Here PIC and AVR have the advantage just because of human inertia.

2. Don't reinvent the wheel syndrome. How many code snippets are out there that I can use (steal) for the common trivial tasks (ie math, I2C, table lookups etc). It is much faster and reliable to use existing solutions than to write and debug everything from scratch. Again advantage to PIC and AVR as there is a lot of code for the taking on the web. Of course this is more important if you are programming in assembly.

So I guess my point is you go with the system that you are most comfortable working in. The MCU choice is not going to be the make or break factor in your altimeter performance. Rather the electrical design, concept and code will be.
 
Here's a free C compiler for PICs that I've been using for many years:
https://www.bknd.com/cc5x/index.shtml

You can use the CC5X compiler as part of the MPLAB IDE (free from PIC). The limitation of the free CC5E compiler is 1K of code, which is plenty for most hobby projects. If you go over that, you can hack things to link together, or buy it.

There are quite a few example online if you google around for them. Start by blinking an LED on a port, then reading an A/D and using that value to change the blink rate. Stuff like that.

When I taught EE labs, Robotics, and EE/CE Senior Design at Syracuse U., quite a few of my students found PICs easy to use.

Like any other low-level programming, you'll have to get comfortable with twiddling bits and talking with the hardware. I'm also a Java programmer, but that uses a completely different side of my brain. ;)

-John
 
The Zilogs look very similar to AVRs, except for a few key features. The biggest is obviously the on-chip debugger, which is great for low-production hobbyists who don't want to spill several hundred dollars for a JTAG interface. I like the fact that they have two 16 bit counters and they support multiplication instructions.

I can't find anything about 13-bit ADCs though.
 
I could never get my PIC programmer circuit to work (I might buy the PIC development board/programmer). The ZiLOG kit looks very nice, and the chips are more powerful than PICs for about the same price.
 
-----------
I can't find anything about 13-bit ADCs though.
-----------

from pages 122 and 123 of the design specification:

"Data Format - In both SINGLE-ENDED and DIFFERENTIAL modes, the effective output of the ADC is an 11- bit, signed, two’s complement digital value. In DIFFERENTIAL mode, the ADC can output values across the entire 11-bit range, from -1024 to +1023. In SINGLE-ENDED mode, the output generally ranges from 0 to +1023, but offset errors can cause small negative values.
The ADC registers actually return 13 bits of data, but the two LSBs are intended for compensation use only. When the software compensation routine is performed on the 13 bit raw ADC value, two bits of resolution are lost because of a rounding error. As a result, the final value is an 11- bit number."
 
mtwieg, good info on the free compilers. Free is good. Yes, one of the pins connects to the programmer interface, which also handles the in-circuit debugging. You can set one or breakpoints in the code, hit the icon to download and run your code on the chip, and then it will halt at your spot(s), at which point you can see the value of any of the registers or your own variables, including arrays in hierarchical format, and in your choice of hex or decimal. If I recall correctly you can write to registers, also, though I've never found a need to do that.

jderimig, I agree, if I already had programmed PICS or ATMELs, I would probably stick with that. But since I was starting fresh, (like ghost appears to be) I was happy to go with Zilog because its development kit was such a good value, I wanted to use a higher-level language, and the features, price, and performance of the MCUs themselves were competitive. Math is part of the C package, as are lookup tables, and an I2C interface is in the Zilog website library, for the Zilog MCUs that have an I2C peripheral (not the XP series. :( , but they do post code for SPI). I know PICs have a huge following and I'm sure there's lots of good code out there for doing a variety of tasks. I have found the Zilog library to be helpful and to have code examples for most of the MCU features and interfaces. And of course, there's a ton of C code out there for other functions not specific to MCUs. I also like to use the XP series features to reduce the parts count and therefore the number of things I might screw up in the analog signal conditioning.

mtwieg and Guy,
The 13-bit functionality for the A/D is definitely there, and I've used it with success. In my last project I was making a controller to balance 8 li-ion cells, and I had a very simple voltage divider for the whole battery stack that made those extra 2 bits really come in handy. I started with their example code that loses the 2 bits of precision, and later I modified the code to just multiply the 13-bit register output by a scale factor that was large enough to preserve all of the precision when I right-shifted the resulting bits to get the voltage values in mV. I can dig up plots of the before and after voltage traces if you're interested, where you can clearly see the jaggies go away in the 13-bit version.
I don't know why they downplay the capability the way they do the in the spec. I ran across a similar thing where in the version of the spec they had last summer, they describe how the differential amp can be used in a 20x mode, but in the current version, they removed references to that feature in and even labeled the register bits that controlled it "reserved." I never used that feature myself, so perhaps they had gotten complaints that it wasn't working well enough, but that's definitely not my experience with the 13-bit A/D. If someone wants to try out the 20x differential input feature (for a resistor bridge pressure transducer interface without external components, for example), I'll post an excerpt from the older version of the documentation.
 
Back
Top