Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all 22138 articles
Browse latest View live

How to Proper Call an Interrupt within a Function

$
0
0

I'm having a problem implementing and interrupt function in my already existing code.  Basically I want the interrupt to trigger either when a certain output is triggered or when the counter that triggers the output reaches the threshold.  

Equipment:

Micro:  MSP430F5522

CCS:  5.5.0.00077

Compiler: TI v4.1.9

The device is supposed to scan for a light, and if the light is detected a certain amount of times in a row, an output is turned on that lights up a green LED.  If it fails a certain amount of times in a row, a red LED is supposed to turn on.  

The problem with this code is that the red LED does not stay on long enough to show that there was a high amount of consecutive misses when scanning for the light.  The solution was to come up with an interrupt function that uses a different clock within the processor so the test cycle is not delayed and the red LED stays on long enough for the operator to know about the misses.  

The RED/GREEN_LED_ON/OFF are bit wise output controllers defined earlier in the file.

This is the original function before I put the interrupt function within it:

#define PASSCOUNTERTHRESHOLD  40//20

   void display( char  event , char test )
	{
		int j,i;

		static int maxConsecPassingCount=0;
		static int consecPassingCount=0; 
		static int passingCount=0; 
		static int timeLimit=0;   // amount of time allowed for non detection before failure is asserted.
		static int consecFails=0;

		if ( event == DETECTED )
		{


			if ( stardata.outputOptions & DUALED )
			{

				if( ++consecPassingCount > 99  && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter
				{
					RED_LED_OFF;
					GREEN_LED_ON;
					return;
				}

				if( timeLimit > 0  && !(EXT_INPUT))
				{
					// evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led
					// else turn on green led
					TA0CCR0 = 0;
					i=TA0R;

					if ( i  > timeLimit )
					{
						RED_LED_ON;
						GREEN_LED_OFF;
					}
					else
					{
						GREEN_LED_ON;
						RED_LED_OFF;
					}
				}
				else
				{
					RED_LED_OFF;
					GREEN_LED_ON;
					timer_us(50);
					GREEN_LED_OFF;
				}

				consecFails=0;
			}


		}
		else if ( event==NOT_DETECTED)
		{
			passingCount+=consecPassingCount;
			if ( consecPassingCount > maxConsecPassingCount )   // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed.
			{
				maxConsecPassingCount = consecPassingCount;
			}
			consecPassingCount=0;


			if ( passingCount > PASSCOUNTERTHRESHOLD)  // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led.
			{
				passingCount=0;
				timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150;  // amount of time which is allowed between non detect intervals.
				maxConsecPassingCount=0;
			}
			if ( timeLimit > 0 && consecFails == 0 )				// start timer
			{
				TA0R=0;
				TA0CCR0 = 5000;
			}

			if ( consecFails > 100)
			{
				GREEN_LED_OFF;
				RED_LED_ON;
				return;
			}
				//consecFails=0;
			else ++consecFails;
		}


	}

I defined the timer used in the interrupt function in the main.c file as follows:

TA2CCTL0=CCIE;

TA2CTL=TASSEL_2+MC_3+ID__8; 

TA2CCR0=125000;

This is the code with the interrupt function replacing RED_LED_ON output:

   void display( char  event , char test )

{

int j,i;

static int maxConsecPassingCount=0;

static int consecPassingCount=0; //kg 8/16

static int passingCount=0; //kg 8/16

static int timeLimit=0;   // amount of time allowed for non detection before failure is asserted.

static int consecFails=0;

if ( event == DETECTED )

{

if ( stardata.outputOptions & DUALED )

{

if( ++consecPassingCount > 99  && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter

{

RED_LED_OFF;

GREEN_LED_ON;

return;

}

if( timeLimit > 0  && !(EXT_INPUT))

{

// evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led

// else turn on green led

TA0CCR0 = 0;

i=TA0R;

if ( i  > timeLimit )

{

#pragma vector=TIMER1_A1_VECTOR  //kg

__interrupt void TIMER1_A1ISR (void)

{

RED_LED_ON;

GREEN_LED_OFF;

}

}

else

{

GREEN_LED_ON;

RED_LED_OFF;

}

}

else

{

RED_LED_OFF;

GREEN_LED_ON;

timer_us(50);

GREEN_LED_OFF;

}

consecFails=0;

}

}

else if ( event==NOT_DETECTED)

{

passingCount+=consecPassingCount;

if ( consecPassingCount > maxConsecPassingCount )   // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed.

{

maxConsecPassingCount = consecPassingCount;

}

consecPassingCount=0;

if ( passingCount > PASSCOUNTERTHRESHOLD)  // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led.

{

passingCount=0;

timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150;  // amount of time which is allowed between non detect intervals.

maxConsecPassingCount=0;

}

if ( timeLimit > 0 && consecFails == 0 )// start timer

{

TA0R=0;

TA0CCR0 = 5000;

}

if ( consecFails > 100)

{

#pragma vector=TIMER1_A1_VECTOR  //kg

__interrupt void TIMER1_A1ISR (void)

{

RED_LED_ON;

GREEN_LED_OFF;

}

}

//consecFails=0;

else ++consecFails;

}

   }

I can't get the code to compile and I can't find a forum that discusses adding interrupts that are controlled in the same way I am using them.  Does anyone have any ideas as to what I am doing wrong?

   void display( char  event , char test ){int j,i;
static int maxConsecPassingCount=0;static int consecPassingCount=0; //kg 8/16static int passingCount=0; //kg 8/16static int timeLimit=0;   // amount of time allowed for non detection before failure is asserted.static int consecFails=0;
if ( event == DETECTED ){

if ( stardata.outputOptions & DUALED ){
if( ++consecPassingCount > 99  && !(EXT_INPUT)) // if no detection for long period , assume no motion and just reset counter{RED_LED_OFF;GREEN_LED_ON;return;}
if( timeLimit > 0  && !(EXT_INPUT)){// evaluate whether the time limit has been violated by stopping timer and reading counter, reset counter for next time. if limit exceeded turn on red led// else turn on green ledTA0CCR0 = 0;i=TA0R;
if ( i  > timeLimit ){
#pragma vector=TIMER1_A1_VECTOR  //kg__interrupt void TIMER1_A1ISR (void){RED_LED_ON;GREEN_LED_OFF;}
}else{GREEN_LED_ON;RED_LED_OFF;}}else{RED_LED_OFF;GREEN_LED_ON;timer_us(50);GREEN_LED_OFF;}
consecFails=0;}

}else if ( event==NOT_DETECTED){passingCount+=consecPassingCount;if ( consecPassingCount > maxConsecPassingCount )   // find maximum string of consecutive passing tests out of a group <PASSCOUNTERTHRESHOLD> of tests to estimate the speed.{maxConsecPassingCount = consecPassingCount;}consecPassingCount=0;

if ( passingCount > PASSCOUNTERTHRESHOLD)  // we should have enough data to predict the speed, so now calculate the maximum failing time allowed before we set the fail led.{passingCount=0;timeLimit= maxConsecPassingCount * stardata.starLimits[test].hiTestLimit2; //150;  // amount of time which is allowed between non detect intervals.maxConsecPassingCount=0;}if ( timeLimit > 0 && consecFails == 0 )// start timer{TA0R=0;TA0CCR0 = 5000;}
if ( consecFails > 100){#pragma vector=TIMER1_A1_VECTOR  //kg__interrupt void TIMER1_A1ISR (void){RED_LED_ON;GREEN_LED_OFF;}}//consecFails=0;else ++consecFails;}
   }


msp430f5529 ADC12 Reading error

$
0
0

I 'm testing the ADC12 module on msp430f5529. I have a very simple program for debugging purpose. I'm setting the reference voltage to be 2.5V and the resolution is 12 bits. I'm expecting to see 0V~2.5V resulting in 0~4095. However any voltage input above around 1.45V will be converted as 1.45V. It seems there is a saturation somewhere. I'm not sure how to solve this problem. Help needed! Thanks. Here is my code:

#include <msp430.h>
unsigned int test;

int main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                 
  P6SEL |= 0x01;     

                      
  REFCTL0 &= ~REFMSTR;

  ADC12CTL0 = ADC12ON + ADC12SHT0_8 + ADC12REFON + ADC12REF2_5V;
  ADC12CTL1 = ADC12SHP + ADC12DIV_1;
  ADC12CTL2 = ADC12REFOUT + ADC12RES_2;
  ADC12MCTL0 = ADC12SREF_1;                

  __delay_cycles(100);

  ADC12CTL0 |= ADC12ENC;                    // Enable conversions

  while (1)
  {
    ADC12CTL0 |= ADC12SC;                   // Start conversion
    while (!(ADC12IFG & BIT0));
    test = ADC12MEM0;
    __no_operation();                       // SET BREAKPOINT HERE

  }

  return 0;
}

MSP430F5529 Launch Pad powered by alkaline batteries

$
0
0

I am trying to power a MSP430F5529 launch pad using alkaline batteries but not sure if I need a DC/DC converter to convert the voltage to exactly 3.3 V (while two 1.5-V batteries give 3V). The manual says when using something that is not exactly 3.3V care has to be taken (remove certain jumpers) to prevent damage to the emulator. But is it the only problem a 3V power supply would cause? Will the rest of the board function properly with a 3V supply plugged to the 3.3V pin? Is there any additional regulators inside the circuit to convert 3V to 3.3V?

UART continuous transmission of request bytes

$
0
0

Hello everyone!

I'm currently working on a project which requires MSP430 to send a set of bytes to an energy meter IC to get the readings for current, voltage,power etc. So I need these readings in regular intervals say 5mins. Also I'll be using this in the ultra low power mode. Can you give me some advice as to how to go about this project, keeping in mind that low power is the primary reason for using MSP430.

Some of the technical doubts I have is :

1) Should I use a while(1) loop to continuosly sent values or should I use timers?

2) I know that low power is achieved by using interrupts. What are the best practices to follow while doing this 

MSP430FR5859 eUSCI I2C slave rise/fall time spec.

$
0
0

Hi all,

My customer is asking for the rise/fall timing specification of MSP430FR5859 eUSCI I2C slave mode, I don't find this information on datasheet.

Picture below is the I2C slave timing specification of competitor;s MCU for reference, please advise where can I get this information, thanks.

Regards,

Luke

How to use USBRAM as Main RAM in MSP430F5529

$
0
0

 HI

     The MSP430F5529 Datasheet shows the chip has a 2K USB RAM, in any usb demo like C3_EchoToHost Demo,

after build Memory configuration shows USBRAM used is 00000000, so can I using this 2K RAM as Main RAM .

Lin Kejian

RTCHOLD bit effect on RTC module

$
0
0

Hi,

I am using MSP430F67791A, I had created separate code boot code and application code.

In Boot code, I am not doing any low level driver initialisation (RTC),

If  there is power cycle during boot code execution, then RTCHOLD will get set. WIll this create any impact on RTC module? if so, How?

Thanks

Girish S

General ADC questions

$
0
0

Hi,

While talking to a customer about developing inclinometer based on MS432P401M he brought up some interesting points which I could not answer right away (I am basically mechanical engineer)

1. When talking about ADCs the mentioned resolution is 14 bit but do we actually get that much resolution or do we lose the LSB? The datasheets for MCUs of some competing companies mention the  No Code Loss ADC resolution but TI does not do that.

2. What are the drawbacks of ADC oversampling? Can I oversample it just enough to make up for the loss of LSB?


What do you mean "Vcc" at LCD Controller in MSP430F6726A?

$
0
0

Hello.

I have a question.

In the 34.2.5.1 section , page 875 ,following URL : MSP430x5xx and MSP430x6xx Family User's Guide,

"Vcc" and "DVcc" is described.

http://www.tij.co.jp/jp/lit/ug/slau208o/slau208o.pdf

What do you mean "Vcc"?

Otherwise, What does "Vcc" source from?(DVcc? AVcc?)

I could not find "Vcc" pin other than "DVcc" pin and "AVCC" pin in the datasheet .

Please help.

Regards,

uchida-k

UART TX transmission failed

$
0
0

I used MSP430F5529 and these two files to do UART transmission. (TX:PIN3.3, RX:PIN3.4 )

and my CCS version is 6.1.2 .

However, I could not enter main section.

(Please visit the site to view this file)(Please visit the site to view this file)

And I also used Acute Logic Analyzer to monitor the output of TX for debugging,

but I still could not see the packet to be sent ( txPkt[1] = {0x0f}; ) .

Please help me to see what I should do to edit my code and make it work. Thank you :)  

