EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Clock problem

Started by "Breno T. Minzon" November 22, 2006
Hi everyone!!!

I'm begining using msp430. I need to count pulses of a quadracture encoder and show in a lcd 16x4. My counter is OK, my LCD functions are ok. But the program only runs 1 time. I think my clock isn't correct. PLease help me. I need to use DCO 16Mhz, without any aditional crystal.

int main( void )
{

unsigned char i;

// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;

//(DCO) 16Mhz
BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to configure any other parameter to use this clock?
DCOCTL = (unsigned char)CALDCO_16MHZ_;

// Set P1.0 a P1.6 (LCD)
//P1.7 = entrada (reset)
//P2 = entrada (encoder)
P1SEL = 0;
P1OUT = 0x00;
P1DIR = 0xfe;

//Porta 2: Input
P2SEL = 0;
P2DIR = 0x00;

// Habilita interrupo na porta 2
P2IE = 0xc0;

// Porta 2: interrupo de zero para um
P2IES = 0;

//Limpa flag de interrupo
P2IFG = 0;

//inicializa LCD
lcd_init();

//inicializa contador
contador = 0;

//While the universe exists
while(1)
{

//Habilita Interrupo
_EINT();

//Converte o contador em cigo ASCII e armazena no buffer
intToAscii(contador);

//escreve o buffer no display
escreveLinha(buffer,LINHA_1);

//preenche com espa em branco a linha 2
escreveLinha(" ",LINHA_2);

}
}

__interrupt void p2_isr(void)
{

_DINT();
contador++;

//Habilita nova interrupo
P2IFG = 0;

_EINT();

}

Thanks a lot,

Breno

Beginning Microcontrollers with the MSP430

(1) Check to make sure CALBC1_16MHZ and CALDCO_16MHZ are
not erased or altered.

(2) If you set BIT4 of both of P1SEL and P1DIR to 1, you
should be able to see SMCLK at P1.4 with an oscilloscope.

(3) If you do not have a watch crystal, you should either
turn on VLOCLK by "BCSCTL3=0x20;" or turn off the oscillator
by "_BIS_SR(OSCOFF);".

(4) Have omitted: "#pragma VETOR=PORT2_VECTOR;"?

--- In m..., "Breno T. Minzon" wrote:
>
> Hi everyone!!!
>
> I'm begining using msp430. I need to count pulses of a
quadracture encoder and show in a lcd 16x4. My counter is OK, my LCD
functions are ok. But the program only runs 1 time. I think my clock
isn't correct. PLease help me. I need to use DCO 16Mhz, without any
aditional crystal.
>
> int main( void )
> {
>
> unsigned char i;
>
> // Stop watchdog timer
> WDTCTL = WDTPW + WDTHOLD;
>
> //(DCO) 16Mhz
> BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to configure
any other parameter to use this clock?
> DCOCTL = (unsigned char)CALDCO_16MHZ_;
>
> // Set P1.0 a P1.6 (LCD)
> //P1.7 = entrada (reset)
> //P2 = entrada (encoder)
> P1SEL = 0;
> P1OUT = 0x00;
> P1DIR = 0xfe;
>
> //Porta 2: Input
> P2SEL = 0;
> P2DIR = 0x00;
>
> // Habilita interrupo na porta 2
> P2IE = 0xc0;
>
> // Porta 2: interrupo de zero para um
> P2IES = 0;
>
> //Limpa flag de interrupo
> P2IFG = 0;
>
> //inicializa LCD
> lcd_init();
>
> //inicializa contador
> contador = 0;
>
> //While the universe exists
> while(1)
> {
>
> //Habilita Interrupo
> _EINT();
>
> //Converte o contador em cigo ASCII e armazena no buffer
> intToAscii(contador);
>
> //escreve o buffer no display
> escreveLinha(buffer,LINHA_1);
>
> //preenche com espa em branco a linha 2
> escreveLinha(" ",LINHA_2);
>
> }
> }
>
> __interrupt void p2_isr(void)
> {
>
> _DINT();
> contador++;
>
> //Habilita nova interrupo
> P2IFG = 0;
>
> _EINT();
>
> }
>
> Thanks a lot,
>
> Breno
>
>
>
Hi, thanks for reply. In my code, i not forfget the pragma, i miss in the
email. I really forget the "_BIS_SR(OSCOFF)" comand. I also notice in your
reply that you write "CALBC1_16MHZ" and "CALDCO_16MHZ ". In my project i put
"CALBC1_16MHZ_" and "CALDCO_16MHZ_ ". The compiler i used, IAR, accept both,
but the second one pair, a warning massage like "integer conversion results
in truncation". The first one pair nothing appears. What is the difference?
by the way, i turned off the xtal, but nothing happens. Thanks again

