Hello, everyone,
I'm using the SD14 digital converter of the RF430frl152h chip. I have had problems working with frequencies around 100kHz. My goal is to read an external sinusoidal signal and recreate it in a square signal with the same frequency. To do this, I thought of looking at the slope of the signal and based on the value read determine if the curve is rising or falling. This, however, works around 1kHz but not really good.
The datasheets says " Sampling frequency of up to 2kHz". So,Maybe the device can't not work with higher frequency than around 1kHz?!
Could the problem be the sampling rate or the conversion rate? Maybe the Port Output has a frequency range of clocking? If you have any ideas, please tell me.
Following there is my code.
#include <msp430.h> #include <rf430frl152h.h> #include <stdbool.h> void settingADC(void); void slopeDetection(void); int prevDATA = 0; int newDATA = 0; bool flag = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop WDT // reset to avoid JTAG configuration P1SEL1 &= ~(BIT4 | BIT5 | BIT6 | BIT7); P1SEL0 &= ~(BIT4 | BIT5 | BIT6 | BIT7); //change frequency of SMCLK to 4 MHz CCSCTL0 = CCSKEY; CCSCTL5 &= ~(DIVS2 | DIVS1 | DIVS0); P1DIR |= BIT5; // set GPIO output P1SEL0 &= ~BIT5; P1SEL1 &= ~BIT5; settingADC(); while(1) { slopeDetection(); } } void slopeDetection(void) { prevDATA = newDATA; // store previous value newDATA = SD14MEM0; // get value from ADC if(newDATA > prevDATA) { P1OUT |= BIT5; //set pin HIGH flag = 1; } else if(newDATA < prevDATA) { P1OUT &= ~BIT5; // set pin LOW flag = 0; } else { if(flag) P1OUT |= BIT5; else P1OUT &= ~BIT5; //nothing } } void settingADC(void) { SD14CTL0 = SD14SSEL0 +UCB0IE; SD14CTL0 &= ~(SD14SSEL1 + SD14DIV0 + SD14DIV1); SD14CTL1 &= ~(SD14INCH0 + SD14INCH1 + SD14INCH2); // INCH =0000->A0,ADCCLK //SD14MEM0 = SD14INCH__A0; // channel A0 SD14CTL1 &= ~(SD14RATE0 + SD14RATE1 + SD14RATE2); SD14CTL0 |= SD14EN + SD14SC; // Start Conversion _BIS_SR(GIE); // interrupts enabled } /***************************************************************************/ /* interrupt vectors for MSP430 */ /***************************************************************************/ #pragma vector = SD14_VECTOR __interrupt void adc_interrupt(void) { SD14CTL0 |= SD14EN + SD14SC; // Start Conversion again }
Best regards.
Giuliano