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.

Msc1210y5 UART0,ADC,Timer isr config help

Other Parts Discussed in Thread: MSC1210Y5, MSC1210, INA826

Hello dear,

                        I have using msc1210Y5 controller, i have configuring UART0,ADC,Timer0 isr, it was working  separately, but both enable across  it will not work 

ADC and uart 0 work but timer 0isr affected. if i have off adc in PDCON register, timer o isr is working but UART 0 is affected, what can i do. i  gave configuration

bellow. if any configure document have please send me.

char ADC_Setup1(void)
{
    int deci=1728;
//    USEC=10;
// PDCON     = 0xff;

    PDCON     = 0x17;//17
//    PDCON     = 0xf5;  // ADC On,PWM Power Down,SPI System Power Down,System Timer Power Down,Watchdog Timer Power Down
    AIE     = 0x20;  // Enable Auxillary A/D Interrupt
    EICON     = 0x60;  // EAI = 1;
    ACLK     = 0x04;  // 4 ->687khz , 16 ->168 khz , RC ->1.5 khz
    ADMUX    = 0x23;  // AIN 2 is +VE  and AIN 3 is -VE  DIFFERENTIAL INPUTS
    ADCON0    = 0x37;     // 37Gain is 128(PGA0,PGA1,PGA2)
    ADCON1    = 0x41;  // 71 31 Voltage Reference is 2.5v,Internal Voltage Reference On (default).    
    //ADCON2=0xc0;// deci & 0xff;//0Xc0;
//    ADCON3=0x07;//(deci>>8) &0x07;
    return(1);

}


void Timer0_init()
{


//Make INT1 edge triggered
TCON |= 0x04;
//this global variable track the number of times the Timer 0 timed out
timer_0_overflow_count = 0;

count_start = 0x200;

TMOD = 0x19;
CKCON = 0; //Select Divide by 12

IE = 0x86;
TH0 = 0x80;//count_start / 256; //set THO for timer0
TL0 = 0x00;//count_start % 256; //set TLO for timer0
TR0=0;
TF0=0;

/*
  EA = 0;             // disable all interrupts
  TR0 = 0;            // stop timer 0
  TMOD = (TMOD & 0xF0) | 0x01;
//  TL0 = 0xFE;
 // TH0 = 0x4B;
 TH0 = 0x80;//count_start / 256; //set THO for timer0
TL0 = 0x00;
  ET0 = 1;            // enable timer 0 interrupt
  TR0 = 1;            // start timer 0
  EA = 1;
*/



}




void interrupt_timer0 ( ) interrupt 1 using 1
{ /*This ISR is called when a type 1 interrupt causes the processor to vector
into the code segment address 0x0006.
Register Bank 1 is used, as opposed to the default Register Bank 0.*/
IE &= 0x7f; //disable global interrupt
timer_0_overflow_count++; //Track number of times this ISR is called
//Reinitialize Timer 0 counters
TH0 = 0x80;//count_start / 256; //set THO for timer0
TL0 = 0x00;//count_start % 256; //set TLO for timer0
IE |= 0x80; //enable global interrupt

//IE |= 0xf0;

TF0=0;
TR0=1;
}

void setport1(void)
{
 
/*   P1DDRL &= 0x0f;
    P1DDRL |= 0x70;                    //P12 input, P13 output
    CKCON |= 0x10;                    // Set timer 1 to clk/4
    //    TH1 = 256 - XTAL/4/16/BAUDRATE;
    TH1 = 0xF7;                        //19200 bps @11.0592MHz
       SCON1  = 0x50;                     //SCON: Async mode 1, 8-bit UART, enable rcvr; TI=CLEAR, RI = CLEAR
    EICON |= 0x80;                     // Set SMOD0 for 16X baud rate clock
    TMOD = (TMOD & 0x0F) | 0x20;    // Timer 1 (Mode 2, Gate=0, internal clock)
    TCON |= 0x40;*/    

     T2CON = 0x34;                 // Use Timer 2 as baudrate generator
    RCAP2H = (T2RELOAD >> 8);     // baudrate reload factor
    RCAP2L = T2RELOAD;
    SCON0 = 0x50;                 // enable serial uart & receiver, TI=SET for printf compatibility
    PCON |= 0x80;                  // double baudrate for UART0
    IE =0x98;
    IP=0x10;
      
}

i want uart 0,adc, timer 0 init and config code and document.

Thanks and regards,

