i want to trigger an adc interrupt in msp430g2553 as soon as the input signal reaches 1.5V. can it be done?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
i want to trigger an adc interrupt in msp430g2553 as soon as the input signal reaches 1.5V. can it be done?
GURU MOORTHY said:can it be done using ADC itself and not using comparator?
No. As far as I know, ADC of msp430 does not have such functionality. Thou you can implement it in software by continuously comparing ADC reading to treshold and then calling function when treshold reached
Ilmars said:No. As far as I know, ADC of msp430 does not have such functionality. Thou you can implement it in software by continuously comparing ADC reading to treshold and then calling function when treshold reached
how can it be done using software comparison. can you just brief?
GURU MOORTHY said:how can it be done using software comparison. can you just brief?
Sure! http://www.tutorialspoint.com/cprogramming/if_else_statement_in_c.htm
I modyfied TI example for you:
// If A1 > 1.5V, P1.0 set, else reset.
//
// MSP430G2x33/G2x53
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// >---|P1.1/A1 P1.0|-->LED
#include <msp430.h>
#include "intrinsics.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // Set P1.0 to output direction
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_1; // input A1
ADC10AE0 |= 0x02; // PA.1 ADC option select
__delay_cycles(30000); // Delay to allow Ref to settle (30ms)
__enable_interrupt(); // Enable interrupts.
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exi
if (ADC10MEM < 0x3ff) // ADC10MEM = A1 < 1.5V
P1OUT &= ~0x01; // Clear P1.0 LED off
else // ADC10MEM = A1 > 1.5V
P1OUT |= 0x01; // Set P1.0 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
Lukasz said:for (;;) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exi if (ADC10MEM < 0x3ff) // ADC10MEM = A1 < 1.5V P1OUT &= ~0x01; // Clear P1.0 LED off else // ADC10MEM = A1 > 1.5V P1OUT |= 0x01; // Set P1.0 LED on } } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR (void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) }
Can you describe the above part. That is when interrupt occurs and what happens inside ISR
GURU MOORTHY said:what happens inside ISR
When ADC conversions is done and result placed in the ADC10MEM register, ADC interrupt is called. What happens in the ISR is actually said in the comment "Clear CPUOFF bit from 0(SR)" which means upon ISR exit CPU will exit sleep (LPM0 mode), continue execution.
You have another clue in another comment: "ADC10_ISR will force exi"
Ilmars said:When ADC conversions is done and result placed in the ADC10MEM register, ADC interrupt is called. What happens in the ISR is actually said in the comment "Clear CPUOFF bit from 0(SR)" which means upon ISR exit CPU will exit sleep (LPM0 mode), continue execution.
You have another clue in another comment: "ADC10_ISR will force exi"
whether the interrupt occurs for every sample?
GURU MOORTHY said:how can we trigger adc interrupt as soon as comparator output goes high?
Never mind. I was kidding. - What's the point to call ADC interrupt if you already got measurement using comparator?
Solution for your problem is continuous ADC sampling and comparing result to treshold. Lukasz even gave you code sample.
GURU MOORTHY said:Can I get ADC interrupt without continuous sampling?
Indeed. If you don't like continuous sampling, you can use single conversion mode. Remember that ADC interrupt is "conversion done" interrupt, not like you ask "voltage greater than 1.5V interrupt". If you want ADC that does treshold matching with interrupts in hardware, you shall use another microcontroller with such functionality. Otherwise on msp430 you shall use software solution, as Lukasz advised
p.s. Just curious: GURU is your real name, surname or dignity?
The ADC10_A, found in 5x family, has a window comparator that will test the conversion result against an upper and lower limit. The ADC10 of the other families (including the G2xx) doesn’t. So it has to be done anually, by comparing the conversion result against a threshold by software in teh adC ISR.
**Attention** This is a public forum