News:

;) This forum is the property of Proton software developers

Main Menu

Double word maths anomaly

Started by charliecoutas, Dec 14, 2021, 03:28 PM

Previous topic - Next topic

charliecoutas

Positron vsn 1.1.0.6  16 bit compiler

Gives wrong result of 32 bit subtraction if result is negative

   Dim PowerA SDword
   Dim PowerB SDword
   Dim ErrorP SDword

   PowerA = 403000
   PowerB = 446936

   ErrorP = PowerA - PowerB

   Hrsout Dec ErrorP         'This gives 4294923360   It should be -43936 

   ErrorP = PowerB - PowerA  'This gives the correct answer

   

Pepe


charliecoutas


charliecoutas

Not an anomaly, user error.

top204

I have not made the Dec modifier automatically see if its operand is a signed or unsigned integer variable, so that a user can see, or transfer, the actual integer value, and not the 2s complement value, if required. The same for the SDec modifier, in that it will always convert the 2s complement value to ASCII, regardless of the integer variable type.

Unlike floating point, where the Dec or SDec modifiers will always transfer the correct floating point value, negative or positive.

charliecoutas

Thanks Les, I don't normally work with negative numbers, my fault. What you say makes sense.

I have got my Constant Power Pulse Generator working. I played around with a sort of Proportional control system but I think it would be too slow. I am sitting in a very tight loop and adjusting the drive to the load every 10uS. I don't know how fast the load can change but I am getting encouraging results. Strewth, is that dsPIC33CK256MP505 fast! The control loop looks like this:

start: Apply drive volts
       Wait 10uS
       Read ADC for load volts
       Read ADC for load current
       Multiply these together
       Calculate error and new drive value
       Goto start

Thanks for your help.
Charlie

top204

Glad you got it working Charlie.

I also found the PID and PI algorithms too slow to stabilise for mechanisms that need immediate changes to happen. They are great for motors and thermal controlling, but not so much for pulses or current changes etc... Even on super fast devices, the algorithms themselves need a stabilising time, even with fine tuning applied. I did try the auto tuning mechanisms, but they did not work as fast as I wanted neither, because they also need time to stabilise and calculate the values to place into the PID or PI, and with mechanisms that change constantly, the auto tune is not the answer because it is constantly tuning and perfroming the PID, so it takes longer to stabilise. :-)

I'm looking forward to a time I can do some further experimenting with the dsPICxxCK devices, and maybe time to add the dsPICxx33CH devices to the compiler as well.

charliecoutas

It's interesting stuff. You can help me a little more please Les: I am driving the ADC inputs to the 33CK256MP505 from an op-amp. The op-amp rails mean it can swing way beyond what the dsPIC33 will allow (3.3v+ 0.3V). So I have a 3.3V zener across the ADC input pin, and a 1K resistor between the op-amp output and the ADC input pin.

But the input resistance to the dsPIC ADC is stated as normally between 500 ohms and 1k max. Which is a problem. The 3.3V zener starts drawing current at about 2.9V and the low input resistance of the ADC drags it down further. I will replace the 1K resistor with a short. It is surprising that the ADC input is so low resistance, but then of course it has to operate at very high speeds.

Question: how do you protect the inputs of a 3.3V chip when its input resistance is only 500 ohms and the op-amp driving it can swing beyond the safe limits of the input?

Charlie

trastikata

Quote from: charliecoutas on Dec 16, 2021, 03:41 PMQuestion: how do you protect the inputs of a 3.3V chip when its input resistance is only 500 ohms and the op-amp driving it can swing beyond the safe limits of the input?
Charlie

Charlie I am usually using a R-to-R op amp powered by the same voltage as the PIC.

Where that is not possible I have a fast 1A Schottky diode to VCC and GND and I always use OA with current limiting and 100 - 200 Ohm resistor, so if the voltage is clamped to VCC+0.3.

Whenever a low impedance is required, I simply use a second 5v or 3.3v R-to-R opamp as voltage follower after the first, clamped OA.

charliecoutas

I see that a R-to-R op amp running on 3.3V would be a solution, just a straightforward buffer, nice idea.

I don't follow the 1A Schottky diode, what is "OA"?

Thanks
Charlie

trastikata

Quote from: charliecoutas on Dec 16, 2021, 04:48 PMI don't follow the 1A Schottky diode, what is "OA"?

OA = OPAMP. The application is the same as the zener diode but better and faster :). Important is that the OPAMP has short circuit protection, and any over- or under-voltage gets dissipated in the 1A Schottky diodes until the OPAMP's over-current protection kicks in.


charliecoutas