Captivate BSWP-DEMO issue in compiling

$
0
0

Hi Everybdoy , 

please  I am on latest  Captivate Ddesign Center  1_30_10_00   and very latest CCS   ( updated now   6.1.2 ) 

I am importing  BSWP-DEMO example  , then clean and  Build  and  I get this error :

"C:/ti/ccsv6/ccs_base/msp430/include/msp430.h", line 1784: fatal error #35: #error directive: "Failed to match a default include file"
1 catastrophic error detected in the compilation of "../captivate/ADVANCED/CAPT_Manager.c".
Compilation terminated.

where am I wrong ?

thank you 

bye

Carlo

MSP430G2303 LaunchPad, Energia ERROR 0451:f432

$
0
0

hi everyone, I got a problem with my MSP430 launchpad and Energia. When i try to upload the new sketch to my MCU, i got the following error :  

"0451:f432 An error occurred while uploading the sketch"

i'm sure my MSP is connected with the usb cable included in the box, it is also connected to a COM port, and it is recognised by energia

which will be the problem?

thank you for your support

msp432 rtc RT1PSIFG

$
0
0

Hi all,

could i have an example about rtc prescaler? In particular i need an example with RT1PSIFG. In the texas example of msp432 there is not an example with led blink 1 second period (or other) using rtc prescaler. 

