Omega HH506RA Serial Protocol

Today I had to figure out how to read temperature from an Omega HH506RA thermocouple signal conditioner/datalogger. The HH506RA is a nice little unit that reads temperature from two thermocouples (type K, J, N, T, R, S, or E). It can display the temperature on its LCD screen and communicate them to a PC over RS232 or USB. The PC connection is optically isolated, which is very nice because RS232 and USB are both notorious for causing noise problems via ground loops.

I’ve put information on how to communicate with the unit up here for future reference.

Read the rest of this entry »

No Comments

Watch out for compiler bugs related to volatile variables

At my new job, I’ve been diving back into embedded software development. During my time as an industrial automation application engineer, I stopped working quite as close to the hardware. It’s definitely fun to be digging around in registers and assembly code again.

I came across this article called on Embedded.com called “When good compilers go bad, or What you see is not what you execute“. I talks about all kinds of ways that compilers can end up generating incorrect (or sometimes technically correct but unexpected) source code. I’ve got a rule of thumb when debugging that in that vast majority of cases “you didn’t discover a bug in the compiler/operating system”. It’s good to keep in mind that that isn’t always the case.

One reference that especially caught my eye was to a paper titled “Volatiles Are Miscompiled, and What to Do about It“. They looked at 13 different C compilers and found out that all thirteen of them had issues with volatile variables.

Volatile variables are very frequently used in the embedded world. Memory-mapped hardware registers (used to read digital and analog inputs for example) are often accessed via volatile pointers in C. The volatile qualifier tells the C compiler “this variable could change at any time, so every time I ask you to read or write it, I really mean it!”

The authors of the paper found that every single compiler they tested failed to correctly implement the volatile qualifier in at least a few of their test cases. However, there are a few things you can do to help protect yourself:

  • Don’t turn on optimization. They couldn’t prove it, but they’re pretty sure that all (and definitely most) of these kinds of bugs are caused by the compiler’s optimizer.
  • Wrap uses of volatile variables in function calls. Because functions are (obviously) used way more than volatile variables, there tend to be very few bugs related to incorrect optimizations of function calls. Hiding volatile accesses in function calls makes it much less likely the access to a volatile variable will get optimized away (assuming the function isn’t inlined).
  • Don’t use volatile variables for inter-thread communication, use semaphores instead. This one deserves a post all of its own.
  • When the code just absolutely has to work, verify the assembly or machine code your compiler produces by hand.

One thing I really liked about the paper is that they used valgrind to help automate their testing. When I’ve run into some really tough to debug memory and pointer issues, valgrind has always been a huge help. I wish it were easier to use it in embedded programming projects.

No Comments

Definitely in favor of padded shorts

I got some padded shorts last week, which was definitely a good move. Things were already painful enough last weekend after a 39 mile ride. This week I went for 45 miles on the same route and felt pretty good through the whole thing. Well, I felt like I was going to keel over and die after 40 miles, but at least my ass wasn’t in pain too.

The stats: 45 miles, average speed 13.1 mph (half a mph better than on last week’s 39 mile ride!), max speed 27.6 mph again (downhill of course), riding time 3h23, total time something like 4 hours.

Once you get off the bike path, people get a lot friendlier. I got a bunch of nods from other cyclists biking around Carlisle. While struggling my way up at 8-9 mph what the CRW site describes as a “mild rolling” hill I even got a big smile and a wave.

Click more for the map.

Read the rest of this entry »

No Comments

More bicycle physics

A moving bicycle without a rider is asymptotically stable. The best way to explain it is to just watch the movie below. Shoving a moving bicycle will cause it to oscillate back and forth, but it’ll eventually find its way back to its stable upright orientation. No deep insight, just something that’s kinda cool.







There’s all kinds of bicycle related physics here.

1 Comment

Maybe there’s something to this fitness thing after all

Just finishes doing the Minuteman Trail again, and in my best time ever. The first time I did a full round trip on the trail, it took me two hours and five minutes. Today I worked really hard and pushing as hard as possible on the uphill sections and did it in 1h48. That three and a half hour ride last weekend with a bunch of steep hills probably didn’t hurt either.

Also, did you know that to turn right on a bicycle (or motorcycle) you actually briefly turn the front wheel to the left? Steering left causes you and the bicycle to lean to the right, which then makes you turn right. This is called countersteering. You don’t even notice it at slow speeds because it happens automatically, but word is that it can save your life at high speeds.

No Comments

Getting Better

I haven’t been cycling as much as I’d like lately because I’ve been traveling a lot and the weather has been pretty rainy. I started up again this week with the goal of getting past 25 miles.

I did my usual route along the Minuteman trail, but kept going when I got to the end (after a 2-3 minute break). There’s a cycling club called the Cambridge River Wheelmen that does some group rides in the Carlisle/Concord/Chelmsford area, so I just used one of their routes once I got to the end of the Minuteman.

