Friday, February 11, 2011

New Computer in My Hands!

Just got my new computer up and running. Sure flies!  I really got lucky here!

My old laptop, an HP D9000, took ill and died.  That is, it died from a voltage surge.  Ok, ok, it took 120VAC into the USB port. Not good. I was able to get it to start once long enough to copy the files from the hard drive to my USB drive. Then after that, no more hard disc. I could boot with Linux on a jump drive or CD but that was it.  Anyway, I use this as my system computer for my ham radio setup. Luckily I have a special insurance policy on my ham radio which also covers my computer. After getting repair estimates and sending all the pertinent information in, HRIA cut me a check to cover it, and here is my new Dell.  Naturally it cost less than half what the other one cost but that isn't important. I (and more importantly my wife, Lori) am back on line. And this thing is cool. 17" screen, 4G Ram, 500G HD, running Windows 7.  Awesome.

Wednesday, February 9, 2011

I've had an Epiphany!

I am working through John Morton's book, "The PIC Microcontroller, Your Personal Introductory Course" and so far all has been going well.  A quick history is that I have always been into electronics, have a BS in Computer Science, work for an electronics company in Tech Support and their display program as well.

I did some Assembly Language programming on a VAX 11-750 in college, but stayed mostly with 'C' since then. I came across several projects that required programming a PIC micro controller with Assembly.  While the code was already written and compiled, I wanted to learn it on my own.  Taking code and modifying it for a project was fun. I built a rocket that will carry a transmitter and send telemetry data to me in Morse Code (CW to my Ham friends) on ham radio frequencies. I can send it slow enough that I can copy it myself, or speed it up so my computer will have to decode it. But I digress. 

I was surfing through some projects on YouTube and saw an LED cube project. The source code was there as well as the hex code to program the microcontroller. I got to playing with it and wanted to learn more.  Wow, basically 35 instructions and I'd have the Assembly language code down for the PIC!

Going through this book I have learned a lot. It is slick, and I even impress myself with how much I remember from college about binary, hex, etc.  Even at 45 I am picking it up quickly. My end goal is to build a little robot that will follow a black line or be autonomous and avoid obstacles with sonar.  I want to program this with Assembly. I have seen a lot of 'C' code but I find this a challenge. Some of the inputs will be from a sonar unit. This will be an analog signal. The inputs I have been dealing with are digital. So on to the section of the book regarding A/D conversion.

I have read this numerous times and have been extremely lost. I looked at example code from other sources but to no avail.  This morning it hit me as I looked over it one more time... HEX code AND Binary.... HMMM!!!

Here is what I feel has been my greatest epiphany this week:

The example in the book talks about taking advantage of the full 10-bit precision of the A/D converter which is spread over ADRESH and ADRESL.  The example was input from a temperature sensor.  36deg C was 0.36V, which when divided by 5V gives 0.072.  This gets multiplied by 1024 to get the 10-bit value for the cold threshold and is written d'74'.  This is written in binary as 0001001010000000.  Now in writing this, bits 0:1 of the A/D result are in ADRESL bits 6:7, and 2:9 of the A/D result are in ADRESH.  I understand this. But then he went on to say, "Thus, the upper byte is (0x12) and the lower byte is (0x80)."

This was the first time this notation was used in the book, and actually even doing a Google search didn't explain a lot until I got into some information regarding hexadecimal. BINGO.

The binary number 0001001010000000 can be written as 0001 0010 1000 0000.  SO... the upper byte (ADRESH) would be (0001 which is 1 in hex)(0010 which is 2 in hex) giving 0x12.  The same for the lower byte 0x80... 1000 is 8 and 0000 is 0 giving 0x80.

EUREKA!  A/D programming is slowly becoming a reality!  Results will be used to control speed/direction of the wheel motors on my little robot.  Sweet!

I love the feeling when a plan comes together.  Bear with me as I move along thru this book on my journey through microcontroller assembly language! I'll definitely post the robot pics here.