• 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.

atmega328p, assembly language, flex sensor issue.

Thread starter #1
has anyone worked with using flex sensors with the ADC of a 328p? I can't figure out the best way to hook this up and get the best range out of it. it varies from 10K-25+K ohms. I was pulling adc input from between a 50k ohm from 5v+ and my flex resistor down to ground. Its not like a potentiometer though so i am confused as to how to get the best adc result out. I see the data sheet says i should use an op amp as an impedance buffer I hooked it up the way it showed in the datasheet but my readings are still skewed. how can i take care of the issue in the programming or what is the best route to take? I need the adc to look at a range it seems like of +1.5v to +5v. Any help on previous experience with working with these to get best results would be appreciated
 

Pommie

Well-Known Member
Most Helpful Member
#2
You need to measure 10K to 25K with an ADC - is the ADC 5V?

I would try a constant current source. A 1mA constant current source will give a reading from 1V to 2.5V

Mike.
Edit, The 1mA figure is wrong. It should be 0.1mA.
 
Last edited:
Thread starter #3
You need to measure 10K to 25K with an ADC - is the ADC 5V?

I would try a constant current source. A 1mA constant current source will give a reading from 1V to 2.5V

Mike..
The ADC is setup to ref AVcc with it being connected to VCC which is 5v and its connected the way the data sheet shows it should be. How do I make a constant current source? the current varies as i adjust my sensor so how could I create a constant current source? sorry for the newbie questions.
 

Pommie

Well-Known Member
Most Helpful Member
#4
Something like this.
CCS.png
Note, I'm a digital guy, Maybe one of the more experienced analogue guys could comment.

In the above circuit the base is held at 3.3V by R2 and R3. This makes the emitter of Q1 4V so the voltage across R1 is 1V and the current 0.1mA. Resistor R4 is your sensor and the voltage at the top of R4 will be 1V to 2.5V.

Mike.
 
Thread starter #5
Something like this.
View attachment 116880
Note, I'm a digital guy, Maybe one of the more experienced analogue guys could comment.

In the above circuit the base is held at 3.3V by R2 and R3. This makes the emitter of Q1 4V so the voltage across R1 is 1V and the current 0.1mA. Resistor R4 is your sensor and the voltage at the top of R4 will be 1V to 2.5V.

Mike.
OK. So then would the input to my adc would be off the collector of the transistor and I would be able to vary the voltage from 1-2.5v at a constant current of 100ma? If the way I am looking at this correct and this would work, how do I go about getting my adc to read 0-255 out between the 1-2.5v input? how can I accomplish that in the program?
 

Pommie

Well-Known Member
Most Helpful Member
#6
This circuit should take the 1-2.5V input and convert it to 0.5V to 4.5V output.
Amp.png

Note, the op amp must be a rail to rail version. The only bits you need from this are the op amp and the three resistors. V1 and V2 are just to simulate it.

Mike.
 
Thread starter #7
Nice thanks. Ill give it a try after work. I think I have some lm358s which should be rail to rail op amps. I'll let you know my results later.
 
Thread starter #8
This circuit should take the 1-2.5V input and convert it to 0.5V to 4.5V output.
View attachment 116886

Note, the op amp must be a rail to rail version. The only bits you need from this are the op amp and the three resistors. V1 and V2 are just to simulate it.

Mike.
for not being an analog guy you have a good handle on this stuff. the circuit you gave me worked out great. I used a BC557 pnp and an lm358 and got .5mv to 4.34volt swing which is excellent. Thank you very much for your help.
 

Pommie

Well-Known Member
Most Helpful Member
#10
Is the .5mV a typo? It should be 0.5V to 4.5V. If it is correct, can you measure the resistance of the sensor when it is 0.5mV?

Mike.
 
Thread starter #11
Sorry no it is 500mv. Or .5v my fault. One more question though. How can i figure out what the output impedance of the op amp would be? Is it the resistance seen on the non inverting input or how can i calculate that impedance?
 

Pommie

Well-Known Member
Most Helpful Member
#12
According to the data sheet the output impedance is 300Ω. The feedback resistor will increase this slightly. If you're only feeding an ADC then it should be fine. Again, not an analogue guy but think this is correct.

Mike.
 
Thread starter #13
What kind of circuit is that called? Is that considered a single ended no inverting feedback amp? (trying to find some definitive information about on the internet but can't find this type of circuit being described. I want to understand the math behind how it is working so I can easily adapt it to other situations I might see. I know from looking about the internet that ideally there is no current on the amps inputs and that the amp is always going to try to balance the inputs by way of varying its output in order to either drive the inverting input (in the given circuit with feedback) higher or lower. but what is the math behind it or how does it work?
 

EE World Online Articles

Loading

 
Top