AEC1 0 Posted August 2, 2012 Share Posted August 2, 2012 Hey all, I am still new to MSP430 and Energia so please bear with me. We have been comparing the responses of comparators for use in projects that will incorporate the MSP430 and we wanted to test the built-in comparator for our MSP430G2553. Is there any way to access and use the comparator to compare two signals within Energia? Any help would be greatly appreciated! Quote Link to post Share on other sites
AEC1 0 Posted August 6, 2012 Author Share Posted August 6, 2012 Any thoughts on this? A little more clarification. For now, our goal is simply to use the comparator to compare an input signal to a voltage reference and then output the result so that we can analyze this output. My main issue is determining how to select comparator use within Energia. Quote Link to post Share on other sites
spirilis 1,265 Posted August 6, 2012 Share Posted August 6, 2012 Not sure if Energia has any libraries or functions for doing that, so the devs would have to chime in. You should be able to monkey around with enabling and configuring the comparator the old fashioned way, i.e. toggling the special-function-registers for it... the MSP430 x2xx User's Guide has all those details-- http://www.ti.com/lit/ug/slau144i/slau144i.pdf Energia (and Arduino, the AVR-oriented IDE it's derived from) ideally abstracts away a lot of those details, but maybe that feature just isn't written yet. AEC1 1 Quote Link to post Share on other sites
Rickta59 589 Posted August 6, 2012 Share Posted August 6, 2012 There aren't any wrappers for the Comparator as of yet. You could look at the TI code samples for the msp430g2553 and use that as a starting point. http://www.ti.com/litv/zip/slac485a code samples there. Check out the ones with *_ca_* in the name of the file. -rick AEC1 1 Quote Link to post Share on other sites
AEC1 0 Posted August 6, 2012 Author Share Posted August 6, 2012 Thanks guys for the assistance. Are there currently any plans for creating a wrapper for the comparator? Quote Link to post Share on other sites
energia 485 Posted August 6, 2012 Share Posted August 6, 2012 This should help you to get going. void setup() { pinMode(RED_LED, OUTPUT); /* Internal reference (comp-)0.25 * VCC and turn on */ CACTL1 = CARSEL + CAREF0 + CAON; /* Select P1.3/CA3/S2 as the compare input (comp+). * This selection is not obvious from register bit definitions. * The Comparator_A+ Block Diagram in sectotion Comparator_A+ Introduction * is a better reference. */ CACTL2 = P2CA2 | P2CA1; } void loop() { /* Pressing S2 will turn on the LED1 */ if ((CACTL2 & CAOUT)) digitalWrite(RED_LED, HIGH); else digitalWrite(RED_LED, LOW); } rohit, AEC1, spirilis and 2 others 5 Quote Link to post Share on other sites
AEC1 0 Posted August 7, 2012 Author Share Posted August 7, 2012 Thanks so much for the help. I just wanted to ask a question for clarification. Can all of the traditionally used MSP430 code that uses the control registers also be implemented within Energia? Quote Link to post Share on other sites
energia 485 Posted August 7, 2012 Share Posted August 7, 2012 Yep you can. All register definitions used in e.g. the TI msp430 code examples can be used in Energia. The example code above is from the TI code examples. The header files that are used with CCS are the same as the ones included in gcc and thus Energia. AEC1 1 Quote Link to post Share on other sites
olivluca 12 Posted September 29, 2012 Share Posted September 29, 2012 While the example works, I had some problems with it: when you push the button it goes to GND, so the comparator should give a 0, but it actually gives an 1 with the button pressed. I thought maybe the reference is sent to V+ and the button to V-, so I studied the diagram to reverse the assignment and I don't understand why your example works: according to the block diagram, you are sending both the reference value and the input pin to V- while V+ is left floating. In the schematic, with CARSEL=1 and CAEX=0 the reference is sent to V-, and P2CA1, P2CA2, P2CA3 also select the input to feed to V-. In theory V+ is selected by P2CA0 and P2CA4, though there's no combination to select P1_3. I tried leaving out CARSEL, so the reference is fed to V+ and the button to V- and it also works (and this time I understand why). Quote Link to post Share on other sites
energia 485 Posted September 30, 2012 Share Posted September 30, 2012 Good catch! Below id the fixed code. Please not that I enable the internal pull-up on P1.3 since most of the LP's don't have R34 not populated. void setup() { pinMode(RED_LED, OUTPUT); /* Internal reference (comp-)0.25 * VCC and turn on */ CACTL1 = CAREF0 + CAON; pinMode(PUSH2, INPUT_PULLUP); /* Select P1.3/CA3/S2 as the compare input (comp+). * This selection is not obvious from register bit definitions. * The Comparator_A+ Block Diagram in section Comparator_A+ Introduction * is a better reference. */ CACTL2 = P2CA2 | P2CA1; } void loop() { /* Pressing S2 will turn on the LED1 */ if ((CACTL2 & CAOUT)) digitalWrite(RED_LED, HIGH); else digitalWrite(RED_LED, LOW); } Schematic: VCC (3.3v) | / |\ 47k \ +---- | \ / | 0.25*VCC | \ | | .83v Comp + | \ | | | \ _____ CAOUT | | | / |______| P1.3 Comp - | / | | | / | +---- | / \ |/ \ | | VSS Quote Link to post Share on other sites
Skeef 0 Posted June 15, 2014 Share Posted June 15, 2014 Hi all! I have a similar problem. I need to compare two voltages about 0.2V. How can I select external reference for (comp-) which I want to adjust with voltage divider? Thanks for any help! Quote Link to post Share on other sites
Skeef 0 Posted June 15, 2014 Share Posted June 15, 2014 Schematic: |\ +---- | \ | adjust*VCC | \ | .about 0.2v Comp + | \ | | \ _____ CAOUT | | / | P1.3 Comp - | / | | / +---- | / |/ Quote Link to post Share on other sites
L.R.A 78 Posted June 15, 2014 Share Posted June 15, 2014 i'm a bit appart in knowing all peripherals of the msp430 but this should help: http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/323007.aspx Quote Link to post Share on other sites
B@tto 51 Posted June 16, 2014 Share Posted June 16, 2014 A good blog about msp430 for beginners (it's where I started to learn how to program msp430 in fact) : http://mspsci.blogspot.fr/2010/12/tutorial-12-making-comparisons.html alchy75 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.