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.

MSP430FR2355: Is it possible to detect phase shifts in a 416Khz pulse using the msp430FR2355?

Part Number: MSP430FR2355

Good morning, first time poster. I have a question about the limitations of the analog in of the MSP430FR2355.

I have a JSATS pinger that emits a 416Khz frequency with a bit shift phase keying code that contains an identifier for pinger.

I am a novice trying to create some code that can convert the sinwave to a square wave, and then measure phase constantly to detect when it goes out of phase to get the bit shift.

My very basic code is used from dev ti website for the first comparator example that just turns on and off the led when a value is less than or greater than 0.5v [or 0x555]

Doing some googling I've found a few forum posts if I think I'm reading correctly say that the max input frequency is 100khz here

www.embeddedrelated.com/.../48373-1.php

So is it possible to detect phase shifts without the use of an external IC to detect them?

Second question, what format is the dev ti adc example code comparator voltage in?

if (ADC_Result > 0x555)                               // 0x555 represent 0.5V

If i convert 0x555 to decimal I get 1365, should I just multiply by 3 if I want to compare at 1.5V and then convert that value to hex?

Thank you for your time to read this!

  • Here are some pictures of my scope capturing the wave form:
    https://imgur.com/a/oQq6WQO

  • Doing this by brute force will be tight. At top speed (24MHz) you'll have 24/0.4=60 CPU clocks to process each cycle. That's maybe 10-15 instructions. FRAM wait states will reduce that further. 

    The first thing I would suggest is to use the internal comparator, rather than trying to compute zero-crossings from the ADC. The output of the comparator can be fed into a timer (e.g. TB2.1(B)) for capture. If you subtract successive capture values, you should see a large delta at the beginning of a shift, and a short one at the end.The comparator has a propagation delay of 1us (max) which in this experiment is fairly large. However, as long as the amplitude is constant, this should appear as a fixed offset in every trigger time, and so subtract away. 

    Having never heard of JSATS, I went to the first Google hit (atstrack.com). Their description suggests that the ID is a burst of (7+16+8)=31 bits, 744us long, every second or so. If my reading is right, you'll have about 744/2=372 samples to save, then you have a long time to process them. There's no DMA, so your code will probably just be a tight polling loop.

    Using those numbers, each bit is 744/31=24us, or about 12 cycles/bit. If you miss a few, you should still be able to detect the shift. Normal BPSK uses a half-cycle phase shift, which would be visible.

    There may also be a trick using, e.g. a timed poll of the comparator output (similar to the way a UART works). To do this the timer and the wave need to be fairly well synchronized (also like a UART).

    This won't be easy, but I'm not sure it's infeasible.

  • Thank you so much for this reply! Do you know of any code I can reference to try and grasp the situation better?
    The code my original program is basically just this dev ti code
    http://dev.ti.com/tirex/explore/node?devtools=MSP-EXP430FR2355&node=AMHMVJeRq5HuLp9RYFbFwA__IOGqZri__LATEST

    Trying to see if i can form a square wave off the led output from feeding a 416khz signal from a signal generator or the jsats pinger was the main goal I had in mind.

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430FR235x Demo - ADC, Sample A1, internal 1.5V Ref, Set P1.0 if A1 > 0.5V
    //
    //  Description: This example works on Single-Channel Single-Conversion Mode.
    //  Software sets ADCSC to start sample and conversion - ADCSC automatically
    //  cleared at EOC. ADC internal oscillator times sample (16x) and conversion.
    //  In Mainloop MSP430 waits in LPM0 to save power until ADC conversion complete,
    //  ADC_ISR will force exit from LPM0 in Mainloop on reti.
    //  If A1 > 0.5V, P1.0 set, else reset.
    //  ACLK = default REFO ~32768Hz, MCLK = SMCLK = default DCODIV ~1MHz.
    //
    //               MSP430FR2355
    //            -----------------
    //        /|\|                 |
    //         | |                 |
    //         --|RST              |
    //           |                 |
    //       >---|P1.1/A1      P1.2|--> LED
    //
    //
    //   Cash Hao
    //   Texas Instruments Inc.
    //   November 2016
    //   Built with IAR Embedded Workbench v6.50.0 & Code Composer Studio v6.2.0
    //******************************************************************************
    #include <msp430.h>
    unsigned int ADC_Result;
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                                 // Stop WDT
    
        // Configure GPIO
        P6DIR |= BIT6;                                            // Set P6.6 LED to output direction
        P6OUT &= ~BIT6;                                           // P6.6 LED off
    
        // Configure ADC A0 pin
        P1SEL0 |= BIT0;
        P1SEL1 |= BIT0;
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Configure ADC10
        ADCCTL0 |= ADCSHT_2 | ADCON;                              // ADCON, S&H=16 ADC clks
        ADCCTL1 |= ADCSHP;                                        // ADCCLK = MODOSC; sampling timer
        ADCCTL2 &= ~ADCRES;                                       // clear ADCRES in ADCCTL
        ADCCTL2 |= ADCRES_2;                                      // 12-bit conversion results
        ADCIE |= ADCIE0;                                          // Enable ADC conv complete interrupt
        ADCMCTL0 |= ADCINCH_1 | ADCSREF_1;                        // A1 ADC input select; Vref=1.5V
    
        // Configure reference module
        PMMCTL0_H = PMMPW_H;                                      // Unlock the PMM registers
        PMMCTL2 = INTREFEN | REFVSEL_0;                           // Enable internal 1.5V reference
        while(!(PMMCTL2 & REFGENRDY));                            // Poll till internal reference settles
    
        while(1)
        {
            ADCCTL0 |= ADCENC | ADCSC;                            // Sampling and conversion start
            __bis_SR_register(LPM0_bits | GIE);                   // LPM0, ADC_ISR will force exit
            if (ADC_Result > 0x555)                               // 0x555 represent 0.5V
                P6OUT &= ~BIT6;                                   // Clear P6.6 LED off
            else
                P6OUT |= BIT6;                                    // Set P6.6 LED on
            __delay_cycles(5000);
        }
    }
    
    // ADC interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC_VECTOR
    __interrupt void ADC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
        {
            case ADCIV_NONE:
                break;
            case ADCIV_ADCOVIFG:
                break;
            case ADCIV_ADCTOVIFG:
                break;
            case ADCIV_ADCHIIFG:
                break;
            case ADCIV_ADCLOIFG:
                break;
            case ADCIV_ADCINIFG:
                break;
            case ADCIV_ADCIFG:
                ADC_Result = ADCMEM0;
                __bic_SR_register_on_exit(LPM0_bits);              // Clear CPUOFF bit from LPM0
                break;
            default:
                break;
        }
    }
    

  • Example msp430fr235x_eCOMP_05.c does much of the setup I described, though as I mentioned I don't think you'll have time for interrupts.

    http://dev.ti.com/tirex/explore/node?devtools=MSP-EXP430FR2355&node=ANP2o69VPRS9i1I9XYQJJw__IOGqZri__LATEST

    Example msp430fr235x_eCOMP_03.c is a gentler introduction to the comparator, and does a square wave/LED thing. (It won't keep up at 416kHz either, but if you can slow the signal down you can see what it's doing on P2.0.)

    http://dev.ti.com/tirex/explore/node?devtools=MSP-EXP430FR2355&node=AIbNCMfsaqm521t3k3v8Ag__IOGqZri__LATEST

  • Hi Forest,

    How about your issue?

    Best Regards

    Johnson

  • Hi Johnson, I've marked my resolved issues. If you need to, lock the thread or consider it solved.

    Thank you!

  • Hi Forest,

    OK, Congratulations!

    If you have any problem later, please create a new post directly on E2E!

    Best Regards

    Johnson

**Attention** This is a public forum