# atmega328p, assembly language, flex sensor issue.

Status
Not open for further replies.

#### digione

##### New Member

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

Something like this. 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.

• digione
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?

This circuit should take the 1-2.5V input and convert it to 0.5V to 4.5V output. 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.

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

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.

Good to hear a successful conclusion.

Mike.

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

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?

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.

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?

It's kind of a cross between a basic non-inverting amp, and a summing amp.

A non-inverting amp would not have R1. The gain is 1+R5/R2 (using the designators in post 6)
A summing amp generally has two or more signals into the inverting input, and the non-inverting input at gnd.

This circuit has two voltages into the inverting input, 0 and +5V, that get scaled differently due to the different resistors R2 and R1. Then a third voltage comes in to the non-inverting pin. See the link below for more on summing amps. 