best regards

Breno

----- Original Message -----
From: "old_cow_yellow"
To:
Sent: Thursday, November 23, 2006 3:30 AM
Subject: [msp430] Re: Clock problem
(1) Check to make sure CALBC1_16MHZ and CALDCO_16MHZ are
not erased or altered.

(2) If you set BIT4 of both of P1SEL and P1DIR to 1, you
should be able to see SMCLK at P1.4 with an oscilloscope.

(3) If you do not have a watch crystal, you should either
turn on VLOCLK by "BCSCTL3=0x20;" or turn off the oscillator
by "_BIS_SR(OSCOFF);".

(4) Have omitted: "#pragma VETOR=PORT2_VECTOR;"?

--- In m..., "Breno T. Minzon" wrote:
>
> Hi everyone!!!
>
> I'm begining using msp430. I need to count pulses of a
quadracture encoder and show in a lcd 16x4. My counter is OK, my LCD
functions are ok. But the program only runs 1 time. I think my clock
isn't correct. PLease help me. I need to use DCO 16Mhz, without any
aditional crystal.
>
> int main( void )
> {
>
> unsigned char i;
>
> // Stop watchdog timer
> WDTCTL = WDTPW + WDTHOLD;
>
> //(DCO) 16Mhz
> BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to configure
any other parameter to use this clock?
> DCOCTL = (unsigned char)CALDCO_16MHZ_;
>
> // Set P1.0 a P1.6 (LCD)
> //P1.7 = entrada (reset)
> //P2 = entrada (encoder)
> P1SEL = 0;
> P1OUT = 0x00;
> P1DIR = 0xfe;
>
> //Porta 2: Input
> P2SEL = 0;
> P2DIR = 0x00;
>
> // Habilita interrupo na porta 2
> P2IE = 0xc0;
>
> // Porta 2: interrupo de zero para um
> P2IES = 0;
>
> //Limpa flag de interrupo
> P2IFG = 0;
>
> //inicializa LCD
> lcd_init();
>
> //inicializa contador
> contador = 0;
>
> //While the universe exists
> while(1)
> {
>
> //Habilita Interrupo
> _EINT();
>
> //Converte o contador em cigo ASCII e armazena no buffer
> intToAscii(contador);
>
> //escreve o buffer no display
> escreveLinha(buffer,LINHA_1);
>
> //preenche com espa em branco a linha 2
> escreveLinha(" ",LINHA_2);
>
> }
> }
>
> __interrupt void p2_isr(void)
> {
>
> _DINT();
> contador++;
>
> //Habilita nova interrupo
> P2IFG = 0;
>
> _EINT();
>
> }
>
> Thanks a lot,
>
> Breno
>
>
>

Yahoo! Groups Links

_______________________________________________________
Yahoo! Acesso Gris - Internet rida e gris. Instale
o discador agora!
http://br.acesso.yahoo.com
__interrupt void p2_isr(void)
{
_DINT();
contador++;
//Habilita nova interrupo
P2IFG = 0;
_EINT();
}