Thanks for help,

Luca

DLMS/ COSEM protocol support for MSP430F67791A

$
0
0

Hi,

We are using"TIDMTHREEPHASEMETER-F6779" source code for 3Phase 4Wire Energy Meter development. In our source code we need to support DLMS protocol to communicate with CMRI unit.

We would like to know whether "TIDMTHREEPHASEMETER-F6779" source code has support for DLMS protocol ?.If not we need the DLMS protocol source code for our development.

Please let us know any reference source code available from TI.

Thanks & Regards

Mohanmurali.M

About LCD controller Voltage in MSP430F6726A

$
0
0

Hello.

I have a question.

I am going to connect Battery to DVCC and AVCC pins and  work LCD Controller.

①I want to know changing current consumption in the Supply voltage.

 Do you have graphs or tables plotted Vcc vs  Icc?

 Any VLCD setting is fine.

②Which Should I set DVCC or AVCC sourced VLCD to minimize current consumption?

Regards,

uchida-k


MSP430 _Heating Effect while processing

$
0
0

Hello Everyone ,

We are using MSP430 for our application.We are monitoring case temperature of MSP430 using thermistor in a resistor divider.Its temperature is going upto 45 deg cel while the board is operating. Is it normal for a controller to have temperature increase like this ??

Thanks & Regards

