Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A-to-D

Status
Not open for further replies.
Pommie said:
or better still, if your using PICC lite
while(ADGO)

As a matter of personal pref I would definitely go with a test for ADIF instead of GODONE. Even if you don't have interrupts enabled, the flag will still be set.

Also when testing bits, instead of
Code:
if(myVar & 0b00000100 ==0b00000100)

you might use
Code:
if(myVar & 0b00000100 != 0b0)

which keeps you from having to screw around with twice as many arbitrary numbers written into the code.
 
Oznog said:
As a matter of personal pref I would definitely go with a test for ADIF instead of GODONE. Even if you don't have interrupts enabled, the flag will still be set.

Why do you prefer this method? The GoDone test will always work and so would be my preferred way, the ADIF bit could get cleared by an interrupt. The data sheet suggests using the GoDone bit if interrupts are disabled. Also, if you test the ADIF bit then you have to have an additional instruction to clear it.

Oznog said:
Also when testing bits, instead of
Code:
if(myVar & 0b00000100 ==0b00000100)

you might use
Code:
if(myVar & 0b00000100 != 0b0)

which keeps you from having to screw around with twice as many arbitrary numbers written into the code.

I believe that I suggested exactly that.

Mike.
 
I thinik the two bit test versions suggested by Oznog might compile into different assembly codes depending on the compiler.

I read somewhere that there is a big difference in writing a simple FOR loop in C in which one increment a variable and checks that it has reach say 100, to a loop when one initiate the variable with value 100 and decrement it to zero.

Code:
for (i = 1; i <= 100; i++);

for (i=100; i>0; i--);


The differences is in number of program words generated by the assembler and the number of cycles used up by the PIC to run the loop.
 
eblc, the answer to your original question is yes.

It's still better when using PICC to use

while(ADGO);

or

while(!ADGO);

As this generates code that uses the bit instructions and is therefore much more efficient.

Mike.
 
Probably a terrible question!

Hi all,

This is going to sounds very silly I guess, but I'm really trying to learn. I'm having some problems with my A/D, and in numerous places an incorrect input impedance is suggested.

I'd like to check this for one of my sensors (this is an ultrasonic transmitter/reciever circuit which gives an output within the 0-5V range). The thing is, I don't understand impedance and how to measure it on the single wire heading into my PIC. Is this just the resistance between my ground and the signal wire? Or am I being very thick!?

:oops: :oops:

Thanks,
Matt
 
Hi, thanks for your prompt reply.

I've been given a talking to and I've calculated that the impedance is about a couple of k. So this should be ok. I've got a 3.9k, 10k and 15k effectively in parallel after the main circuit (which is pretty big, oscillator,reciever,sum&difference multiplier and differential amp).

The main problem is that the A/D seems to sample for a short period of time, and then stop. The it seems to stop when there's a large change in values.

Similar potential divider sensors such as my LDR and thermistors run for a good while, but the ultrasonic cicuit mentioned above seems to stop after just a couple of seconds.

I'm debugging by displaying the values on an LCD, and it just holds the last value, and needs the development boards reset button to be pressed before it goes again.

Matt
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top