You dont need to disable INT on entry and re-enable INTs on exit of an ISR.
The MSP430 automatically globally disables INTs when it vectors to an interrupt
(SR is pushed and then GIE is reset to = 0)

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of Breno T. Minzon
Sent: Thursday, 23 November 2006 4:49 AM
To: m...
Subject: [msp430] Clock problem

Hi everyone!!!

I'm begining using msp430. I need to count pulses of a quadracture encoder and show in a lcd
16x4. My counter is OK, my LCD functions are ok. But the program only runs 1 time. I think my
clock isn't correct. PLease help me. I need to use DCO 16Mhz, without any aditional crystal.

int main( void )
{

unsigned char i;

// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;

//(DCO) 16Mhz
BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to configure any other parameter to use
this clock?
DCOCTL = (unsigned char)CALDCO_16MHZ_;

// Set P1.0 a P1.6 (LCD)
//P1.7 = entrada (reset)
//P2 = entrada (encoder)
P1SEL = 0;
P1OUT = 0x00;
P1DIR = 0xfe;

//Porta 2: Input
P2SEL = 0;
P2DIR = 0x00;

// Habilita interrupo na porta 2
P2IE = 0xc0;

// Porta 2: interrupo de zero para um
P2IES = 0;

//Limpa flag de interrupo
P2IFG = 0;

//inicializa LCD
lcd_init();

//inicializa contador
contador = 0;

//While the universe exists
while(1)
{

//Habilita Interrupo
_EINT();

//Converte o contador em cigo ASCII e armazena no buffer
intToAscii(contador);

//escreve o buffer no display
escreveLinha(buffer,LINHA_1);

//preenche com espa em branco a linha 2
escreveLinha(" ",LINHA_2);

}
}

__interrupt void p2_isr(void)
{

_DINT();
contador++;

//Habilita nova interrupo
P2IFG = 0;

_EINT();

}

Thanks a lot,

Breno



Yahoo! Groups Links
I think I found a problem. (I missed it the first time.)

You should have used "CALBC1_16MHZ" and "CALDCO_16MHZ".
You could have used "(const)CALBC1_16MHZ_" and
"(const)CALDCO_16MHZ_" too.
But "(unsigned char)CALBC1_16MHZ_" and
"(unsigned char)CALDCO_16MHZ_" are incorrect.

Note that these two "const" are stored in Info-Flash
and could have been erased or altered by accident!
You need to check them during debugging. (Just inspect
memory location 0x10F8 to 0x10FF. Or, alternatively,
single step and examine BCSCTL1 and DCOCTL registers.)

Other issues: (a) Microbit is right, you do not need the
"_DINT();" and "_EINT();" inside the interrupt routine.
(b) you can move the "_EINT();" from inside to in front
of "while (1) {...}".

