Jump to content
Sign in to follow this  
itaytamir

WDT interrupt doesnt work

Recommended Posts

hi everybody.

 

i'm having a problem with the WDT. i'm working with several interrupts, such as UCART,port1, and WDT.

the problem is while i'm inside the UCART interrupt routine, the watchdog wont interrupt.

 

for example:

 

#pragma vector=USCIAB0RX_VECTOR //describing the communication IR

__interrupt void USCIA0RX_ISR (void)

{

int i;

char Ch_received; //the recived Char

char Choice; //saves the user's choice from the PC menu

 

while(!(IFG2&UCA0RXIFG)); //waits untill Rx buffer is full

Choice = UCA0RXBUF; //gets the user choice (which mode to use)

 

switch (Choice) //choose a mode

{

case enter_timer:

 

while(1)

{

RX_ON;

while(!(IFG2&UCA0RXIFG)); <-------

Ch_received = UCA0RXBUF;

if (Ch_received == Exit) //if we get 'e' we

{

 

is the head of the routine. the program stays in the line marked with arrow, and never goes to the WDR IR routine.

 

this is the main program :

 

void main(void)

{

WDTCTL = WDTPW+WDTCNTCL+WDTSSEL+WDTTMSEL; // Set WatchDog to ACLK, reset WatchDog counter, one second intervals, Interval timer mode

FLL_CTL1 = 0x00; //ACLK

SCFI0 = 0xA0; // Divide by 8

IE1 = WDTIE; //Enable WDT interrupt

 

FLL_CTL0 |= XCAP14PF; // Configure load caps

 

// Select COM1-COM2-COM3- LCD controls

 

P2DIR |= 0x1E; // Ports P2.2, P2.3 and P2.4 as outputs

P2SEL |= 0x1E;

P5DIR |= 0x1E; // Ports P5.2, P5.3 and P5.4 as outputs

P5SEL |= 0x1E; // Ports P5.2, P5.3 and P5.4 as special function (COM1, COM2 and COM3)

 

// Active S4 to S25

LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4;

 

// LCDA configuration

LCDACTL = LCDFREQ_192 | LCD4MUX | LCDSON | LCDON; // (ACLK = 32768)/192,

//4-mux LCD, LCD_A on,

//Segments on

LCDAVCTL0 = LCDCPEN; // Charge pump enable

LCDAVCTL1 = VLCD_3_44; // VLCD = 3,44 V

 

// SW1 and SW2 ports configuration

P1SEL &= ~0x03; // P1.0 and P1.1 I/O ports, selelcts the secondary peripheral module function

P1DIR &= ~0x03; // P1.0 and P1.1 digital inputs

P1IFG = 0x00; // clear all interrupts pending

P1IE |= 0x03; // enable port interrupts

 

LCD_Clear();

 

P2SEL |= 0x030; // P2.5,4 = USCI_A0 RXD/TXD

UCA0CTL1 |= UCSSEL_1; // CLK = ACLK

UCA0BR0 = 0x03; // 32k/9600 = 3.33 (Round this value to 3)

UCA0BR1 = 0x00; //

UCA0MCTL = 0x06; // Modulation number 6 (table 19.2 pg. 560)

// 0-1-1-1-0-1-1-1

 

UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine

IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

 

LCD_Clear(); //intionlize LCD screen

_BIS_SR(LPM0_bits + GIE); // Enter LPM0, interrupts enabled

}

 

do you have idea? i've tried anything i thought of. thank a lot! (and sorry about the length of my Q.)

Share this post


Link to post
Share on other sites

hi

 

thanks a lot! that worked just fine. now i have a new problem, maybe you can help me again:

 

im trying to use the ADC. after so many hours, it's finely responded, but it allways gives me the same value- Vcc, ground, just name it, always gives FFF.

can you tell me what is i'm doing wrong?

 

these are the def. again:

 

 

//DAC config :data written, 1X reference, medium current, interrupt pending, DAC enabled
DAC12_0CTL = DAC12LSEL_0 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC; 


//ADC config


ADC12CTL0 = REFON + REF2_5V + ADC12ON + SHT0_2; // turn on 2.5V ref, set samp time
ADC12CTL1 = SHP;                          // Use sampling timer
ADC12MCTL0 = SREF_1;                      // Vr+=Vref+
for (i = 0x3600; i; i--);                 // Delay for needed ref start-up.
ADC12CTL0 |= ENC;                         // Enable conversions

//WDT congif
WDTCTL = WDTPW+WDTCNTCL+WDTSSEL+WDTTMSEL; 
IE1 = WDTIE;   
__bis_SR_register(GIE);//Enable WDT interrupt

//PORTS config
P6SEL |= 0x01;  // P6DIR|=0x01;// Enable A/D channel A0
P5DIR |= 0x1E;                                        // Ports P5.2, P5.3 and P5.4 as outputs
P5SEL |= 0x1E;                                        // Ports P5.2, P5.3 and P5.4 as special function (COM1, COM2 and COM3)
P2DIR |= 0x00;                  // Ports P2.2, P2.3 and P2.4 as outputs
P2SEL |= 0x00;     // Ports P2.2, P2.3 and P2.4 as special function (COM1, COM2 and COM3)
P2IFG|=0x00;
P2IE|=0xFF;
// SW1 and SW2 ports configuration  
P1SEL &= ~0x03;                                    // P1.0 and P1.1 I/O ports, selelcts the secondary peripheral module function
P1DIR &= ~0x03;                                    // P1.0 and P1.1 digital inputs
P1IFG = 0x00;                                      // clear all interrupts pending
P1IE |= 0x03;                                      // enable port interrupts 

P3DIR |=0xFF;										  // Ports P3.x as inputs
P3SEL |=0x00;										  // Ports P3.x as I/O

//LCD config

LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4; // Active S4 to S25
LCDACTL = LCDFREQ_192 | LCD4MUX | LCDSON | LCDON;  // (ACLK = 32768)/192, 4-mux LCD, LCD_A on,
LCDAVCTL0 = LCDCPEN;                               // Charge pump enable
LCDAVCTL1 = VLCD_3_44;                             // VLCD = 3,44 V

//USART config

P2SEL |= 0x030;                           // P2.5,4 = USCI_A0 RXD/TXD
UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK
UCA0BR0 = 0x03;                           // 32k/9600 = 3.33 (Round this value to 3)
UCA0BR1 = 0x00;                           //
UCA0MCTL = 0x06;                   // Modulation number 6 (table 19.2 pg. 560) 0-1-1-1-0-1-1-1  
UCA0CTL1 &= ~UCSWRST;                     // Initialize USCI state machine
IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

FLL_CTL1 = 0x00;                                      //ACLK
SCFI0 = 0xA0;                                         // Divide by 8
FLL_CTL0 |= XCAP14PF;                     // Configure load caps

 

and the routine is:

 

void ADC_Illumination (void)

{//performs a single conversion on channel A0. The conversion results are stored in ADC12MEM0.
ADC12CTL0 |= ADC12SC;                   // Start conversions
while (!(ADC12IFG & 0x0001));           // Conversion done?
Current_Light=ADC12MEM0;

 

at first it never went beyond the while loop, now it does, but as i said, with the same value over and over again.

 

i want the ADC to work without any timer, just triggered every loop. is that possible?

 

thanks a lot!

Share this post


Link to post
Share on other sites

At first: you don't specify the type of processor what you use. This is important information.

 

- I don't see anywhere in your code place, where you select the analog input. It is necessary to assign a concrete input pin to A/D converter. (...maybe A0 is default selected?)

 

And here is my advice: Go to TI homepage and search page of you processor. Into the page you will find "code examples" (it is ZIP file full of examples for how use of various parts of the processor). You use them as a basis for their experiments.

Share this post


Link to post
Share on other sites

sorry bluehash, i'll do it next time.thanks.

 

i'm using MSP430FG4618.

actually, I copied the code from the TI example.

as far as i understand, i defined port 6 as input, except for 6.0 which is output (the P6DIR was accidentally marked as comment.just here, the real code is OK)

P6.0 is using for the DAC, which actually works just fine. after i defined the rest of the ports as input, i've tried each port, none of them worked.

perhaps P6SEL should be 0xFF? or am i missing here something?

 

because of the fact the debugger succeeded to pass the loop, i assume the port is defined correctly. now i just dont understand why it doesnt change a all.

 

thanks again!

Share this post


Link to post
Share on other sites

You do not understand at all.

 

Each pin you want to use the ADC must be set with

P6SEL |= BITx;

EXAMPLE (set P6.2, P6.3 and P6.5 to use as analog inputs):

P6SEL |= BIT2 + BIT3 + BIT5;

P6DIR worked for digital input/output, not for analog!

 

And next you must set ADC multiplexer - select a pin that is connected to ADC input.

ADC12MCTL0 = SREF_1 + INCH_2;            // Channel A2 = P6.2, Vref+
//OR
ADC12MCTL0 = SREF_1 + INCH_3;            // Channel A3 = P6.3, Vref+
//ETC...

Only then you can run the ADC.

ADC12CTL0 |= ADC12SC;                   // Start conversions
while (!(ADC12IFG & 0x0001));           // Conversion done?
Your_Integer_variable=ADC12MEM0;

 

All these informations is in the TI examples!

 

And you need thoroughly reading [tipdf]SLAS508[/tipdf] and [tipdf]SLAU056[/tipdf] (at least the chapters dealing with the ADC).

Share this post


Link to post
Share on other sites

nobody, you're a life saver. thanks!

 

that actually made the trick.

 

if you can help me one last time, i'll be more than grateful

 

i'm trying to use the DMA to move info to the DAC, without success. as you recommended, i used the first example of using the DMA in TI examples, but it still doesnt work.

 

DTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
if (DTMF_Style == 0)
{
	DMA0SA = (int)Value;                    // Source block address
	DMA0DA =  DAC12_0DAT_;                     // Destination single address
	DMA0SZ = 0x00A;                           // Block size (10 decimal)
	DMACTL0 = DMA0TSEL_5;                     // DAC12IFG trigger
	DMACTL1 = ENNMI;					//enable non maskable IR
	DMA0CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
               DMA0CTL |= DMAEN;

               DMA0CTL |= DMAREQ;   
        __bis_SR_register(GIE);       // Enter LPM0

       }
else
{
	DMA0SA = (int)Value+DTMF_Style;                    // Source block address
	DMA0DA = DAC12_0DAT_;                     // Destination single address
	DMA0SZ = 0x001;                           // Block size (10 decimal)
	DMACTL0 = DMA0TSEL_5;                     // DAC12IFG trigger
	DMACTL1 = ENNMI;					//enable non maskable IR
	DMA0CTL = DMADT_4 + DMAEN;	 // Rpt, word-word
               DMA0CTL |= DMAEN;
               DMA0CTL |= DMAREQ;
       }     

 

when value[] is an array of interger, defined in the global section.

DTMF_Style gets value between 0-9.

 

when DTMF_S=0 i want the DMA to move the table to the DAC, repeatedly, in other case i want to use only one value of the array.

the trigger should be by request, and the DMA should stop working using the USART IR, as follows:

 

else if (DTMF_mode == 1)
{ //must be an Exit command
	DMA0CTL &= ~DMAEN;   // DMA disabled
	DTMF_mode = 0;
	Exit_Flag = 1;
	DAC12_0DAT=0x0; //light off
}

 

thanks a lot!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...