Got it! That's what I'll go for. The series resistor might be a problem, the input resistance to the ADC is 500 ohms (at least). I'll play around with it. Many thanks.

Charlie

top204

#12
You can get clamping diodes for a particular voltage, and that is what the diodes above are operatng as. Some attach from the Gnd to the Input, and stop voltages rising any higher by clamping down. They sometimes use them on audio inputs of pre-amplifiers, and TVs had them on the imput lines of the PSU sections.

The resistance of the ADC does come into play when accuracy is required at higher speeds, but it is not always critical for standard ADC operations. It is the charging requirements of the internal ADC capacitor that dictates the resistance on the ADC.

I've always gone for a high speed buffer op-amp, operating at the same VDD as the microcontroller, because it can also give more control what the ADC sees, with biasing on the op-amp if required.

charliecoutas

#13
I have put a 3.9V zener from the 3.3V rail to ground as well. There isn't much more than the dsPIC on the 3.3V rail, so I imagine that the op-amp could force the rail above 3.3v due to the clamping diode, assuming that the 3.3V regulator wouldn't object if the rail was pushed higher?

Using op-amps on 3.3V is a new idea for me (I grew up with valves). Don't you need a negative rail as well? I can't imagine that an op-amp would work well enough with just a single 3.3V supply and ground?

The ADC storage capacitor on the dsPIC33CK is 5pF!  Draw the curtains and call me Gladys!

Charlie

trastikata

In- and Output Rail-to-Rail at 2.5 volts and 20 to 50 MHz bandwidth OpAmps are standard today, general purpose OpAmp with such characteristics cost around 90 cents.

With the ubiquitous low voltage LiPo powered devices there is no other way but to adjust the elemental base too.

charliecoutas

Thanks, studying modern op-amp technology........

top204

#16
Look at Non-Inverting Op-Amp circuits, or a unity gain buffer. They do not need a virtual ground, and if a positive voltage is entered, a positive voltage is outputted (if that is actually a word. LOL). These days, Op-Amps can work off extremely low voltages, and take next-to-nothing in current. Make sure you get a rail to rail Op-Amp for an ADC buffer that is not for audio.

In the early days, the dual supply is what always put me off Op-Amps, because I couldn't afford two PP3 batteries as a kid. :-) I then discovered the virtual ground with 2 resistors and a capacitor for audio and radio work with the 741 Op-Amp. Then Non-Inverted for buffers, where a single voltage works.

My lovely dad showed me how to work with valves (tubes) when I was a boy and I still love them. I still remember asking him how to build a valve radio because I was so used to transistors. I was fascinated by the high voltages required, and the output volume one could get with a single pentode working as class A. That led me on to higher voltages with internal X and Y plate CRTs and that fascination has never left me. I miss televisions with a CRT in them, because they were always good to work on. Heavy, but fun to repair. LOL

I envy your work at Bletchley Charlie. Working with all of that wonderful old equipment and components. :-) Do you still come across the Anode resistor going higher in value over time, causing the valve's output to become weaker?

charliecoutas

Thanks Les, I'm looking at low voltage op-amps. I'll stick to the LF351's I'm using in this design and use the clamps that trastikata suggested. It's almost finished so I don't want to change too much.

The failures we get at the computer museum at Bletchley Park are several. In no particular order:
Valves going low emission, mainly because they are not drawing any anode current for most of their (logic) life,
Electrolytic capacitors drying out (and sometimes going bang), oil-filled caps leaking all over our nice wooden polished floor,
Power resistors going high resistance,
Connection dry joints, solder going bad,
Mechanical problems, mainly Colossus's tape reader system,
Filament lamps,
People messing around with settings....    and so on.


top204

QuoteValves going low emission, mainly because they are not drawing any anode current for most of their (logic) life

What causes the loss of emission with no Anode voltage Charlie? I know this used to happen with TV Cathode Ray Tubes, because the cathode used to get a crust on it because it was mainly cadmium, so it needed de-crusting with a high voltage for a short while, but I didn't know valves had a special cathode?

charliecoutas

I think it's due to the electron cloud hanging around the cathode with nowhere to go. A chemical deposit forms and falls back onto the cathode and effectively stops it emitting electrons. I think heavy ions play a part as well. Look up Cathode Poisoning. I'm pretty sure Tommy Flowers (the designer of Colossus) knew about this because many of the valves in Colossus (2500 in Mk2) conduct in their idle state rather than stay off. Some valves also lose their vacuum after many many years, a clue is that the getter (that mirror-like silver patch) goes white and powdery.

I've got the Schottky diode clamp on the ADC inputs instead of a zener and the results are more accurate at near-rail voltages. The 3.3V zener was dragging the signal down at any voltage above about 2.7V.