Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

741 op-amp: just for the craic

Post any examples or modules that you want to share here

741 op-amp: just for the craic

Postby Spogg » Wed Aug 26, 2015 4:02 pm

Hi all

This is really a bit of daftness I thought might amuse.

I re-created, as far as I could, the old 741 operational amplifier. Same pinouts!

There's some notes in the schematic. I was unable to get negative feedback to work in FS so my solution was different. Maybe someone could explain a bit more about feedback in FS; what you can and can't do and why...

Cheers

Spogg
Attachments
741 op-amp.fsm
Look! No soldering!
(118.77 KiB) Downloaded 1108 times
User avatar
Spogg
 
Posts: 3327
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England

Re: 741 op-amp: just for the craic

Postby KG_is_back » Wed Aug 26, 2015 8:30 pm

by negative feedback you mean something like this?
Attachments
negative feedback.fsm
(303 Bytes) Downloaded 1077 times
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: 741 op-amp: just for the craic

Postby Spogg » Thu Aug 27, 2015 8:19 am

Hey KG!

That's a very strange thing you made there!

Negative feedback around an opamp takes the output from the opamp and feeds a reduced version back into the inverting input. This sets the overall gain of the circuit. For an excellent reference see this link:

http://www.electronics-tutorials.ws/opamp/opamp_2.html
This is part of a large tutorial and the other pages look good.

Originally I wondered if Flowstone could realise this behaviour, just out of interest. There is no real practical advantage since all op amp circuits can be emulated in FS by other means.

For my initial experiment, which failed, I tried the schematic below. Every input in Flowstone appears to be a summing point, so if you connect a value of 10 and a value of -8 into an appropriate input the effect is the same as if you connected just a value of 2. In principle this is ideal for a virtual earth input for an op amp.
However, and this is where I came unstuck, the fedback value does not sum correctly into the inverting input so the output cannot be regulated by the feedback loop.

I'm not sure why this doesn't work so I tried various stuff out, all to no avail. I suspect it's due to the fact that analogue electronics relies on current whereas the "current" for Flowstone is actually code execution and the nature of such is very different. The components in Flowstone are only representative of hidden code.

Anyways, thanks for taking an interest!

By the way, your screen name: What are you back from? :D

Cheers

Spogg
Attachments
op-amp dev 1.fsm
This doesn't work!
(68.49 KiB) Downloaded 1075 times
User avatar
Spogg
 
Posts: 3327
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England

Re: 741 op-amp: just for the craic

Postby tulamide » Thu Aug 27, 2015 9:28 am

Spogg wrote:http://www.electronics-tutorials.ws/opamp/opamp_2.html
This is part of a large tutorial and the other pages look good.

I had a quick look and the important part was exactly as I assumed: 180° out of phase.

A signal still expresses voltage, but normalized. That's why you have a signal range of [-1, +1]. That's the negative and positive phase of the voltage (The number expresses V2/V1). Now inverting (bringing it 180° out of phase) that simply means multiplying by -1 (-1 * -1 = +1; -1 * +1 = -1, the same is true for all other possible values in between).

I don't know how much of the signal will be fed back, but that amount has to be multiplied by -1 to invert it.

For all other questions you might want to wait for others to reply.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2692
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: 741 op-amp: just for the craic

Postby Spogg » Thu Aug 27, 2015 12:32 pm

Thanks tulamide, I do appreciate your commenting.

In my last upload (my dev 1 attempt) I wrote the simple DSP code like a differential amplifier, which is what's inside an op amp. In this way the sign of values of the input is taken care of; the input difference could produce a positive or negative result. If the inverting input (-) is higher (i.e. more positive) than the non-inverting input then the output will be negative and the opposite is true.
In a real op amp the output can then be fed back to the inverting input to re-balance the input so the '-' input terminal is effectiveley zero (so called virtual earth), as long as the output doesn't need to exceed the power supply levels (in a real op amp this would be saturation or clipping).
If, on the other hand, you create positive feedback, i.e. a proportion of the output feeds back into the + input, you get a schmitt trigger where the hysteresis is determined by the amount of positve feedback. I haven't demonstrated that but I tried it and it didn't work either.
It seems the execution of code stops after 1 pass and why shouldn't it? Maybe one could create iterative code which checked for stability within defined limits but I can't do that, nor can I be bothered to try :lol:

My working op amp uses open-loop defined gain settings which we can only get away with in the unreal world of code and digital systems.

EDIT: The example below uses a differential "op amp". This creates the difference signal expected but if you apply feedback the results are not as expected...

Cheers

Spogg
Attachments
Differential op amp stream.fsm
Working but no feedback...
(370.96 KiB) Downloaded 1084 times
User avatar
Spogg
 
Posts: 3327
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England

Re: 741 op-amp: just for the craic

Postby martinvicanek » Thu Aug 27, 2015 3:11 pm

