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.

msp430 multiple timer delay

Other Parts Discussed in Thread: MSP430G2553

hi, I'm new in area of msp430..maybe my english is not good but ı will try explain what is my problem...ı need your help...
I have a graduation project..ıwant to make this project with msp430g2553...
In this project , I have two time delay...

#include "io430.h"
#include "in430.h"

void main( void )
{

WDTCTL = WDTPW + WDTHOLD;
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ;


__delay_cycles(500000);

P1DIR = 0xFF;
P1OUT= 0x00;
P1SEL_bit.P0 = 1;

P2DIR = 0x00;
P2OUT = 0x00;


TA0CCR0=30000;            // first time delay 30 sn
TA0CCTL0=CCIE;
TA0CTL=TASSEL_2 + MC_1 + TAIE;

_BIS_SR(GIE);
while(1){

if(P1OUT_bit.P1 == 1){

TA0CCR1=15000;                  // second time delay 15 sn
TA0CCTL1=CCIE;
TA0CTL=TASSEL_2 + MC_1 + TAIE;}

else {P1OUT_bit.P3 = 1;}

}}

pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{

i++;
if(i==1000)
{
P1OUT_bit.P1 = 1;

i=0;}

TACTL_bit.TAIFG = 0;}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1 (void)
{
switch (__even_in_range(TAIV, 10))
{
case 2: {i++;
if(i==1000)
{

P1OUT_bit.P2 = 1;
i=0;}

TACTL_bit.TAIFG = 0;}
break;

}}

 

problem is that first delay is working but second is not working...Why ? How can ı chang this code??

Or How can I get two different time delay....But ı want second will start after first time delay...

Also the other question? first delay will occur after  6. high to low position of clock signal..
                                             second will control the 15 second time delay...

Thank you for helping...
 

  • I think this bit of code might be the problem:
    if(P1OUT_bit.P1 == 1){

    TA0CCR1=15000;                  // second time delay 15 sn
    TA0CCTL1=CCIE;
    TA0CTL=TASSEL_2 + MC_1 + TAIE;}

    else {P1OUT_bit.P3 = 1;}

    It will repeatedly restart the CCR1 timer. Technically, your code uses 1 timer with 2 counters. Not really multiple timer. It also uses a busy wait loop in main. That is not really the typical MSP430 style where mainline code stays sleeping. What is your project objective?

  • Since you (a) don't disable the first timer (TA0CCTL0:CCIE) when you start the second timer and (b) use the same variable as a global counter, they're both incrementing "i". The CCR1 ISR will increment i=1, the CCR0 ISR i=2, and so on; eventually, the CCR1 ISR will increment to i=999, and the CCR0 ISR to i=1000, at which point it will reset it to 0. Since the CCR1 ISR never saw it at 1000, it won't trigger completion, i.e. it won't "work".

    It's hard to guess where you're going with this code, but the simplest way to accomplish your stated goal would be to dispense with the CCR1 setting entirely (and don't set TAIE, by the way) and switch to the second timer by setting CCR0=15000.This will cause the timer to cycle in half the time, so your 1000*cycle will be half as well.

    Where you go from there depends on your overall project goal.

  • ı will make graduation project ... device controlling with dtmf using msp430...

    I wont make two timer..because ı cant.. ı will use __delay_ms for first delay and  timer for second delay..but now ı have different problem..you know in dtmf project , there is a decoder (cm8870)..and if you want to control the devices you must enter the true password..I want to make for 4 digits..Also ı saw a dtmf project for pic...I try to change codes from pic to msp430...when ı apply with proteus ı achieved...but in practice sometimes first true password , ı succeed ..but some sometimes not in first maybe two or three..So it is acting complicated...ı will share only part of password for pic and msp430...

    #include <pic.h>
    #include <delay.c>

    #define StD RB4
    #define HAT_ROLE RA1
    #define LED RA2
    #define PALS RA0

    // 4MHz osilator
    __CONFIG(XT&WDTDIS&PWRTEN);

    unsigned char kontrol=0;
    unsigned int CX;

    sifreoku:

    for(i=0;i<5;i++){


    kontrol=0;
    TMR0=131; 
    T0IE=1; // TIMER ON

    //--------------------------------------

    while(StD==0){
    if(kontrol==1){ 
    HAT_ROLE=0; goto basla; 
    }
    else {};
    }

    T0IE=0; CX=0; 

    sifre[i]=PORTB&0x0F;

    while(StD==1); 
    }

    if(sifre[0]==1 && sifre[1]==2 && sifre[2]==3 && sifre[3]==4 && sifre[4]==11){

    LED=1;

    for(;;){
    while(StD==0); 

    komut=PORTB&0x0F;

    if(komut==1)RB5=1; // device 1 ON
    if(komut==2)RB6=1;
    if(komut==3)RB7=1;
    if(komut==4)RB5=0; // device1 OFF
    if(komut==5)RB6=0;
    if(komut==6)RB7=0;

    if(komut==12){ // # tusuna basildi ise hatti kapat
    HAT_ROLE=0; LED=0; goto basla;
    // Cihazlarin ON/OFF durumlari degismeden kalir.
    }
    }
    //--------------------------------------
    }

    else{
    goto sifreoku; 
    }



    HERE FOR MSP430 : 

    sifreoku:

    j=0;
    for(j=0;j<4;j++){


    TA0CCR0=40000;
    TA0CTL=TASSEL_2 + MC_1 + TAIE;
    TA0CCTL0=CCIE;



    while(!(P1IN & 0x30)){
    if(kontrol==1)
    {P1OUT_bit.P1 = 0;goto basla;}
    else{};}


    TA0CTL=MC_0; i=0;
    sifre[j]=(P1IN & 0x30); 
    while((P1IN & 0x30));
    }

    if(sifre[0]==0x10 && sifre[1]==0x20 && sifre[2]==0x10 && sifre[3]==0x20 ){
    P1OUT_bit.P6=1; while(1){//device control..ı will add here...}
    }

    else{sifre[0]=0x00;sifre[1]=0x00;sifre[2]=0x00;sifre[3]=0x00;
    goto sifreoku;}

    }


    My question this method is true for part of password controlling???

  • ı fixed my problem..ı connect the 100 nf to button's second leg and to ground..and ı achieved..thx

**Attention** This is a public forum