I am developing an application on the MSP430F5529LP that senses plant tissue resistance. A change in such resistance changes the frequency of an opamp (TLV2372) R-C multivibrator, the output of which is buffered by the second opamp in the same package. I feed this output into Port 4.0 with the intention of measuring pulse width using timer_B capture. The power supply for the opamp is the launchpad 3.3V.
I started to write a program to do this, but, having trouble with capture, I decided to constantly monitor timer_B by generating an independent PWM output. The complete code listing is here:
#include "driverlib.h" #include <msp430.h> void Port_Mapping(void); void main (void){ WDT_A_hold(WDT_A_BASE); UCS_clockSignalInit(UCS_MCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_1); // Setup Port Pins Port_Mapping(); GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7,GPIO_PIN4); //PWM to verify timer_B is on GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); //variation in LED luminance tracks input signal TIMER_B_configureContinuousMode(TIMER_B0_BASE,TIMER_B_CLOCKSOURCE_SMCLK, TIMER_B_CLOCKSOURCE_DIVIDER_1,TIMER_B_TBIE_INTERRUPT_DISABLE, TIMER_B_DO_CLEAR); TIMER_B_startCounter(TIMER_B0_BASE,TIMER_B_CONTINUOUS_MODE); TIMER_B_initCompare(TIMER_B0_BASE,TIMER_B_CAPTURECOMPARE_REGISTER_2, TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_B_OUTPUTMODE_RESET_SET,0x8000); TB0CCTL0 = CM_1 + CCIS_0 + SCS + CAP + CCIE; // pos. edge + CCIXA + sync + capture mode + Interrupt enable //TIMER_B_initCapture in driverlib is broken - will not compile (TIMER_B_CAPTURE_INPUTSELECT_CCI0A not valid) TB0CCTL1 = OUTMOD_3; // CCR1 set/reset to P1.0 while (1){ __delay_cycles(0x00FF); } } #pragma vector=TIMERB0_VECTOR __interrupt void TIMERB0_ISR (void) { static int TB0CCR0_old; static int TB0CCR0_diff; TB0CCR0_diff = TB0CCR0 - TB0CCR0_old; TB0CCR0_old = TB0CCR0; TB0CCR1 = TB0CCR0_diff + 0x2000;// Add Offset to CCR1 [Cont mode] } void Port_Mapping(void) { P4DIR = 0xFE; // P4.1 - P4.7 output, P4.0 input P4SEL |= 0x81; // select P4.0 and P4.7 for Port Map functions __disable_interrupt(); // Disable Interrupts before altering Port Mapping registers PMAPPWD = 0x02D52; // Enable Write-access to modify port mapping registers #ifdef PORT_MAP_RECFG PMAPCTL = PMAPRECFG; // Allow reconfiguration during runtime #endif P4MAP0 = PM_TB0CCR0A; // P4.0 capture pin PMAPPWD = 0; // Disable Write-Access to modify port mapping registers #ifdef PORT_MAP_EINT __enable_interrupt(); // Re-enable all interrupts #endif } My efforts in monitoring timer_B paid off in that I found the test output signal at P7.4 vanished when I connected my opamp multivibrator to P4.0. I then tried inserting a one megohm resistor between the signal source and P4.0 with the same result. I then tried connecting, through a 10K resistor, P4.0 to launchpad ground and 3.3V. In all cases, the test output at P7.4 got messed up in that the square wave it should have been became no longer square - the duty cycle got messed up. All of the jumpers I used for this are short: 5 inches long.
I also noticed that, when the duty cycle was wrong, halting the program (not using the pause in CCS, but hitting the red stop button, thus leaving the launchpad "dangling") made the duty cycle returne to the square wave it should be. But the susceptibility to connecting anything to P4.0 remained even in this "dangling" state.
So my concern here is that perhaps this chip is not suitable for real-world sensing applications. Say it 'aint so!