--- In m..., "Breno T. Minzon" wrote:
>
> Hi, thanks for reply. In my code, i not forfget the pragma, i miss
in the
> email. I really forget the "_BIS_SR(OSCOFF)" comand. I also notice
in your
> reply that you write "CALBC1_16MHZ" and "CALDCO_16MHZ ". In my
project i put
> "CALBC1_16MHZ_" and "CALDCO_16MHZ_ ". The compiler i used, IAR,
accept both,
> but the second one pair, a warning massage like "integer conversion
results
> in truncation". The first one pair nothing appears. What is the
difference?
> by the way, i turned off the xtal, but nothing happens. Thanks again
>
> best regards
>
> Breno
>
> ----- Original Message -----
> From: "old_cow_yellow"
> To:
> Sent: Thursday, November 23, 2006 3:30 AM
> Subject: [msp430] Re: Clock problem
> (1) Check to make sure CALBC1_16MHZ and CALDCO_16MHZ are
> not erased or altered.
>
> (2) If you set BIT4 of both of P1SEL and P1DIR to 1, you
> should be able to see SMCLK at P1.4 with an oscilloscope.
>
> (3) If you do not have a watch crystal, you should either
> turn on VLOCLK by "BCSCTL3=0x20;" or turn off the oscillator
> by "_BIS_SR(OSCOFF);".
>
> (4) Have omitted: "#pragma VETOR=PORT2_VECTOR;"?
>
> --- In m..., "Breno T. Minzon" wrote:
> >
> > Hi everyone!!!
> >
> > I'm begining using msp430. I need to count pulses of a
> quadracture encoder and show in a lcd 16x4. My counter is OK, my LCD
> functions are ok. But the program only runs 1 time. I think my clock
> isn't correct. PLease help me. I need to use DCO 16Mhz, without any
> aditional crystal.
> >
> > int main( void )
> > {
> >
> > unsigned char i;
> >
> > // Stop watchdog timer
> > WDTCTL = WDTPW + WDTHOLD;
> >
> > //(DCO) 16Mhz
> > BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to
configure
> any other parameter to use this clock?
> > DCOCTL = (unsigned char)CALDCO_16MHZ_;
> >
> > // Set P1.0 a P1.6 (LCD)
> > //P1.7 = entrada (reset)
> > //P2 = entrada (encoder)
> > P1SEL = 0;
> > P1OUT = 0x00;
> > P1DIR = 0xfe;
> >
> > //Porta 2: Input
> > P2SEL = 0;
> > P2DIR = 0x00;
> >
> > // Habilita interrupo na porta 2
> > P2IE = 0xc0;
> >
> > // Porta 2: interrupo de zero para um
> > P2IES = 0;
> >
> > //Limpa flag de interrupo
> > P2IFG = 0;
> >
> > //inicializa LCD
> > lcd_init();
> >
> > //inicializa contador
> > contador = 0;
> >
> > //While the universe exists
> > while(1)
> > {
> >
> > //Habilita Interrupo
> > _EINT();
> >
> > //Converte o contador em cigo ASCII e armazena no buffer
> > intToAscii(contador);
> >
> > //escreve o buffer no display
> > escreveLinha(buffer,LINHA_1);
> >
> > //preenche com espa em branco a linha 2
> > escreveLinha(" ",LINHA_2);
> >
> > }
> > }
> >
> > __interrupt void p2_isr(void)
> > {
> >
> > _DINT();
> > contador++;
> >
> > //Habilita nova interrupo
> > P2IFG = 0;
> >
> > _EINT();
> >
> > }
> >
> > Thanks a lot,
> >
> > Breno
> >
> >
> >
> Yahoo! Groups Links
>
>
> _______________________________________________________
> Yahoo! Acesso Gris - Internet rida e gris. Instale
> o discador agora!
> http://br.acesso.yahoo.com
>
ok, now is ok. Thanks a lot for the help. Thanks all too!!!

regards

Breno

----- Original Message -----
From: "old_cow_yellow"
To:
Sent: Thursday, November 23, 2006 3:06 PM
Subject: [msp430] Re: Clock problem
I think I found a problem. (I missed it the first time.)

You should have used "CALBC1_16MHZ" and "CALDCO_16MHZ".
You could have used "(const)CALBC1_16MHZ_" and
"(const)CALDCO_16MHZ_" too.
But "(unsigned char)CALBC1_16MHZ_" and
"(unsigned char)CALDCO_16MHZ_" are incorrect.

Note that these two "const" are stored in Info-Flash
and could have been erased or altered by accident!
You need to check them during debugging. (Just inspect
memory location 0x10F8 to 0x10FF. Or, alternatively,
single step and examine BCSCTL1 and DCOCTL registers.)

Other issues: (a) Microbit is right, you do not need the
"_DINT();" and "_EINT();" inside the interrupt routine.
(b) you can move the "_EINT();" from inside to in front
of "while (1) {...}".

