Solved

C code to read TTL levels

Posted on 2004-04-06
8
229 Views
Last Modified: 2010-04-01
Without going into too much unnecessary information here is my problem.  I have a circuit on a helicopter that i am trying hack into for an electronics project.  Specifically one PIC that i am interested in deals with the command signals to the motors, and i need to read this data to evaluate and decode.  A good way of doing this, or so i'm told, is to simply connect the PIC to a serial input and read the TTL levels, (which are 0V - 5V).  I need a program that will read these levels and convert them to a useable format (1's and 0's) and have been trying to find something on the web, can anyone help?
0
Comment
Question by:Stupot
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 16

Expert Comment

by:George Tokas
ID: 10765470
PIC is a microcontroler.
That means there is a software inside it to perform some actions.
If you take my advice as electronic engineer also, don't try to hack it.
If it is not protected (I mean at programming phase) then you can get the code from inside the PIC and with dissasembly you can see the program and modify it yourself.

Regards,
gtokas.
0
 

Author Comment

by:Stupot
ID: 10765659
That would be ideal, but unfortunately the helicopter is fairly revolutionary in its design and the manufacturers have gone to some lengths to ensure that it cannot be reverse engineered that easily (Like scratching off part numbers e.t.c).  Also it's quite expensive (and not mine), so i can't really take the PIC off the circuit to access the code inside.  Also it's probably been protected, though i haven't checked, but the company are reluctant to give any information regarding the circuitry.
0
 
LVL 44

Assisted Solution

by:Karl Heinz Kremer
Karl Heinz Kremer earned 75 total points
ID: 10767106
The serial port does not use 0/5V signal levels, so you would not be able to use it directly. A better choice is the parallel port, it uses the same signal level as your device.
What operating system are we talking about?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Stupot
ID: 10774994
I will probably use windows, but have the option to use linux if preferrable.
Also, the person who mentioned the idea suggested using the C functions 'inport' and 'outport'.
0
 

Accepted Solution

by:
Jay_Harbath earned 150 total points
ID: 10777834
The hardware way to do this is to use a logic analyzer that clips onto the PIC package and monitors and records all the PIC I/O   Unfortunately that will result in a huge data log of square waves.  You then have to figure out enough of the schematic to understand which control outputs from the PIC are going to the motor control circuitry and which inputs to the PIC come from motor feedback circuitry.  Once you know which pin does what, then you get the exhaustive and exhausting process of trying to determine what algorithm the PIC programmer used to read the inputs and control the outputs.  A nasty, dirty, mind numbing job to say the least.  

The software way would be to remove the PIC from the board, put it into a PIC programmer and attempt to read out the hexadecimal machine code.  This assumes that that particular chip does not have some sort of program security feature that prevents someone (like you) from reading out the program after the chip has been programmed.  Many microcontroller manufacturers have hardware program protection features that can be set after a chip has been programmed and verified.  I use them all the time.  Now, given that the company programming the PIC did not use any sort of program protection, all you will get is a hex file of the contents of the program memory.  You then need a disassembler that can convert the machine code into very, very raw assembly language.  You still need to understand the schematic with this approach, because you will have to understand which control outputs from the PIC are going to the motor control circuitry and which inputs to the PIC come from motor feedback circuitry.  With this information, you can start trying to understand the raw assembly language program and start guessing at variable names for memory locations and I/O pin assignments.  After extremely long hours (days, months) of effort, you might come up with some semblance of a commented assembly language program with a glimmering of the algorithm the original engineer used.  Mind you, this will only be an assembly language equivalent.  It is very likely that the engineer programmed most if not all of the application in C, but no disassembler in the world can go from machine code to C.  Considering how C compilers optimize, you won’t even find one that can convert assembly language back into C.  

To do what it sounds like you want to do will take thousands of dollars of equipment (logic analyzers or PIC programmers) and months of very hard work and lots of knowledge of electronics.  Reverse engineering embedded control applications takes courage, perseverance, and stupidity to make the attempt, strong motivation and very, very deep pockets.  
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10778579
If you are willing to use Linux, take a look at this project: http://vodka.tky.hut.fi/~jap/Programming/Slogan/
This is a simple logic analyzer that reads eight input channels (the eight data lines of the parallel port). You don't need any special hardware, just the software and the connector.
0
 
LVL 16

Assisted Solution

by:George Tokas
George Tokas earned 75 total points
ID: 10783353
Jay_Harbath put it the right way.
Even if you read the PIC using a programmer if it is protected then the data you will have will be garbage.
For me i.e. if I needed to I will take a look at the circuitry to have an idea of how it is implemented and then I will make a new one of my own.
Anyway the control data from remote controls have a standard protocol.
Jay_Harbath you must be on the same field with me.
Check out my details and contact me if you like.
Regards,
gtokas.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question