One of the plusses of riding on rail trails is that they were designed for trains so they have nice and low grades. Roads are a different story. There were times when I was crawling up hills at 7 or 8 mph. On the brighter side flying down the hills at 30 mph is lots of fun.

Anyway, I ended up doing 39 miles in 3.5 hours (3 hours of pedaling) at an average speed of 12.6 mph. Next goal: 50 mile ride. Other goal: Pedal faster.

Map after the jump.

Read the rest of this entry »

, ,

No Comments

Minuteman: Did it again

I made it to the end of the Minuteman trail again. Looks like I need to find a new goal for myself. It would be nice if I could do this in under two hours.


View Larger Map

No Comments

Made it!

I made it to the end of the Minuteman trail today. 24 miles in just over 2 hours.


View Bike Route 2009-07-03 in a larger map

No Comments

Cycling

I decided to take up cycling. After looking fruitlessly on Craigslist for a few months, I splurged and bought myself a bike. It’s a 2009 Gary Fisher Wingra. Hopefully I keep up the motivation to get $600 (once you include accessories) out of this guy.

Sure there’s a nice picture of the bike on the Gary Fisher website, but the crappy low-light iPhone picture proves it’s my bike.

My new bicycle, a 2009 Gary Fisher Wingra

My new bicycle, a 2009 Gary Fisher Wingra

No Comments

The return

The return to France wasn’t bad, with a few exceptions. I took the Eurostar (Italian high speed train) from Rome to Milan. While the other Italian trains are pretty sucky, the Eurostars are nice. A lot nicer than the TGV, but then the supplement is 12 euros instead of 3. While I was waiting for the train to leave, a guy came up to me and asked if this was second class. I said yes, then asked if he had a reservation (reservations are always required on high-speed trains, while on most trains your ticket kets you just get on any train you want). He said no, so I tried to explain that he needed one because it was a Eurostar. He started saying no that couldn’t be right, at which point I reached the end of my Italian. So the other people tried to explain it to him too, but he still wouldn’t believe them. They managed to convince him to go talk to the conductor (the train had left at this point), so thanks to us he avoided a big fine, but he was still pissed off he had to pay the supplement (a whopping 13.50 euros), and he never thanked us for saving him the fine. Jerk.

Anyway, I got into Milan, and promptly got crapped on by a pigeon, for the fourth time. The pigeons definitely saved the best for last. I was walking along, when I all of a sudden felt something wet hit my hair. I thought "Goddam, that’d better be water," then stuck my hand into my hair. "Fucking shit," I mumbled, followed by "Literally!" I went to find something to wipe it off, but for some reason when there’s pigeon shit in your hair and you suddenly feel it start to ooze onto your forehead and towards your eyes, it suddenly becomes very hard to remember the Italian word for napkin. So, I ended up just saying "Scusi!!" at a sandwich stand and pointing at my head like an idiot until the woman got a horried look on her face, shoved some napkins at me, and pointed me to the bathroom. I swear, the next time I come to Europe, I’ll be buying some arsenic and mixing it with some pigeon feed.

My train was 45 minutes late leaving Milan, and I had a 30 minute connection to make once it got to Karslruhe. Fortunately, the Germans made up a bunch of time once they took it over, because I ran out of credit on my cell-phone while trying to call Dan to figure out what I was going to have to do to make to Metz before noon if I missed my connection (I needed to get there before noon to take my suitcase back from the office in my dorm).

I made it Metz early Friday morning, got my suitcase, rented a room for a night, and promptly passed out (I think I had slept two hours the night before). I ended up just hanging out, catching up on the news, and writing in my travelogue all day because my feet were incredibly sore and I really didn’t feel like going anywhere else.

On Saturday, I headed to Strasbourg, and basically did more of the same. Everyone had been telling me to read The Da Vinci code, and since I didn’t have anything better to do, I went to the bookstore to buy it. I couldn’t find it except in large-print, so I ended up buying Angels and Demons, the book that came before it. I also got myself my last cheap trappist beer (some Chimay blue… quality stuff). The book turned out to be incredibly good. It had a good plot, and it was really cool because it was set mostly in Rome, so I had just been to a whole bunch of the places it described a few days earlier.

And now here I am, in the Paris airport, waiting for my flight to Atlanta. The airport actually has little desks with power outlets, so people with laptops can use them before getting on their flight without draining their batteries. I thought I was going to have to find an outlet somewhere and sit on the ground, and here I am with a desk and padded stool. Anyway, that’s pretty much everything. I have to go back and fill a bunch of holes in my travelogue, some of which I’ll do now and some of which I’ll probably do back in Atlanta. After I’ve let thing percolate in my head a bit, maybe there’ll even be some deep thoughts that no one cares about except for me.

No Comments