Rajesh

MSP430FR5735 I2C Master receive problems using DriveLib for a battery charger IC

$
0
0

I am using an MSP430FR5735 Microcontroller to talk to a battery charger IC. The process is simple, send a data register byte for the location that you want to read from, then read one byte.

I call the function charger_read_reg and send the register location that I want to read.

charger_read_reg(0x0C); // read from the charger at the defined address

//*****************************************************************************
// initialize I2C TX
//*****************************************************************************
void init_I2C_TX(void)
{
    EUSCI_B_I2C_initMasterParam param = {0};// TX
    param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
    param.i2cClk = CS_getSMCLK();
    param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
    param.byteCounterThreshold = 1;
    param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
    EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
}

//*****************************************************************************
// initialize I2C RX
//*****************************************************************************
void init_I2C_RX(void)
{
    EUSCI_B_I2C_initMasterParam param = {0};// TX
    param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
    param.i2cClk = CS_getSMCLK();
    param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
    param.byteCounterThreshold = 1;
    param.autoSTOPGeneration = EUSCI_B_I2C_SEND_STOP_AUTOMATICALLY_ON_BYTECOUNT_THRESHOLD;
    EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
}

//*******************************************************************************************************************
// Charger read comms
//*******************************************************************************************************************
void charger_read_reg(C_REG_ADDR)       // read register routine for the charger
{

 init_I2C_TX();
 EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, CHARGER_SLAVE_READ_ADDRESS);  // Specify slave address
 EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);   // Set to transmit mode
 EUSCI_B_I2C_enable(EUSCI_B0_BASE);      // Enable I2C Module to start operations


 EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE, C_REG_ADDR);   //Send single byte data.(address of register to read)
 while(EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE))
     {
         ;
     }

 init_I2C_RX();
 EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, CHARGER_SLAVE_READ_ADDRESS);  //Specify slave address
     EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);    //Set Master to receive mode
     EUSCI_B_I2C_enable(EUSCI_B0_BASE);        //Enable I2C Module to start operations

     c_0x0C_r = EUSCI_B_I2C_masterReceiveSingleByte(EUSCI_B0_BASE);

}

