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.
Upon power-up, the controller will turn on the green and red LEDs. The LEDs will blink for 5 seconds before they are turned off. After initialization the controller will check the initial voltage level. If the input voltage is lower than 1.5V, the red LED will start blinking (a suitable blinking rate should be used to ensure human eyes' detection) for 15 seconds (it will be turned off after 15 seconds). Otherwise (i.e. input voltage > 1.5V), the green LED will blink. It will only stop blinking when the controller detects a press on the push button. While either green or red LED is on, any change when both LEDs are off. The LEDs should remain off as long as the input voltage does not cross the 1.5V threshold.
Voltages are: Max 3V and Min 1.5V
I had trouble initialization of this problem.when 1.5V takes place. i don't get the coding of how to continue from initialization the controller... while i manage to get both green and red LEDs and blinks for 5 seconds.
this is where i'm currently stuck at:
#include "msp430x22x4.h"
int rg = 0;
//psh = 0;
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL0 = SREF_0 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
P1DIR |= 0x01;
P1DIR |= 0x02;
P1OUT = 0x04;
P1REN = 0x04;
TACCTL0 = CCIE;
TACCR0 = 37500;
ADC10AE0 |= 0x01;
//P1IE = 0x04;
//P1IES = 0x04;
{
if (rg == 0)
{P1OUT |= 0x01; P1OUT |= 0x02;}
volatile unsigned int i;
i = 60000;
do i--;
while (i !=0);
rg = 0;
}
P1OUT |= 0x03;
TACTL = TASSEL_2 + MC_3 + ID_3;
__bis_SR_register(CPUOFF + GIE);
P1OUT &=~0x03;
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
if(ADC10MEM > 0x511.5) //Nadc = 1023 x ( Vin - Vr- / Vr+ - Vr- ) // Max 3V
{
P1OUT |= 0x01;
P1OUT &= 0xFD;
P1OUT &= ~0x04;
}
if(ADC10MEM < 0x511.5) //Nadc = 1023 x ( Vin - Vr- / Vr+ - Vr- ) // Min 1.5V
{
P1OUT |= 0x02;
P1OUT |= 0x04;
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void PORT1_A (void) //Timer subroutine effects the blinking LEDs
{
rg++;
if(rg == 10)
{TACTL = 0; TACCTL0 &= ~CCIE; __bic_SR_register_on_exit(CPUOFF);}
else
{P1OUT ^= 0x03;} //both LED
}
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_A (void)
{
__bic_SR_register_on_exit(CPUOFF);
if (ADC10MEM > 511.5)
{}
else if(ADC10MEM < 511.5)
{}
}
Can tell me what can be change or what can be added?
What does 0x511.5 mean? Are you sure that the code pasted correctly?
Did you try to use Grace?
I use NADC = 1023 x (Vin - VR- / VR+ - VR-) = 1023 x (3 - 1.5 / 1.5 - (-1.5)) = 511.5
You should click the link and read what Grace is for. e2e automatically create links to TI products when they are mentioned.
I recommend starting with: http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/256616/898182.aspx#898182. You will find there classes on data conversion.
There is no such thing in C language as 0x1234.5.
Good luck,
Maciej
MSP4302274 does not exist. I guess you are using a MSP430F2274.
You did not say how the LEDs are connected to the chip. I guess one of them is connected to P1.1; but I hope the other one is not connected to P1.0
You did not say how the “voltage” is connected to the chip either. There are some hints that it may have been connected to P1.0.
You did not say what compiler you are using. All the compilers I know of cannot compile the code you posted. My guess is, you are not posting the actual code.
Even if the compiler you used understands you, it does not matter whether the "voltage" is greater or less than 1.5V. You did nothing in either case.
Upon power-up, the controller will turn on the green and red LEDs. The LEDs will blink for 5 seconds before they are turned off. After initialization the controller will check the initial voltage level. If the input voltage is lower than 1.5V, the red LED will start blinking (a suitable blinking rate should be used to ensure human eyes' detection) for 15 seconds (it will be turned off after 15 seconds). Otherwise (i.e. input voltage > 1.5V), the green LED will blink. It will only stop blinking when the controller detects a press on the push button. While either green or red LED is on, any change when both LEDs are off. The LEDs should remain off as long as the input voltage does not cross the 1.5V threshold.
That sounds very suspiciously like a homework assignment - is it?
http://www.catb.org/~esr/faqs/smart-questions.html#homework
Mark Wong2 said:i don't get the coding
Do you mean that you have been provided with code, and you don't understand it?
Or that you don't "get" how to write the code?
If the latter, what have you done before attempting to write any code?
Coding should be the final step of the process - after you have thoroughly analysed the problem and designed a solution.
How have you been taught to design your solution: flowcharts? state diagrams? - or what?
Mark Wong2 said:if(ADC10MEM > 0x511.5) //Nadc = 1023 x ( Vin - Vr- / Vr+ - Vr- )
There are several 'C' syntax errors in there:
Perhaps some basic 'C' references would help: http://blog.antronics.co.uk/2010/12/12/things-you-shouldve-learned-in-c-class-0-introduction/
i'm sorry and yes its my assignment. but i really really stuck at it. i have been stuck at it for 2 weeks. yes i don't understand and don't get how to continue from the last part i left off. from ADC interrupt. how to make it blink for 15 seconds. No attempts done. this is my first time writing this program. have never learn this program before other than C#, C++, and C. i'm using IAR Embedded Workbrench. I apologies for posting assignment on the forum.
Your kit runs on msp430f2274. You can find examples for this chip in CCS installation directory (download free version at http://www.ti.com/tool/ccstudio) [...]\ccsv5\ccs_base\msp430\msp430ware_1_25_00_30\examples\devices\2xx\MSP430F22x2, MSP430F22x4 Code Examples\C. There are 21 sample c files for ADC.
First start making LEDs blink as you like. Then try to run one of the ADC examples from the directory. If you have further issues I recommend looking into Teaching ROM that I posted link to before.
Good luck with your placement,
Maciej
**Attention** This is a public forum