Ramesh k

  • Ramesh,

    It is not clear where you actually enable Timer 0, as there are lots of stuff commented out.  All of the documentation and sample code we have available is on the ftp site:

    ftp://ftp.ti.com/pub/data_acquisition/MSC_CD-ROM/

    Best regards,

    Bob B

  • Hello Bob Benjamin,

                                 I want UART0,ADC ,and TIMER 0 ISR, i have init  UART0 and ADC  both working fine, But UART0,ADC ,and TIMER 0 ISR int everything can't work,

    it was affected by PDCON register. so please update clear solution.

    Thanks and regards,

    Ramesh k

  • Ramesh,

    The only example code we have is in the location I pointed to on the ftp server I gave you earlier.  I also stated that the code snippet you sent doesn't initialize the timer.

    First of all you will need to turn on the peripherals you want to use.  In your case PDCON must be 0x15.  Neither your current code or your commented code show that you are turning on both the ADC and the Timers.

    Second problem I see is that even if PDCON is set properly the Timer0 interrupt enable flag is not set as it is commented out.  The timer enable is ET0=1 and the timer start is TR0=1.  In your interrupt routine for the the timer I would reset the interrupt flag before re-enabling the global interrupt enable.

    You could be having another issue as well.  If you do not service the ADC interrupt properly or re-enable the interrupts at this point the timer will never trigger an interrupt as the ADC interrupt has a higher priority.

    Always remember that the best information available is in the MSC1210 datasheet and user's guide.

    Best regard,

    Bob B

  • Hello Bob Benjamin,

    I was augury your point on this given bellow ,

    You could be having another issue as well.  If you do not service the ADC interrupt properly or re-enable the interrupts at this point the timer will never trigger an interrupt as the ADC interrupt has a higher priority.  

    Because, i have enable and initialized UART0,ADC,and TIMER0 ISR, when power on, the  UART 0 and ADC also working fine,but timer is count or increment 10 to 19 counts  after it will not work. but UART0,ADC fine. may be simultaneously work on UART0,ADC,and TIMER0 ISR the priority will affect, so please give

    a solution for this.

    Thanks and Regards,

    Ramesh k


  • Ramesh,

    I will be glad to help you any way that I can, but you need to give me all the details of what you are seeing and doing.   You have given me very little to work with, as there are thousands of configurations possible with the MSC1210.  You have only given me a small portion of your code, and that code is flawed because of what you have commented out.  You must send me the exact code you are using when you say you UART0 and ADC work fine but the TIMER0 does not work.  There is no way the TIMER0 will work with the code you sent and I already told you what was wrong.

    In your first post it appeared that the timer didn't work at all, and now you are saying that is does for a little while and then stops.  How are you determining this?  What do you mean by timer count?  Is this the count that is used in the interrupt service routine?

    If you give me a zip file of your entire code I will try to duplicate your situation and get it running at my location.  I just don't have enough information to give you a 'solution' at this time.

    Best regards,

    Bob B

  • Dear Bob,

    please find below

    PDCON=0x15 set ADC on,Uart on both fine,Timer 0 can't work


    PDCON=0x1f // adc,uart off, Timer 0 works fine, but adc can't work
    Note: my counter increment in Timer0 isr, depend on every while loop

    i have attached document the following link, please find it.

    2555.Timer_ims_combined_1.zip

    Thanks and Regard,

    Ramesh k

  • Ramesh,

    Today is a holiday in the USA, so I will look in more detail tomorrow.  PDCON with default setting turns off the timer peripheral, so the timer should not work using 0x1F. A zero bit turns on the peripheral and a 1 turns it off.

    Best regards,

    Bob B

  • Ramesh,

    As I stated before, you must make sure that the PDCON bits are set correctly.  What is very confusing is if the timers are not enabled (PDCON bit 1 low) you should not have been able to see anything work.  This is curious.

    You do have a code issue however, which may be causing your main problem.  This is regarding the interrupt enable. In setport1() you set IE = 0xF0, which enables the interrupts for the serial port and sets the global high.  Later you set IE = 0x86 in Timer0_init() which turns on the Timer0 interrupt, but turns off the Timer2 interrupt used for the serial communications.

    I would code this as follows:

    Early in main(), IE = 0;

    In setport1(), IE |= 0xF0;

    In Timer0_init(), IE |= 0x86;

    This should properly set your interrupts.

    Best regards,

    Bob B

  • Dear Bob Benjamin,

                    I have updated your configuration, but ADC, and UART only working fine, But still Timer 0 isr can't work

    please again find it. and reply me.


     
    void main()
    {


    //        xdata    char   Key,x;
            int disp=0,x=0;
            bit dispflag=0;
            bit EnterBit  = 0;
            bit EscapeBit = 0;
        
    //        char pdata command;
            short memcount=0;
            
            IE=0;   
            reception_status=0;
             CKCON = 0x20;                 // 0 MOVX cycle stretch
            USEC= (XTAL/1000000) - 1;    // 11.0592MHz/11=1.005MHz
            PDCON = 0x0F;    
            //        init_lcd();
            //        lcd_title();
                                 
            
            lock=1;

            setport1();     
            init_lcd();
            ADC_Setup1();
            Timer0_init();

    /***************************************************/
     

      initflag=1;
    //TR0=1;
    //PDCON=0x1f;  //NOTE:

    /*******************************************

    Dear Bob,

    please find below

    PDCON=0x15 set ADC on,Uart on both fine,Timer 0 can't work


    PDCON=0x1f // adc,uart off, Timer 0 works fine, but adc can't work
    Note: my counter increment in Timer0 isr, depend on every while loop

    ****************************************/



    while (1)
    {
         
    weight_count=getRC(); //Note: ADC count when use this line when PDCON=0x15 other wise block this line

    delay(2000);

          //  gotoxy(0,2);
           // putstring("weight:   ",0,10);
              
           //  split1(timer_0_overflow_count);  //LastWeight


    weight_disp(weight_count); //adc count display using UART 0

    weight_disp(timer_0_overflow_count);//timer 0 count print UART 0
    }



    }//ENDMAIN().



    /**************** Timer0 init ****************************/


    void Timer0_init()
    {

    //Make INT1 edge triggered
    TCON |= 0x04;
    //this global variable track the number of times the Timer 0 timed out
    timer_0_overflow_count = 0;

    count_start = 0x200;

    TMOD = 0x19;
    CKCON = 0; //Select Divide by 12

    IE |= 0x86;
    TH0 = 0x80;//count_start / 256; //set THO for timer0
    TL0 = 0x00;//count_start % 256; //set TLO for timer0
    TR0=1;
    TF0=0;

    }




    void interrupt_timer0 ( ) interrupt 1 using 1
    {
    IE &= 0x7f; //disable global interrupt
    timer_0_overflow_count++; //Track number of times this ISR is called
                               //Reinitialize Timer 0 counters
    TH0 = 0x80;//count_start / 256; //set THO for timer0
    TL0 = 0x00;//count_start % 256; //set TLO for timer0
    IE |= 0x86; //enable global interrupt

    TF0=0;
    TR0=1;
    }


    /****************************************************************/
    char ADC_Setup1(void)
    {
        int deci=1728;
    //    USEC=10;
        PDCON     = 0x15;  // ADC On,PWM Power Down,SPI System Power Down,System Timer Power Down,Watchdog Timer Power Down
        AIE     = 0x20;  // Enable Auxillary A/D Interrupt
        EICON     = 0x60;  // EAI = 1;
        ACLK     = 0x04;  // 4 ->687khz , 16 ->168 khz , RC ->1.5 khz
        ADMUX    = 0x23;  // AIN 2 is +VE  and AIN 3 is -VE  DIFFERENTIAL INPUTS
        ADCON0    = 0x37;     // 37Gain is 128(PGA0,PGA1,PGA2)
        ADCON1    = 0x41;  // 71 31 Voltage Reference is 2.5v,Internal Voltage Reference On (default).    
        //ADCON2=0xc0;// deci & 0xff;//0Xc0;
    //    ADCON3=0x07;//(deci>>8) &0x07;
        return(1);
    }     


     

    void setport1(void)
    {
     
     /*    P1DDRL &= 0x0f;
        P1DDRL |= 0x70;                    //P12 input, P13 output
        CKCON |= 0x10;                    // Set timer 1 to clk/4
        //    TH1 = 256 - XTAL/4/16/BAUDRATE;
        TH1 = 0xF7;                        //19200 bps @11.0592MHz
           SCON1  = 0x50;                     //SCON: Async mode 1, 8-bit UART, enable rcvr; TI=CLEAR, RI = CLEAR
        EICON |= 0x80;                     // Set SMOD0 for 16X baud rate clock
        TMOD = (TMOD & 0x0F) | 0x20;    // Timer 1 (Mode 2, Gate=0, internal clock)
        TCON |= 0x40;    */

         T2CON = 0x34;                 // Use Timer 2 as baudrate generator
        RCAP2H = (T2RELOAD >> 8);     // baudrate reload factor
        RCAP2L = T2RELOAD;
        SCON0 = 0x50;                 // enable serial uart & receiver, TI=SET for printf compatibility
        PCON |= 0x80;                  // double baudrate for UART0
        IE |=0xF0;
        IP=0x10;
          
    }

    Thanks and regard,

    Ramesh k

  • Ramesh,

    It is possible that I'm misunderstanding what you are trying to do.  As I do not have a schematic, I can only guess.  Up to this point I was assuming that you were strictly free running the timer0 updating your variable 'timer_0_overflow_count.'  I also believe that I made an error on what I told you to use for IE register based on your code assignment and not on the other register settings.

    Let's take a look at what registers must be set when using the timer0.  First off all the timer power must be turned on by setting the appropriate bit low in the PDCON register.  Other registers that affect the timers are CKCON, TCON, TMOD, TH0, TL0, TR0, TF0, and IE.

    CKCON adjusts the count divider, and is not critical to operation.  TH0 and TL0 set the counter start point.  The timer will count up until it overflows, so the start point is not critical to the operation.  TF0 gets set by as a flag by the timer0 overflow, and you initialize as 0 (reset) and re-initialize to 0 in the interrupt routine which is correct.  Timer 0 operation must have the TR0 high and it is set high both in initialization and the interrupt which is correct.  TCON contains both the bits for TR0 and TF0, but also determines the type and method of the interrupt detection. 

    Here is where we start to have a problem, as you have this register set to 0x04 which sets INT1 to edge triggered (high to low).  Timer 0 uses INT0, so maybe the correct bits are not set in this register.  TMOD sets the timer mode controls.  In your code TMOD is 0x19, where bits 3-0 are timer 0 mode controls.  With bit 3 set, the timer 0 will only run if TR0 is high, and INT0 is also high.  This means this timer must have hardware interaction to operate.  Do you have a control signal connected to the INT0 pin (P3.2)?  And is it logic high?  Do you want this timer to run this way, or do you want it to free run with software control only?

    Lastly the IE register.  This is set to 0x86, which globally enables the interrupts and enables the INT1 pin and enables the timer 0 interrupt.  It does not enable the external INT0 interrupt which is required by your setting of TMOD.

    In Timer0_init() if you want the timer to just free run the settings should be:

    TMOD = 0x11;

    IE |= 0x82;  // also set in the interrupt service routine

    In Timer0_init() if you want the timer to run based on the INT0, TCON should be set as desired and the other settings should be:

    TMOD =0x19 ;

    IE |= 0x83;  // also set in the interrupt service routine

    This is assuming that I have the correct idea on what you are trying to do.  If my assumptions are not correct, please explain how you intend on using the timer.

    Best regards,

    Bob B

  • Dear Bob Benjamin ,

    do you want it to free run with software control only?

    yes i want free run with software control

    In Timer0_init() if you want the timer to just free run the settings should be:

    TMOD = 0x11;

    IE |= 0x82;  // also set in the interrupt service routine

     i was used this above config but ADC,UART only works fine,

    Timer 0 isr did not work, when i set PDCON=0x15 // ADC,UART 0 works fine,TIMER isr cant work.

    when i set PDCON=0x1d // ADC off ,UART 0 works fine,TIMER0 isr  works fine.

    so when i have on adc in PDCON =0x15 it was affected in timer 0 isr its very clear,

    please timer 0 isr and adc both interrupt may be affected. so clear to me this configuration

    Thanks,

    Ramesh k

  • Ramesh,

    I can't seem to find the code portion for the interrupt service routine for the ADC.  Can you point me to the code?  The ADC (auxiliary interrupt) has higher priority over the timer.  If the auxiliary flag is not reset, the timer interrupt will never execute.

    Best regards,

    Bob B

  • Dear Bob Benjamen,

                         I am working polling method for ADC reading, i am not used ISR method, this code is bellow,

                                     long getRC()
                                            {
                                        while (!(AIE & 0x20)){};      // Wait for data ready
                                        ADVALUE = ADRESH;
                                        ADVALUE = ADVALUE<<8;
                                        ADVALUE = ADVALUE + ADRESM;
                                        ADVALUE = ADVALUE<<8;
                                        ADVALUE = ADVALUE+ADRESL;
                                        ADVALUE=ADVALUE/100;
                                    
                                         return(ADVALUE);
                
                                       }  

    The ADC (auxiliary interrupt) has higher priority over the timer.  If the auxiliary flag is not reset, the timer interrupt will never execute.

    i agree your points above.
     
          Note: I am reading one document its more details have points given bellow  ,                       

    1)

    10.5 Interrupt Priorities
    The MSC1210 offers three levels of interrupt priority: highest, high, and low.
    By using interrupt priorities, higher priority may be assigned to certain interrupt
    conditions. The “highest” priority is reserved for the Auxiliary interrupt that vectors
    through address 0033H—the Auxiliary interrupt is always of “highest”
    priority and no other interrupt may be assigned that priority.
    All other interrupts may be assigned either “high” or “low” priority. For example,
    assume the Timer 1 interrupt has been enabled to be automatically called every
    instance Timer 1 overflows

    2).

    However, before the Timer 1 Interrupt (or any other interrupt) is truly enabled, bit
    7 of IE must also be set. Bit 7, the Global Interrupt Enable/Disable, enables or
    disables all interrupts simultaneously (except the Auxiliary Interrupts). That is to
    say, if bit 7 is cleared, no interrupts will occur, even if all the other bits of IE are
    set. Setting bit 7 will enable all the interrupts that have been selected by setting
    one of the other “enable bits” in one of the three SFRs. This is useful in program
    execution if there is time-critical code that needs to be executed. In this case, the
    code may need to be executed from start to finish without any interrupts getting
    in the way. To accomplish this, simply clear bit 7 of IE and (CLR EA) bit 5 of EICON
    (CLR EAI), and then set them after the time- critical code is done.


    so,  when can i set PDCON=15, adc uart 0 fine, when disable adc using PDCON=0x1d when Timer isr and UART 0 working fine,

    i have used (CLR EAI) bit  it didn't control properly in adc, and timer isr this is control one time only.

    i want more details of this.

    Thinks and regards,

    Ramesh k



  • Ramesh,

    Your code enables the ADC interrupt, but you don't use it in an interrupt routine.  I believe your intent is to monitor the interrupt flag that is issued when the conversion result is posted, but you have the wrong register in the 'while' of your getRC() routine.  AI is the flag in the EICON register.  It can be rather confusing about all that is going on with the interrupts.  Let's take a deeper look. 

    The ADC interrupt is a member of a single interrupt system called Auxiliary Interrupt.  So you need to enable the interrupts twice for the ADC, which you do in the main procedure.  However, once the auxiliary interrupt flag is set (AI) it is never reset.  As this flag has a higher priority than the timers, the interrupt service routine will not call the timer interrupt.  You should set AI=0 at the end of your function getRC().

    As I previously mentioned at the beginning, the AIE register enables the ADC interrupt in the Auxiliary Interrupt, but it does not enable the Auxiliary Interrupt (master) or contain the flag information for the Auxiliary Interrupt.  The other enable (master auxiliary enable) is contained in the EICON register.  This is bit 5 of the register (EAI) which is called the Enable Auxiliary Interrupt.  The flag is bit 4 of the register, AI.  In the 'while' of your routine you want to make sure you are monitoring the flag and not the interrupt enable.

    Clearing EAI will disable the interrupt for the ADC, but will not clear the flag that has already been set.  This can only be done clearing the AI bit (AI=0).

    Best regards,

    Bob B

  • Dear Bob,

                      Clearing EAI will disable the interrupt for the ADC, but will not clear the flag that has already been set.  This can only be done clearing the AI bit (AI=0).

    i was set above but adc cant control, when PDCON reg disable adc bit it will controll, but EAI,AI using this bit cant control.

    NOTE:

    1) my sensor Load-cell, i have apply 5v power supply its work fine,ADC count stable(input 1mv upto 20mv), but 12v power supply apply its (input 2mv) when adc

      count cant stable.7000 count jumping. what appan please update me.

    Thanks and regard,

    Ramesh k

  • Ramesh,

    You cannot exceed the absolute maximum voltage specifications.  If you excite your load cell with 12V, the balance point of the bridge is 6V which is greater than the supply of the MSC1210.  In this case the ESD cells will turn on and conduct current that can damage the MSC1210.  You must also make sure that the input is within the common mode input range of the MSC1210 analog inputs.  This is determined by the PGA setting used and the AVDD supply.

    Best regards,

    Bob B

  • Dear Bob,

                          I am not clear above this point, i have using MSC 1210 power supply AVDD=5V ,and DVDD=3.3v and my loadcell operating voltage 5V to !2V(EXE-,EXE+)

    so i have given 5v/800mA for EXE+,EXE-,  zero scale is 1.2 mv then works fine, same i have used 12V/800mA power supply  zero scale is 2.2 mv but my count not stable.

    we have used industrial so required 12v (EXE+,EXE-). what can i do?

    i thing,  we will change Low pass input resistor 1K replace to higher value. its possible?

    Thanks,

    Ramesh k

  • Ramesh,

    As I have not seen a schematic, so I can't speak directly to your filter.  If you want to use a 12V excitation to the load cell, you will need to adjust the output in some way so that the + input to ground, or the - input to ground does not exceed the AVDD supply of the MSC1210.

    If you think of the load cell as a variant of the Wheatstone bridge, strain on the bridge affects the resistance value of the leg in the bridge.  In the balanced, or no load state, the bridge is simply two parallel voltage dividers that behave the same way.  The difference between the measuring point (+ and -) has zero, or close to zero difference.  However, there is a voltage common to each of the inputs relative to ground.  As each resistance in the bridge is equal, the common voltage relative to ground will be half of the excitation voltage (or 1/2 of 12V which is 6V.)  In this case, each of the analog inputs may have 0V difference between them, but has 6V that is applied in common to each.  6V is greater than the AVDD supply.  The absolute maximum analog input is specified to be 300mV above the AVDD supply.

    To use an excitation of 12V, you will need to bring the common mode voltage below AVDD and withing the range of the PGA of the MSC1210.  The best region for the common mode voltage is mid-supply of AVDD (or 2.5V.)  To accomplish this, you will need some type of instrumentation amplifier, like the INA826 that will accept the higher common mode voltage, and set the output relative to a reference.  The reference can be the REFOUT of the MSC1210 at 2.5V.

    Best Regards,

    Bob B

  • Dear Bob,

                         How are you? I am fine. sorry for delay. I have used PDCON=0x15;   i am try to control adc using AI=0,EAI =1 adc working. but AI=0,EAI =0 adc cant control or off.

    Note:

    1) i am using UART0 isr, its working fine before init this register PDCON=0x15;  When i was int PDCON=0x15  after adc works fine, but UART0 isr and timer 0 isr

    affected.

    2) When i have init adc PDCON=0x15, All vector ISR should not work, its very clear,  this problem also we faced on timer 0 isr. now i have tested UART 0 ISR also.

    3) when i have init PDCON=0x15 before All isr working fine, after init PDCON=0x15 All isr cant work. after i was disable PDCON=0x15; but all irs cant work..

    4) you are say  set/clear AI=0,EAI =1 and control( on/off) adc. its cant work. so please update what can i do? please update me.

    Thanks and regard,

    Ramesh k.

  • Ramesh,

    I'm sorry to hear that you are still having issues.  At this point it is really hard for me to follow your code as there are a number of issues.  It appears that several pieces of code have been put together.  I would suggest that you put together only the pieces of code you need and not all the extra code.  This would make it much easier to debug.

    First of all, it is very difficult for me to find your functions.  The source code for the functions should be in '.c' files and not in the header files '.h'.  The way the code is setup currently is very confusing and hard to follow.  Many register settings are conflicting and are hard to determine the end configuration.  Items such as CKCON are set to one value in the main and then changed within a function which totally changes the previous setting.  Maybe it doesn't matter in the end, but it is really hard to try and figure out what you want to do.

    If you tell me exactly what you want to do (maybe through pseudo code) I can help you create the code from scratch.  It appears that you have set your clock to 1 MHZ, and the timer is set to divide by 12, which would be 83.3kHz.  This is a clock period of 12us.  The timer is set to overflow at 32768 counts or about every 393.216ms.  This would add to your overflow count every 393.216ms.  It also appears that the data rate should be about 22 sps.  This means a new sample should arrive every 45.45ms.  This would mean that you would get about 8 samples between each timer update.  Is this what you are expecting to see?

    Also, when you are polling the ADC the EICON should be the default value of zero which sets EAI = 0.  If you send me exactly what you want to do, including all the timing, I will help you write your code correctly.  This includes the UART settings as well in regards to baud rate, etc..

    Best regards,

    Bob B

  • Dear Bob,

                            My application is dynamic weighing system for truck, so i have find speed of the vehicle using TIMER0 ISR and calculate the speed o vehicle,

    Then Read the adc for weight.and print the the values to  uart 0 ISR, this is our requirement for this project. so please send any sample code

    using TIMER0ISR,UART0ISR,and ADC both combined a source code.

    I have find your MSC1210 sample code there is not available both combined examples, everything have separate code, so i want both combined codes(TIMER0ISR,UART0ISR and ADC poling or ISR method). so please send me.

    Thanks and regards

    Ramesh k

  • Ramesh,

    I've attached your sample code.  Console output looks as below with column 1 as the ADC output, and column 2 as the timer overflow count.

    1033.adc.c
    //********************************************************************
    // File name: adc_test.c
    //
    // Copyright 2003-2012 Texas Instruments Inc as an  unpublished work. 
    //
    // Version 1.0.1
    //
    // Compiler Version (Keil V2.38), (Raisonance V6.10.13)
    //
    // Module Description:
    // ADC Example Program - Polls ADC and Timer0 and UART operation
    //
    //********************************************************************
    #include "legal.c"         //Texas Instruments, Inc. copyright and liability 
    #include <REG1210.H>       // The header file with the MSC register definitions
    #include <stdio.h>         // Standard I/O so we can use the printf function
    
    extern signed long bipolar(void);
    
    #define autobaud()    ((void (code *) (void)) 0xfff3) ()    // For MSC1210/11/12/13/14
    #define LSB 298e-9
    #ifndef XTAL 				// if no XTAL compiler variable defined use:
        #define XTAL 22118400 	// XTAL frequency 22.1184 MHz
    #endif
    
    unsigned long int timer_0_overflow_count;
    
    Main(void) {
        char i,j;
        float result;
        
        
    	
        PDCON = 0x15;           // Turn on the A/D, and timers
        ACLK = XTAL/2000000;    // ACLK freq. = XTAL Freq./(ACLK +1) = 0.9216 MHz
                                // 0.9216 Mhz/64 = 14,400 Hz
        DECIMATION = 1440;      // Data Rate = 14,400/1,440 = 10 Hz
        ADMUX = 0x76;           // AINP = AIN7, AINN = AIN6  
        ADCON0 = 0x30;          // Vref On, 2.5V, Buffer Off, PGA=1
    
    	CKCON = 0x10;	        // Timer1 div 4
    	TCON = 0;		        // Stop TR1, TR0
        autobaud();             // uses built in ROM routine to set up UART based on CR
        ADCON1 = 0x01;          // bipolar, auto, self calibration, offset, gain
        
        /* Timer initialization */
         
        timer_0_overflow_count = 0;
        
        TMOD = 0x01;            // Timer0 16 bit mode
        IE = 0x86;
        ET0 = 1;                // Enable the timer0 interrupt
        TH0 = 0x80;             // set the timer start count to 0x8000
        TL0 = 0x00;
        
        TF0=0;                  // clear the timer0 interrupt flag
        TR0=1;                  // turn on the start the timer0
        
        /* End of timer initialization */
        
        
        printf("ADC Test, ACLK=%d\n",ACLK);
        //wait for the calibration to take place
        for (i=0;i<3;i++){     // dump 3 conversions
            while(!(AIE&0x20)) {}
            j=ADRESL; 
        }
    	
    	j=1;
        while(1){
            while(!(AIE&0x20)) {} // Waiting for conversion
            result=bipolar();     // Save Results
                    
            printf ("%10.8f\t", result*LSB);
                    
            printf("%ld\n", timer_0_overflow_count);          // print the timer overflow count
            
        }
    } 
    
    void interrupt_timer0 ( ) interrupt 1 using 1
    { 
    TR0 = 0;                    // turn off timer0
    timer_0_overflow_count++;   //Track number of times this ISR is called
                                //Reinitialize Timer 0 counters
    TH0 = 0x80;                 // set the timer start count to 0x8000
    TL0 = 0x00;
    
    TF0=0;                      // reset the timer0 interrupt flag             
    TR0=1;                      // restart the timer0
    }
    

    Best regards,

    Bob B

  • Dear Bob,

                             Thaks for your updation, you have used uart 0 for in-builded,but my requirment using UART0 ISR , so please update me UART0 isr and UART0 INIT also

    as same code, required for TIMER0 ISR,UART0 ISR, and ADC( ISR/ or polling), Must UART0 ISR and Timer 0 ISR method. so kindly update me.

    Thanks and Regards,

    Ramesh k

  • Dear Bob,

                             Thanks for your updation, you have used uart 0 for in-builded,but my requirment using UART0 ISR , so please update me UART0 isr and UART0 INIT also

    as same code, required for TIMER0 ISR,UART0 ISR, and ADC( ISR/ or polling), Must UART0 ISR and Timer 0 ISR method. so kindly update me.

    Thanks and Regards,

    Ramesh k

  • Ramesh,

    I've been working on this, but I have a problem in that my compiler is an EVAL version and I have limited code space.  I'm trying to reduce the code so that I can get you something to work.  Keep in mind that I have many other customers, and cannot devote my entire work time on your solution.  I will post an update as soon as I'm able.

    Best regards,

    Bob B

  • Ramesh,

    Here is sample code using UART0 as interrupt mode.  Sending a keyboard 's' starts sending output, and sending 'e' ends the output to the console screen.  If you start and stop, then start again you will observe that the timer function continues to update even though the screen update does not.

    7115.adc.c
    //********************************************************************
    // File name: adc_test.c
    //
    // Copyright 2003-2012 Texas Instruments Inc as an  unpublished work. 
    //
    // Version 1.0.2
    //
    // Compiler Version (Keil V2.38), (Raisonance V6.10.13)
    //
    // Module Description:
    // ADC Example Program - Polls ADC and Timer0 and UART (INT) operation
    //
    //********************************************************************
    #include "legal.c"         //Texas Instruments, Inc. copyright and liability 
    #include <REG1210.H>       // The header file with the MSC register definitions
    #include <stdio.h>         // Standard I/O so we can use the printf function
    
    
    extern signed long bipolar(void);
    
    
    
    #define autobaud()    ((void (code *) (void)) 0xfff3) ()    // For MSC1210/11/12/13/14
    
    #define LSB 298e-9
    #ifndef XTAL 				// if no XTAL compiler variable defined use:
        #define XTAL 11059200 	// XTAL frequency 11.592 MHz
    #endif
    
    #define BAUDRATE 9600 // 9600bps communication baudrate
    
    
    int run_flag = 0;
    unsigned long int timer_0_overflow_count;
    
    Main(void) {
        char i,j;
        int result;
        
         /* ADC initialization */
    	
        PDCON = 0x15;           // Turn on the A/D, and timers
        ACLK = XTAL/1000000;    // ACLK freq. = XTAL Freq./(ACLK +1) = 0.9216 MHz
                                // 0.9216 Mhz/64 = 14,400 Hz
        DECIMATION = 1440;      // Data Rate = 14,400/1,440 = 10 Hz
        ADMUX = 0x76;           // AINP = AIN7, AINN = AIN6  
        ADCON0 = 0x30;          // Vref On, 2.5V, Buffer Off, PGA=1
    
    	CKCON = 0x10;	        // Timer1 div 4
    	TCON = 0;		        // Stop TR1, TR0
        
        ADCON1 = 0x01;          // bipolar, auto, self calibration, offset, gain
        
        /* end of ADC initialization */
        
        /* UART0 initialization */
      
        autobaud();             // uses built in ROM routine to set up UART based on CR
        printf("ADC Test\n");
        RI_0 = 0;                   // clear receive flag
        TI_0 = 0;                   // and trasmit flag
        
        IE = 0xB0;
    	  
        /* end of UART0 initialization */
        
        /* Timer initialization */
         
        timer_0_overflow_count = 0;
        
        TMOD = 0x01;            // Timer0 16 bit mode
        IE |= 0x82;
        ET0 = 1;                // Enable the timer0 interrupt
        TH0 = 0x80;             // set the timer start count to 0x8000
        TL0 = 0x00;
        
        TF0=0;                  // clear the timer0 interrupt flag
        TR0=1;                  // turn on the start the timer0
        
        /* End of timer initialization */
               
        
        printf("ADC Test\n");
        
        //wait for the calibration to take place
        for (i=0;i<3;i++){     // dump 3 conversions
            while(!(AIE&0x20)) {}
            j=ADRESL; 
        }
    	
    	j=1;
    	 
        while(1){
        
            if (run_flag)
            {
                while(!(AIE&0x20)) {} // Waiting for conversion
                result=bipolar();     // Save Results
                    
                printf ("%10.8f\t", result*LSB);
                    
                printf("%ld\n", timer_0_overflow_count);          // print the timer overflow count
            }
            
        }
    } 
    
    
    
    
    void interrupt_timer0 ( ) interrupt 1 using 1
    { 
        TR0 = 0;                    // turn off timer0
        timer_0_overflow_count++;   //Track number of times this ISR is called
                                //Reinitialize Timer 0 counters
        TH0 = 0x80;                 // set the timer start count to 0x8000
        TL0 = 0x00;
    
        TF0=0;                      // reset the timer0 interrupt flag             
        TR0=1;                      // restart the timer0
    }
    
    
    void UART0_Interrupt (void) interrupt 4 using 2
    {
        char dummy;
    
    
        if(RI_0)        // code section for receive interrupt
        {
            
            dummy = SBUF0;
            RI_0=0; 
            //SBUF0 = dummy;        //used for echo
            //TI_0 = 0;
            switch(dummy) 
            {
                case 's':
                    run_flag = 1;
                    break;
                case 'e':
                    run_flag = 0;
                    break;
                default:
                    break;
            
            }
            
            
        }    
           
    }
    
    
    

    Best regards,

    Bob B

  • Dear Bob,

                         I have compile and download your code (7115.adc.c and 1033.adc.c) both cant work, i am check with terminal

    no response so please check and update me.

    Thanks and regards,

    Ramesh k

  • Ramesh,

    I'm sorry you are having problems.  I compiled using Raisonance, and you are using Keil.  I don't have Keil on my computer, so I can't check it.  I've attached the hex code you can use and should be able to load on your system to verify.

    2318.ADC.HEX

    Best regards,

    Bob B

  • Dear Bob,

                               2318.ADC.HEX this code works fine, but i have download and change execution mode doesn't work  then press Enter after print ADC TEST

    and press s print value and press e stop, its ok fine, but why required enter first time?.

    7115.adc.c this sample code download after press Enter  print ADC TEST only, then s and e pressed doesn't print adc and timer values.

    so please update me.

    Note:

    one more question?

              My load cell given 5V supply, output of sig+ and sig- is current is 0.5uA with 1mV  and adc works fine,

      same EXC +/- given 12v supply, output of sig+ and sig- is current is 165uA  each signal  coming 2.2mV  and adc cant work.

    i am very critical situation.so please update me.

    Thanks,

    Ramesh k

  • Dear Bob,

                         Sorry for the interrupt, i am waiting for your valuable replay.

    so kindly update me. because i am very critical position.

    Thanks,

    Ramesh k

  • Ramesh,

    I'm in the midst of traveling and this is the first chance I've had to respond.  Maybe I wasn't clear before, but the first 'Enter' is to set the UART parameters automatically using 'autobaud()', which will accurately set up the timers and configuration for communication using whatever terminal setup you may be using.  This uses a hardware ROM routine built into the MSC1210.

    I'm not sure what could be happening when you compile your program.  The hex file was created using the same c code I sent, so maybe there is something in the compiler/linker of your Keil setup that is conflicting with your operation.  I will not be able to look into this further until sometime later next week.

    Regarding your load cell, please review the information I posted earlier that explained this in detail.  You cannot excite the load cell with 12V as it sets the common mode at 6V which is greater than the AVDD supply.  This violates the absolute maximum input specification of the device.  It will also conduct current through the ESD diodes which is why you see the excessive current.  So in short, you cannot excite the load cell with 12V and then read it directly from the MSC1210.  It is impossible.

    Best regards,

    Bob B

  • Dear Bob,

                         Sorry for the  again interrupted, i am waiting for your valuable replay.

    so kindly update me. because i am very critical position.

    Thanks,

    Ramesh k

  • Ramesh,

    I recompiled the code with Keil, and it works fine.  I think that maybe you have something set wrong in Keil.  I've attached a zip file that contains the project files for both Keil and Rasionance.  Perhaps you can identify a setting that is different than yours.  At this point I'm not sure what more I can do for you in providing further help in getting your code to work.

    0172.MSC_Example.zip

    Best regards,

    Bob B

  • Dear Bob,

    MSC_5F00_Example.zip  this source code working fine, But  you have used UART 0 using printf statment , i want transimite through polling method using SBUF0,

    like this  SBUF0='A'; while(TI_0 == 0); TI_0 =0; poling method transmit cant work. please update me.

    Thanks and regards,

    Ramesh k

  • Ramesh,

    Your original problem stated that the uart, timer and ADC could not operate at the same time.  I demonstrated that this is possible.  I also told you that I do not have a full version of the compiler, so I cannot do extensive code operations.  Built in functions, like fprint() are available to me as they are in the standard library.

    As far as building routines that function outside of the interrupt, and yet use interrupt flags only confuses operation.  So in this case you cannot use polling and interrupt functions at the same time.  Turning the uart0 interrupt off (bit 4 of the IE register) would be appropriate.

    Remember that when you turn off internal interrupt operations and use polling, you have eliminated the priority interrupt system.  This means you may have to disable lower priority interrupts when higher priority functions are in operation otherwise interrupt flags may be missed, misinterpreted, or ignored.

    This may have been your original problem.  It is up to you the programmer to decide how your system is to function.  I demonstrated that all three operations can work simultaneously.  If you want to devise your own method, that is fine.  However, I do not have the software to write advanced code of the nature and operation you desire.  You will have to debug your system and discover where your software is failing.

    Best regards,

    Bob B

  • Dear Bob,

              interrupt flags may be missed, misinterpreted, or ignored. 

    yes, your above point is correct, because i have used  SBUF0='A'; While(TI_0==0); TI_0 =0; TI_0 flag is cant set properly, after i remove while condition and replace delay

    its works fine. SBUF0='A'; delay(50); TI_0 =0;  this is not right way, so please update me how we can fix it.

    Thanks,

    Ramesh k

  • Ramesh,

    Sometimes actions within a comparison can be misinterpreted.  The TI_0 flag should get set once the buffer has been written.  Try a different comparison with the while to see if the action completes.  For example:

    while(!TI_0);

    Best regards,

    Bob B

  • Dear Bob,

                            I had solve all the software bugs, Very very Thanks Dear Bob,  i have enable  axillary interrupt AIE =0x20 that is affected,

    so Thanks for spend your valuable time. i have solved software bug with your help. still i have problem for load cell read  adc its hardware problem mV and current.

    already i have posted last mail so please give solution for me. i am waiting for your reply.

    Thanks,

    Ramesh k

  • Ramesh,

    I already answered your analog questions in earlier posts.  I suggest that if I have not answered a specific question you start a new post with just the analog questions so we keep specific topics together.

    To quickly address once again, you cannot exceed the common mode voltage specification for the analog inputs.  The DC voltage from the analog + input and the - input cannot exceed the AVDD supply voltage.  This input can be measured from each input to ground with your load cell connected.  There are some further restrictions as to the limit of this range (may be less than AVDD) when gain is used and the internal buffer is also used.

    For example, with 12V excitation, the balanced bridge state will be 1/2  the excitation voltage (6V).  6V will exceed the 5V AVDD supply, and will draw excessive current (through ESD protection diodes) and can damage the MSC1210.

    The solution is to lower the excitation voltage, or use the circuit I gave in the earlier post.

    Best regards,
    Bob B

  • Dear Bob,

                           I am trying to SD CARD interface in MSC1210 for data logger, SD CARD is SPI Protocol , can you help me?, spi init  and sample code for SPI and SD CARD 

      interfacing in MSC1210. please send sd card sample code. I am waiting for your valuable reply.

     

    Thanks and Regards,

    Ramesh k