What's happening is that the register data is sent,  a long 1mS delay ( I don't know why there is a delay) then the read address is sent and I never get a NACK or data returned.

I am not sure that I am switching between TX and RX I2C modes correctly. Any Ideas?

MSP430FR5994 LEARAM?

$
0
0

Working with the MSP430FR5994.. what is LEARAM used for? can i use it like normal ram? i was hoping to use the whole 8k ram.. 

 

    RAM                     : origin = 0x1C00, length = 0x1000

#define LEASTACK_SIZE 0x138

MEMORY
{
LEARAM : origin = 0x2C00, length = 0x1000 - LEASTACK_SIZE
LEASTACK : origin = 0x3C00 - LEASTACK_SIZE, length = LEASTACK_SIZE
}

msp432 timers

$
0
0

I WAS INTIALLY RECOMMENDED TMDSDOCK28035,  I WAS TOLD BY A DEVELOPPER THAT MAY BE AN OVERKILL AND SHOULD LOOK AT

THE MSP432.  MY TASK IS TO READ TIME INTERVAL FROM 2 EA EXTERNAL SIGNALS TTL AND MEASURE THE TIME INTERVAL FROM 200 NANO SECONDS TO 1 MILLISECOND IN CONSECUTIVE ADDRESSES UP TO 1000.  THEN IS WILL EXPORT SERIALLY TO ANOTHER COMPUTER.

WHICH ONE OF THE 2EA. PARTS WOULD BE BETTER AND SIMPLE.

20-Bit address msp430fr5994

$
0
0

I trying to make a pointer out of a long int.. 

on the msp430fr5959 this code works

char * Flash_ptr = (char *) 0x10000; 

but when i try this line on msp430fr5994 i get this error

Description Resource Path Location Type
#173-D invalid type conversion main.c /xxxx line 110 C/C++ Problem

Using CCS and the same compiler

How can i get this to work? Thank you

Viewing all 22138 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>