Shop OBEX P1 Docs P2 Docs Learn Events
How to detect logic level? — Parallax Forums

How to detect logic level?

lardomlardom Posts: 1,659
edited 2012-11-12 06:09 in Propeller 1
I did some basic tests with the LM339 by setting the ground input to 1/2 Propeller supply. Turning the potentiometer I measured voltage at the output. It worked. Next I wrote a simple method and pressed F10. I found I could only get an led to light up if I touched the wire connected to the comparator output. I'm stumped. Please help.
PUB main

    dira[11]~~
    dira[13]~
    outa[11]~
    
    repeat
      if ina[13]                   'comparator output
        outa[11]~~                 'LED connected here
        waitcnt(clkfreq/2 + cnt)
        outa[11]~

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-11 09:28
    The LM339 has an open collector output. You need a pullup resistor to Vdd (3.3V). 10K is a reasonable value. Almost anything will do. Low values (a few hundred Ohms) draw more current and high values (a few hundred thousand Ohms) are susceptable to noise.
  • lardomlardom Posts: 1,659
    edited 2012-11-11 09:57
    @Mike Green, Ha! Thanks. I would not have figured that out. I actually did try a 100K resistor. 'Too low draws too much current and too high is susceptable to noise'.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-11 10:47
    100K allows roughly 30uA to flow. That's probably enough if that area of the PCB or wiring isn't too noisy and if there's not so much capacitance around there that the RC time is significant. 100 Ohms allows 30mA to flow, more than for a typical LED ... wasteful but otherwise OK since the LM339 can't really provide 30mA and isn't damaged by connecting the output directly to the supply voltage.
  • lardomlardom Posts: 1,659
    edited 2012-11-11 11:28
    Thanks for the additional numbers. My goal is detect a state change or 'zero cross' for a sensorless bldc.
    I have to fine tune the circuit but at least I know I'm on the right track.
    EX.
    
      IF ina[x] <> ina[x]
        outa := %001001              'commutate
    
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-11-11 11:40
    It occures to me that if you are sensing 1/2 of VDD, 3.3V, or +1.65V logic level you don't need the LM339 at all. For safety just use a series pin input protection resister.

    Depending on the maximum voltage you are testing keep the current to less than 0.5mA.
    10K for 5V
    20K for 10V
    360K for 120VAC

    Duane J
  • lardomlardom Posts: 1,659
    edited 2012-11-11 12:14
    Hi Duane, I'm testing 6V on the motor and I want to raise it to 8V. I'm trying not to fry stuff as I learn. It seems that ina responds to voltage much less than 1.65V. I still am not sure why. I guess I need a better understanding of pull-ups. Since bldc ground is not stable I want to try to avoid sensing 1/2 VDD. I wanted to try experiments to sense state changes between - / + which, in my thinking should work almost as well as hall effect sensors.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-11-11 14:30
    Hi Larry;
    lardom wrote: »
    Hi Duane, I'm testing 6V on the motor and I want to raise it to 8V. I'm trying not to fry stuff as I learn. It seems that ina responds to voltage much less than 1.65V. I still am not sure why. I guess I need a better understanding of pull-ups. Since bldc ground is not stable I want to try to avoid sensing 1/2 VDD. I wanted to try experiments to sense state changes between - / + which, in my thinking should work almost as well as hall effect sensors.
    The Prop was designed so ina's threshold is quite close to 1/2 of VDD.
    There may be a couple of reasons why you are not seeing this.
    1. There may be some delay from the BLDC voltage and the output to ina making it seem the transition isn't 1.65V.
    2. There may be noise from the BLDC.

    BTW, I agree with the use of the comparator to eliminate voltage differences between the Prop's ground and the motors.
    Also, generally comparators do the "Comparison function" much better than Op-Amps because they are much faster and inputs don't saturate primarily because the gain is low.

    A bit of caution though. LM339 doesn't tolerate input voltages outside the specified range. I can't find it in the spec but I remember that the LM339 may invert the expected output polarity when outside the specified range. No damage but unexpected operation.

    There are comparators that guarantee proper output polarity even when outside the specified input range.

    Duane J
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-11-11 16:14
    You might want to try this:
    DiffComp.png

    This is a kind of Differential Input Voltage Comparator.

    Duane J
    221 x 186 - 3K
  • lardomlardom Posts: 1,659
    edited 2012-11-12 06:09
    :smile: The 3rd possible reason is that I was 'clueless'. I made electronic and logical errors. There are three main parts to my schematic which are 3 1/2 H-bridge, pwm and comparators. The H-bridge and pwm are working. So far with a stepping loop I'm able to accelerate the motor with DC and then switch to pwm. I wrote a test method to pass commutation control to the comparators. It failed and my education continues.. I bought a 2nd LM339 and had to ask for help.


    Bridge pwm and comparators.JPG
    614 x 499 - 74K
Sign In or Register to comment.