Shop OBEX P1 Docs P2 Docs Learn Events
SXB Comparitor Function (resolved) — Parallax Forums

SXB Comparitor Function (resolved)

RS_JimRS_Jim Posts: 1,768
edited 2009-12-04 12:32 in General Discussion
I seem to be struggling to get the comparitor function to work.· I am feeding pin B2 with a pulse that varies from 1.8 to 2.3 volts and feeding pin one with a voltage divider that gives me aproximately 2.1 volts.· I initialize the SX as follows:
·CMP· Con $08
·CmpEN $00
·Mode CMP
·Mov· !RB,CmpEn

I connect B6 to B0 with a resister and then monitor B6 in an interupt service routine. Do I have to continue issuing the Mode and Mov !RB instructions or is once enough?· I am not getting the pulse to come through even though I can feed the same pulses through a 741 OP am and get it to work as a comparitor. I need to use the compare function to eliminate some noise on the incoming pulse that is causing false triggering in the software.

Thanks
JIm






Post Edited (Radio Shack Jim) : 12/4/2009 12:30:44 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2009-12-02 13:57
    Jim,
    You only have to setup the mode once. But be aware that it is a SWAP and not a write.

    I think you also have to make RB.0 an output. It's been a long time since I used the comparitor.

    Can you post you code ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1st rule of finance...Don't lose money.
    Never be ashamed of making an honest·profit.
    Live within your means...Make do, or do without.
    ·
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-12-02 16:43
    Actually, you don't have to make RB and output; the comparator output bit goes right to the physical pin (I've used this several times). There is no need to connect RB.0 to RB.6 -- with RB.0 in input mode you can in fact read the state of the comparator (I did this on a recent customer project).
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-12-02 23:22
    Jonny,
    so I configure the comparator with mode $8, then Mov !rb,0 then set rb.0 as input, or just read the state of rb.0?
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-12-03 22:47
    By default RB.0 is an input, so long as the comparator output bit is enabled you will see this when reading RB.0.
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-12-04 12:32
    Jonny and Bean,

    Thanks for all the help.· I went back and studied the hardware on the chip and found that even if the port is configured as an output, you can read its state.· I found my biggest problem was with my reference voltage.· I used a 10K pot and adjusted it until I got the state change to occur at the right time. Now, I may even try to use edge triggering which I had tried before and found it failed.

    RS_JIM
Sign In or Register to comment.