Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me understand C code of PC-based oscilloscope

Status
Not open for further replies.

aibelectronics

Member level 2
Joined
Aug 8, 2005
Messages
48
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,841
is this code feasible:
float scale=1;....
c=c*0.0196*45/scale; ?
Now c is an array that accepts inputs (1's and 0's) from interfaced hardware and 0.0196 is a real decimal number. Won't there be a type conflict on multiplication?
 

Re: c code

With this expression your code will only multiply 1's and 0's with 0.0196, and will give 0 or 0.0196. 0.0196 will be translated to type of c that is (i suppose) unsigned char and you'll always have 0 as result.
First you have to translate input 1's and 0's to decimal number and than you can multiply it with 0.0196.
This way if you have 1,0,0,1,0,1,1,1 you must translate it to c=10010111 and later you can multiply it with 0.0196, but first you must make typecast of c that now is char, to float:

unsigned char c;
float m;

m=(float) c;
m=m * 0.0196;
 

c code

Aibelectronics: You haven't told us what type variable is "c". I'm guessing it is some integer or real type. If that's true, then your answers are "YES" and "NO".

C will automatically promote "c" to a double prior to multiplication with 0.0196, and then automatically convert the product to the type of "c" prior to assignment. There are a couple of unlikely exceptions, so please tell us what type variable is "c"?
 

Re: c code

echo47:
I think that aibelectronics wants input stream of bits to multiply with 0.0198 as number and not as bit multiplied with decimal, since there is no sense multiplying 1 or 0 with 0.0196.
? aibelectronics ? what do you want your code to do ????
 

Re: c code

the code comes from a project: PC Based Oscilloscope (see electronicsforu.com).

c is an array and is of type integer. It obtains its inputs from connected hardware such that the analog signal can be displayed on the PC screen. 0.0196 is the resolution for the ADC used in the conversion process. So you see c is an array of 1's and 0's essentially.

Could the code be wrong?
 

Re: c code

c is a vector of type integer. So whatever value you assign to it will be converted into an integer (although I've forgotten if the process would be truncation or rounding). For example, if c=1, then c=c*0.196 may give you c=0.
 

Re: c code

Since 0.0196<0.5 c will allways be 0.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top