In the analog world, feedback is instantaneous, so you have
Code: Select all
out = gain*(in - feedback*out)

which you can solve for out
Code: Select all
out = in*gain/(1 + gain*feedback) = in/feedback

The second equality holds (approximately) for high gain.

This does not work in the digital world, because feedback has a one sample delay. (You can only compute the output from known input.) So you would have
Code: Select all
out = gain*(in - feedback*out1)

where out1 stands for the previous output. For high gain, this results in an unstable recursion, so your signal blows up.

The correct way to simuate delayless (= analog) feedback loops in digital is to resolve the loop gain beforehand.
User avatar
martinvicanek
 
Posts: 1322
Joined: Sat Jun 22, 2013 8:28 pm

Re: 741 op-amp: just for the craic

Postby Spogg » Thu Aug 27, 2015 6:37 pm

martinvicanek wrote:In the analog world, feedback is instantaneous, so you have
Code: Select all
out = gain*(in - feedback*out)

which you can solve for out
Code: Select all
out = in*gain/(1 + gain*feedback) = in/feedback

The second equality holds (approximately) for high gain.

This does not work in the digital world, because feedback has a one sample delay. (You can only compute the output from known input.) So you would have
Code: Select all
out = gain*(in - feedback*out1)

where out1 stands for the previous output. For high gain, this results in an unstable recursion, so your signal blows up.

The correct way to simuate delayless (= analog) feedback loops in digital is to resolve the loop gain beforehand.


I'm not 100% certain I understand your response but thanks anyway Martin!

By resolving the loop gain do you mean like my first upload where the gain is pre-set for both inputs?
I'm intrigued by the statement that "feedback has a one sample delay". If you can spare a moment I'd really appreciate it if you could elaborate on that a bit and maybe show me an example or a reference.
Possible the silent many who are reading this could also learn something...

Cheers

Spogg
User avatar
Spogg
 
Posts: 3327
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England

Re: 741 op-amp: just for the craic

Postby martinvicanek » Fri Aug 28, 2015 11:47 pm

Consider the analog non-inverting amp schematic below.
IMG_1457.JPG
IMG_1457.JPG (26.66 KiB) Viewed 31571 times
The system behavior is determined by the op amp free running gain and the feedback topology. Thus, the op amp output is given by
Code: Select all
out = gain*(in+ - in-)

where in+ is the voltage at the non-inverting input and in- is the voltage at the inverting input. The latter receives a fraction k = R1/(R1 + R2) of the output voltage,
Code: Select all
in- = k*out

Substituting this expression in the first equation we obtain
Code: Select all
out = gain*(in+ - k*out)

What happens if we apply some nonzero voltage to the non-inverting input? The output will respond immediately, however since a fraction of the output is fed back to the inverting input, the response will not be with the full free running gaing. We can actually compute the resulting loop gain by solving for out,
Code: Select all
out = gain*in+/(1 + gain*k) = in+/k

the second equality being a high-gain approximation.

Now what happens in the digital domain? A naive code would look like this:
Code: Select all
streamin in;
streamin k;
streamout out;
float gain=1000;
out = gain*(in - k*out);

Let's analyze step by step what happens if we apply an input signal, say in = 0.1. For the sake of simplicity, assume R1 = R2 or k = 0.5. From the analog circuit we woult expect roughly out = 0.2.
Let us assume that before we applied the input signal, the output was zero. In the first step the right hand side of the assignment instruction evaluates to
gain*(in - k*out) = 1000*(0.1 - 0.5*0) = 100
So at the end of step 1, out = 100.
In the second step, the right hand side evaluates to
gain*(in - k*out) = 1000*(0.1 - 0.5*100) = 100 - 50000 = -49900.
So at the end of step 2, out = -49900! You can easily work out further steps and see that the system blows up exponentially instead of reaching the value out = 0.2. The trouble is that in the assignment instruction, the variable out on the right hand side is different from the variable on the left hand side, the difference being a unit delay.
User avatar
martinvicanek
 
Posts: 1322
Joined: Sat Jun 22, 2013 8:28 pm

Re: 741 op-amp: just for the craic

Postby Spogg » Sun Aug 30, 2015 4:05 pm

Thanks for this Martin.

This is an excellent explanation of the difference between code execution and analogue voltage/current.

I've knocked up the schematic below which illustrates your points I think. The open-loop gain is set inside the opamp and the external amount of feedback has to be within a very small range in order not to get infinity out from the op amp. VERY unstable, even though it's negative feedback.

Thanks again for taking the time to explain this.

Cheers

Spogg
Attachments
Negative feedback demo as per MV.fsm
Only for demo
(133.51 KiB) Downloaded 1051 times
User avatar
Spogg
 
Posts: 3327
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England


Return to User Examples

Who is online

Users browsing this forum: No registered users and 9 guests