Shop OBEX P1 Docs P2 Docs Learn Events
How to clamp an input signal to propeller? — Parallax Forums

How to clamp an input signal to propeller?

jcfjrjcfjr Posts: 74
edited 2020-05-08 18:00 in Propeller 1
I have developed an automatic antenna tuner for amateur radio applications. I sample the frequency of the signal being transmitted through one of the prop pins, to preset my tuner components to the proper settings via stepper motors. At 10 watts signal strength, my frequency sample is about .8v pep, and at 100w the sample is about 1.88v pep. But, when I apply full legal power of 1500w, the freq sample goes to above 5v. I have tried resistive pads, but to reduce the 5v to 3.3v they reduce the lower power readings to something below what the propeller can read. I have also tried a zener diode to clamp the voltage, but it seems to reduce the voltage as well at the lower power readings, below the clamping voltage desired. Does anyone know how I can buffer the input to the propeller? All I need from the measurement is the frequency, but I am concerned that at the higher power, I may damage the prop. I need to limit the voltage of the frequency measurement at the higher power settings, but not the signals below 100w. Any suggestions for a buffer that can accomplish this? The frequencies I am measuring are between 3.5 - 28.5 Mhz.
«1

Comments

  • evanhevanh Posts: 16,040
    edited 2020-05-08 21:12
    A couple of options I can think of: One is use the compDAC input mode for setting the digital input threshold to a smaller voltage. The other is an AC coupler circuit with VIO/2 DC bias at the prop2.

    Either would work with the attenuated signal then.

  • jcfjrjcfjr Posts: 74
    edited 2020-05-08 21:36
    Sorry evanh. Could you give little more explanation for each of your suggestions? The ability to lower the threshold sounds interesting, but not a clue how to do that.
  • evanhevanh Posts: 16,040
    I'll start with describing standard CMOS. Here the input threshold is half the supply rail. I/O supply is named VIO on the prop2. VIO voltage is 3.3 Volts, so regular threshold is 3.3 / 2 = 1.65 Volts.

    CompDAC mode uses an internal analogue comparator along with an internal DAC. So quite a different beast to a regular CMOS input. Result is the DAC level can specified the switching threshold for an input - Presumably between supply (VIO) and ground (GIO).

    Configuration, including the DAC level, is done with the P field of WRPIN. Here's an earlier write-up of it:
    	%11_VV_CDDDDDDDD = COMP_DAC comparator mode, DAC always clocked (registered)
    		DIR enables PinA digital output
    		%VV = Comparator config
    			00: IN = PinA > D.  PinA driven by 1k5R from OUT
    			01: IN = PinA > D.  PinA driven by 1k5R from !IN
    			10: IN = PinB > D.  PinA driven by 1k5R from IN
    			11: IN = PinB > D.  PinA driven by 1k5R from !IN
    		%DDDDDDDD = DAC level for internal analogue compare
    
  • evanhevanh Posts: 16,040
    edited 2020-05-08 22:36
    Hmm, that "IN" and "OUT" aren't an entirely accurate representation of the options. In our more recently updated block diagram that above IN is called "Input" at the custom pad ring. And the above OUT is called "Output" entering the custom pad ring from the synthesised core. Further reading at https://forums.parallax.com/discussion/171420/smartpin-diagram/p1

    EDIT: Also, the "DAC always clocked" comment is out of date now too. I had thought the main DAC was used with the comparator but the comparator has its own DAC that just switches in the eight bits from WRPIN mode register.
  • evanhevanh Posts: 16,040
    edited 2020-05-08 23:30
    Assembly code for changing a regular pin input to a compDAC input is a one-liner:
    	wrpin	##%1100<<17 | 50<<8, #TPIN	' 50 x 12.94 = 647 mV comparator threshold, 3.3/255 = 12.94 mV/step
    

    EDIT: Or to make it easily a dynamic threshold adjustment:
    	...
    	setbyte	cdm, th, #1
    	wrpin	cdm, #TPIN
    	...
    
    
    th	long	50		'comparator threshold is 3.3/255 = 12.94 mV/step
    cdm	long	%1100<<17
    

    EDIT2: Typo correction
  • evanh, My bad. I just realized I posted this under propeller 2 and not 1. It appears that propeller 2 may have what you are talking about, but I am using a propeller 1. Thanks for your explanation.
  • evanhevanh Posts: 16,040
    Ah, lol. No problem. The prop1 is fine with the second option of course.

  • Moved from Prop1 to Prop2.
  • Evanh
    do you have any sample ac coupler circuit? Sorry, my background is mechanical engineering because I couldn’t hack electrical engineering
  • evanhevanh Posts: 16,040
    Wouldn't call myself experienced but it should just be a case of one inline capacitor plus two resistors forming a divider.
                     VIO ---
                          |
                         ---    [
                       R1| |    [
                         | |    [
                         ---    [ Propeller
                 C1||     |     [
    RF signal -----||-----+-----[ Pin input
                   ||     |     [
                         ---    [
                       R2| |    [
                         | |    [
                         ---    [
                          |
                     GIO ---
    
    The ratio between the capacitor and resistors could be used to attenuate with I guess. Also, prolly a good idea to unbalance the resistors enough to limit noise injection from being counted.

    Appropriate values I can't even guess at other than likely quite high resistances and low capcitance.
  • AribaAriba Posts: 2,690
    This should work.
    The threshold voltage of a P1 pin is around 1.42V, that's why the Rs are not equal.
    At your frequencies also lower Cap values should work, 10pF or 22pF i.e. this makes it even more safe for the pin. There are protection diodes in the pins, so a 5V signal through a small Cap should not kill the pin.

    Andy
    256 x 110 - 2K
  • evanhevanh Posts: 16,040
    edited 2020-05-09 03:53
    [calculated it below]
  • Andy,
    Thanks for schematic. Is the 12kohm resistor connected to 3.3v?
  • evanhevanh Posts: 16,040
    edited 2020-05-09 03:47
    Yes, the higher resistance attached to the 3v3 supply lowers the balance point from 1.65 V to 1.42 V.

    EDIT: Actually,the lowered balance is 10/(10+12) * 3.3 = 1.5 Volts. So still got some margin above 1.42 V so good to use.

  • AribaAriba Posts: 2,690
    I see now that you say: At full power it's above 5V, not it's 5V. So depending how much above 5V it may be more safe to also add a series resistor to the capacitor. Something like 2k ohm should not lower the voltage swing too much.
  • jcfjrjcfjr Posts: 74
    edited 2020-05-09 23:50
    OK, I had a chance today to play with your schematic evanh, and as it turns out, you are right Ariba about the 2k resistor.
    Here are results at 7Mhz today
    Voltage @ + Voltage @ + Voltage @
    (Input)+ (P1Pin)+ Output thru series 2k resistor
    30 watts + 1.08 + .96+ .52
    100 watts + 1.76+ 1.56+ .88
    1500 watts+7.5+ 6.2+ 3.04

    Without the resistor in series it would have been too much. Not sure why the AC coupler section did not bring down the voltage more, seems the series resistor did all the work. And applying the 3.3v to the 12K resistor only offset the voltage by about 1.4v, the pep reading was still the same. If I removed the 3.3v, pep reading was same but no offset. Question is now is if the .52 v is enough to read a frequency with. Thanks for the help guys.

    Sorry I don't know how to transfer the format for my table above, did not seem to see the spaces to form the columns.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2020-05-10 02:00
    The reactance of 100pF at 7MHz is only 227Ω, so it is natural that more of the input voltage is transferred to the pin if the 2000Ω resistor is absent. The input impedance of the resistor network 5.5kΩ (10k||12k). There is also the source impedance of the sampling network and wiring and the capacitance of the input pin that enter into the calculation.

    To keep the format of a table you can use the Code tags to surround the text, the "C" option in the format menu. It takes some fiddling to get things to line up.
    30 watts        1.08   0.96    0.52
    100 watts       1.76   1.56    0.88
    1500 watts      7.5    6.2     3.04
    
  • btw, low voltage zener diodes are fairly useless as they have a rather soft knee and leak current below the threshold. If you need a low voltage "zener", try using an LED. If you use a green LED then they will start conducting at 1.8V, above the P1 threshold. However it is more common to use Schottky diodes for clamping if necessary or limit the current sufficiently for the internal clamp, although series resistance will limit the response time and frequency. The biased AC coupled method with a series resistor seems like a good idea and if you really wanted to be certain, just add Schottkys to Vdd and Vss.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2020-05-10 03:03
    Self-biasing might be a solution to handle the wide range of input voltages. In this scheme, a bpin is set up to provide the bias, as in sigma-delta ADC, but with slow RC network on the feedback loop. The 100nF capacitor initially charges up to threshold and then hovers near threshold, so the input sees rather random highs and lows due to the feedback. However, feedback is isolated from the input by the 10k resistor, so that even a small 7MHz input signal can overdrive feedback, thus, apin can count the true input frequency. The input referred time constant of 100pF with 12k has to be chosen slower than the period of the 7Mz input frequency.
    552 x 332 - 13K
  • jcfjrjcfjr Posts: 74
    edited 2020-05-11 21:07
    Tracy,
    Instead of a Bpin, couldn't I just use existing 3.3v for bias?
  • Cluso99Cluso99 Posts: 18,069
    There is a good sigma delta application note for the P1 in the docs from the main Parallax website.
  • jcfjr, I didn't mean to imply that there was anything wrong with using the existing 3.3V and a divider as has been suggested. It sounds like the solution you have now is okay, is it?
    With the 10k and 12k resistors and the 100pF with added 2k. I'm curious how your setup samples the RF. Is it through a resistive pad of some sort, or maybe an inductive loop or directional coupler?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2020-05-12 18:37
    What I was suggesting isn't sigma-delta. It is simply using the POSDET mode to provide a bias voltage matched closely to the input switching threshold. When first turned on, the apin starts at the Vss level, so the bpin goes high and the 100nF capacitor charges up via the 1M resistor until the capacitor voltage hits the input threshold, whence the input pin sees high, and bpin goes low. The apin subsequently hovers near the threshold and as the bpin toggles more or less at 50% duty cycle to keep it there. In sigma-delta you wouldn't have the additional resistor from the bias source (the 100nF capacitor) back to the input pin. The resistor isolates the input pin, so that it can be overdriven by an input signal. When overdriven, the feedback can't keep up, but the bias remains centered closely on the switching point. Therefore it should respond to quite small input signals.

    In a sigma-delta application, you might have a microphone connected through a capacitor to the apin input node, with direct resistive bpin feedback. The input stays close to the threshold, but the bpin pulse density closely tracks (balances) the input current, so that counting the bpin pulse density allows the Prop to track the analog level. With a low-impedance voltage source fed thru a capacitor at the input, the current is a function of the rate of change of voltage, not by its absolute value. It is easily possible for a large rapidly changing input voltage, a square wave for example, to overdrive the input. When that happens, the bpin pegs to one of the rails, in which case the Prop loses track of the analog level and sees only high or a low, balance is lost, no longer sigma delta. The scheme I was suggesting just takes that to an extreme to enhance the overdrive effect.

    I shouldn't get too deep into it, unless I actually try it out to see if there is a gotcha I've missed!
  • jcfjr, I didn't mean to imply that there was anything wrong with using the existing 3.3V and a divider as has been suggested. It sounds like the solution you have now is okay, is it?
    With the 10k and 12k resistors and the 100pF with added 2k. I'm curious how your setup samples the RF. Is it through a resistive pad of some sort, or maybe an inductive loop or directional coupler?

    Tracy,
    This solution will protect the prop up to 1500watts, but I am not so sure there will be enough there to measure frequency at the 30watt level. I have ordered a new board to implement the current solution (can't breadboard it onto existing board) and won't know if it is going to read the lower power frequency until I build it out. If that doesn't work, I have found a '850Mhz, low distortion, output limiting, programmable gain, buffer amplifier' (HFA1113) chip that sounds like it should just clip the upper voltages to a set voltage. You set the upper and lower clipping voltages with two pins on the chip. Sounds like what I am looking for, but it is surface mount (yuck), so back to Hong Kong for another board, just so I could try it. So I am hoping this solution works.

    I am just using a short piece of wire(about 1.5") in parallel with the center conductor of the feedline. I am also using a directional coupler to measure my forward and reverse voltage to calculate the SWR.

    What is POSDET mode? Still do not understand your bpin idea, but would like to understand better how it works, as a possible alternate solution.
  • rbehmrbehm Posts: 102
    edited 2020-05-14 01:44
    How about a logarithmic amplifier?
    Something like this AD8307 from Analog Devices.
    https://www.analog.com/media/en/technical-documentation/data-sheets/AD8307.pdf
    US$13.50 from Digikey https://www.digikey.tw/product-detail/en/analog-devices-inc/AD8307ARZ/AD8307ARZ-ND/936617

    I have not used it myself yet. Just an idea.
  • I am using the AD8307 to convert the rf signals from my directional coupler to a dc signal I measure with the MCP3202 adc for my forward and reflected voltages. But I need to measure the frequency and limit the amplitude, and the 8307 converts the rf signal amplitude to a dc output . I cant use the input to the 8307 to get the frequency because it is too weak to read.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2020-05-14 19:54
    The buffer amplifier sounds like overkill. The basic circuit, with a smaller coupling capacitor, the small series resistor, and a couple of Schottky diodes to clamp the voltage, should be sufficient. I drew it here, trying to imagine a circuit model of what your have as capacitive coupling to the feed line, and how that relates to the ground connection. The diodes prevent the input from forward biasing the Propeller substrate diodes, which could cause weird things to happen. With the small input capacitor and the ? resistor, there should be no danger of damage. The construction does have to be tight at your RF frequencies, minimal spurious inductors in the path.

    This shows the bias voltage adjustable with a potentiometer. If you were to adjust the potentiometer through the input switching threshold, you would see a point where the input is at a peak of sensitivity to lower levels of the input signal, right at the threshold. There will be a lot of noise that determines the lower limit of sensitivity to a real signal. You'd probably adjust it to one side or the other of the exact threshold, outside the noise band, so you get no count when there is no input.
    again, the noise band determines your limit of sensitivity.

    As it stands, your firmware is probably using one of the counter modes, either POSEDGE or NEGEDGE to count the rising or falling edges of your input signal.

    In the scheme I mentioned above, using the mode POSDET, with feedback to the bpin, the feedback mimics the effect of adjusting the potentiometer seen the the simpler scheme. The feedback causes the bias voltage to settle right on top of the threshold, the point of highest sensitivity, noise and all. The feedback rule is simply that the bpin follows the inverse of the apin, as determined at each 12.5ns Propeller clock cycle (at 80MHz clock rate). I really should specify POSEDGE with feeback, not POSDET with feedback, because still what you want to do is to count the edges on the apin over a period of time. POSDET measures the input period, not the frequency. The period in your situation is too short to be meaningful in relation to the Prop clkfreq.


    484 x 383 - 11K
  • Tracy,

    Given that the input is not a square wave, wouldn't it be prudent to add a little hysteresis to the Prop's input pin to ward off the counting of false edges? This can be done by applying an inverter to the POSDET output, along with a weak resistor to the input pin.

    -Phil
  • The buffer amplifier sounds like overkill. The basic circuit, with a smaller coupling capacitor, the small series resistor, and a couple of Schottky diodes to clamp the voltage, should be sufficient. I drew it here, trying to imagine a circuit model of what your have as capacitive coupling to the feed line, and how that relates to the ground connection.

    Tracy,
    I have attached a picture of my setup for my frequency sampling, pretty simple, but effective for measuring the feedline frequency to within a few cycles. I put my capacitor meter between the input to the prop and the center conductor of the feedline and measured 8.8pf. I think this would be the answer to your ?pf coupling question. As you see this is a single conductor to the prop, no grd. I get different answers from my scope that has confused me, and I think it may be in relation to your ? on the ground. If I put my scope on the line coming into the prop, and ground the probe to prop grd, I will get a pep voltage of .84v @ 30 watts and the tuner does not have enough to measure a freq. But if I remove the ground connection on the probe and measure (floating grd) , I get 2.56v, and the tuner measures the frequency. I really do not understand why the difference, and which voltage the prop is actually seeing. These measurements are without any resistor dividers or caps in line, from my sensor in the picture directly to prop pin. It seems as though the probe is acting as a voltage divider when grounded. This is the reason I am not so sure the current divider network will work at lower power, if it yields the answer my scope gives when grounded.

    So I am trying to figure out how to setup my scope to properly measure Vx when adjusting the 1k pot. Which Schottky diodes are you using in your design, and how do I determine the capacitor value across the resistors. I am using POSEDGE to make my freq measurements.

    In this design you are using a fixed bias voltage set with the pot. I am intrigued of how you would use a bpin to bias, I have some extra pins available, and not excited about putting a pot on the board. I have included my code for frequency measuring below, where would you put the bpin biasing in this code, and what would it look like?
    Repeat                                       
            Dira[Fpin] := 0
            Ctra := 0
            Ctra := (%01010 << 26)|(%001 << 23)|(0 << 9)|(Fpin)
            Frqa := 1
            Phsa := 0
            waitcnt(40_000_000 + cnt)                       'Count freq for 250ms to see if signal
            Frequency1 := Phsa/1000
            Frequency1 := Frequency1*2
            
            if frequency1 < floorfreq                                                       '
    
               buttons
              
                 IF reset == 1
                    Nstep := 4
                   Return
                             
               IF Poff == 1            
                 Nstep := 5
                 Return
              Pst.Str(string(11, 13, "Sig Search"))
              
              newencstat := INA[0..5]    
              IF oldencstat <> newencstat  
                tune := 1
                WriteObjValue($13,$00,$01)                        'Turn on encoder LED
                Pst.Str(string(11, 13, "LED on"))  
                return
    
              CASE Rtune
                 0: Nstep := 0
                     Next
                 2: Nstep := 6
                     Return              
                                
               
            elseif frequency1 > 0  
             
              Dira[Fpin] := 0                               'Measure frequency1 
              Ctra := 0
              Ctra := (%01010 << 26)|(%001 << 23)|(0 << 9)|(Fpin)                   
              Frqa := 1                                                             
              Phsa := 0
              waitcnt(20_001_200 + cnt)                     'Added 1200 cnts for freq correction                                            
              Frequency1 := Phsa/1000
              Frequency1 := Frequency1*4
       '       
    
              Dira[Fpin] := 0                                'Measeure frequency2
              Ctra := 0
              Ctra := (%01010 << 26)|(%001 << 23)|(0 << 9)|(Fpin)                   
              Frqa := 1
              Phsa := 0
              waitcnt(20_001_200 + cnt)
              Frequency2 := Phsa/1000
              Frequency2 := Frequency2*4
              
              IF frequency2  <> frequency1
                nstep := 0
                return                                      'If Freq1 <> Freq2 then bad measure, try agn
                     
              WriteObjValue($0F,$03,Frequency2)             'Write frequency to display
              Efrequency2 := Frequency2 
              IF Frequency1 == oldfrequency
                nstep := 1
               return
              elseif nstep := 2           
                return
    


    1512 x 2016 - 402K
Sign In or Register to comment.