--- In m..., "Breno T. Minzon" wrote:
>
> Hi, thanks for reply. In my code, i not forfget the pragma, i miss
in the
> email. I really forget the "_BIS_SR(OSCOFF)" comand. I also notice
in your
> reply that you write "CALBC1_16MHZ" and "CALDCO_16MHZ ". In my
project i put
> "CALBC1_16MHZ_" and "CALDCO_16MHZ_ ". The compiler i used, IAR,
accept both,
> but the second one pair, a warning massage like "integer conversion
results
> in truncation". The first one pair nothing appears. What is the
difference?
> by the way, i turned off the xtal, but nothing happens. Thanks again
>
> best regards
>
> Breno
>
> ----- Original Message -----
> From: "old_cow_yellow"
> To:
> Sent: Thursday, November 23, 2006 3:30 AM
> Subject: [msp430] Re: Clock problem
> (1) Check to make sure CALBC1_16MHZ and CALDCO_16MHZ are
> not erased or altered.
>
> (2) If you set BIT4 of both of P1SEL and P1DIR to 1, you
> should be able to see SMCLK at P1.4 with an oscilloscope.
>
> (3) If you do not have a watch crystal, you should either
> turn on VLOCLK by "BCSCTL3=0x20;" or turn off the oscillator
> by "_BIS_SR(OSCOFF);".
>
> (4) Have omitted: "#pragma VETOR=PORT2_VECTOR;"?
>
> --- In m..., "Breno T. Minzon" wrote:
> >
> > Hi everyone!!!
> >
> > I'm begining using msp430. I need to count pulses of a
> quadracture encoder and show in a lcd 16x4. My counter is OK, my LCD
> functions are ok. But the program only runs 1 time. I think my clock
> isn't correct. PLease help me. I need to use DCO 16Mhz, without any
> aditional crystal.
> >
> > int main( void )
> > {
> >
> > unsigned char i;
> >
> > // Stop watchdog timer
> > WDTCTL = WDTPW + WDTHOLD;
> >
> > //(DCO) 16Mhz
> > BCSCTL1 = (unsigned char)CALBC1_16MHZ_; //Do i need to
configure
> any other parameter to use this clock?
> > DCOCTL = (unsigned char)CALDCO_16MHZ_;
> >
> > // Set P1.0 a P1.6 (LCD)
> > //P1.7 = entrada (reset)
> > //P2 = entrada (encoder)
> > P1SEL = 0;
> > P1OUT = 0x00;
> > P1DIR = 0xfe;
> >
> > //Porta 2: Input
> > P2SEL = 0;
> > P2DIR = 0x00;
> >
> > // Habilita interrupo na porta 2
> > P2IE = 0xc0;
> >
> > // Porta 2: interrupo de zero para um
> > P2IES = 0;
> >
> > //Limpa flag de interrupo
> > P2IFG = 0;
> >
> > //inicializa LCD
> > lcd_init();
> >
> > //inicializa contador
> > contador = 0;
> >
> > //While the universe exists
> > while(1)
> > {
> >
> > //Habilita Interrupo
> > _EINT();
> >
> > //Converte o contador em cigo ASCII e armazena no buffer
> > intToAscii(contador);
> >
> > //escreve o buffer no display
> > escreveLinha(buffer,LINHA_1);
> >
> > //preenche com espa em branco a linha 2
> > escreveLinha(" ",LINHA_2);
> >
> > }
> > }
> >
> > __interrupt void p2_isr(void)
> > {
> >
> > _DINT();
> > contador++;
> >
> > //Habilita nova interrupo
> > P2IFG = 0;
> >
> > _EINT();
> >
> > }
> >
> > Thanks a lot,
> >
> > Breno
> >
> >
> >
> Yahoo! Groups Links
> _______________________________________________________
> Yahoo! Acesso Gris - Internet rida e gris. Instale
> o discador agora!
> http://br.acesso.yahoo.com
>

Yahoo! Groups Links

_______________________________________________________
Yahoo! Acesso Gris - Internet rida e gris. Instale
o discador agora!
http://br.acesso.yahoo.com

Memfault Beyond the Launch