CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Sampling frequency with timer0 interrupts problem
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Sampling frequency with timer0 interrupts problem
PostPosted: Thu Apr 17, 2008 2:35 am     Reply with quote

Hello Guys?
I'm sampling a signal from adxl330 accelerometer at 1000HZ using timer0 to interrupt every 1ms (0.001S) and then print out the values to hyperterminal. The formula I used to achieve reload time is:
Rt =65536 - tm*Fosc/(4*Fscal)
where tm =time =0.001
Fosc =Clock frequency =20MHZ
Fscal =prescaler =256
Rt= 65536 - (0.001*20*10^6)/(4*256)
= 65536- 20
= 65516
so I used set_timer0(65516) as shown in the code. The problem is the values I'm getting are wrong. Can anyone tell me what the problem is?

Code:
#include <16F877A.h>
#device *=16
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#byte   PORTB = 0x06   // PortB lives in File 6 (data bus)
#byte   PORTC = 0x07   // PortC lives in File 7 (address bus A12 to A8, RX, TX & R/W)
#byte   PORTD = 0x08   // PortD lives in File 8 (address bus A0 to A7)
#byte   PORTE = 0x09   // PortE lives in File 9 (used for DIP switches)

#include <stdio.h>
#include <2416.C>
#include <stdlib.h>
#BIT ADFM = 0xFC0.7

#use    fast_io(B)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(C)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(D)     // Fast access to PortD (don't fiddle with TRISD)
#use    fast_io(E)     // Fast access to PortE (don't fiddle with TRISE)
unsigned int16 dc;
int16 data;
int1 flag;
#int_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(65516);   //reload for the next 1 ms (65536 - (tick*20*e6)/(4*256)) where t =0.001 second
   dc++;
   //read_adc(ADC_START_ONLY); //only starts the conversion read_adc(); start adc
   read_adc();
   if(dc > 2048)
   {
      flag = 1;
      dc = 0;
   }

}

#int_AD
void AD_isr(void )
{
   int16 tmp;
    //ADXL330ACCELCalibrateXYZ();
    set_adc_channel(0);                  // select the required channel
    tmp = read_adc();
    //tmp=read_adc(ADC_READ_ONLY); //reads the result of the last conversion and store it in value
 
    data = (tmp - 512L);
   
    printf("%.2f,\t%0Ld \r\n",(dc*0.01) ,data);
    if(data >= -2 || data <= 2)
    {
       data =0L;
    }
   
   
   
       
   
   
}

//#define LCD_TYPE 1
#include <LCD4X20.C>

void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm);

void main()
{
   unsigned int16 result;
   int16 res =0L;
   data = 0L;
   result= 0L;
 
   lcd_init();   
   set_tris_b(0x17);             // TRISB = 00010111; RB4,RB2,RB1 and RB0 TTL Inputs
   port_b_pullups(FALSE);        // Don't use internal pull up resistors   
   setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
   setup_adc(ADC_CLOCK_DIV_64); 
   setup_timer_0( RTCC_DIV_256 );   //Timer0 enabled with a 245 prescaler
   ADFM = 1;

   lcd_gotoxy(1,1);// Type some characters and backspace over them.AccelBuff
   lcd_putc(" X      Y      Z");
   
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_AD);
   enable_interrupts(GLOBAL);
   dc = 0L;
   flag = 0;

   // TODO: USER CODE!!
   while(1)
   {
     if (flag==1)
     { 
         flag = 0;
         ADLX330ACCELBlinkLED(9, 4, 12);
     }   
   }
 }

void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm)

    int i;
    for(i = 0; i < tm; i++ )
    {
     output_low(PIN_B5);
     delay_ms(on); 
     
     output_high(PIN_B5);
     delay_ms(off);
    }
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Sampling frequency with timer0 interrupts problem
PostPosted: Thu Apr 17, 2008 5:42 am     Reply with quote

If you are getting an interrupt every 1 ms., then inside that interrupt rountine you are calling printf, which sends stuff at 9600 baud to hyperterminal, then that will take up much more than 1 ms., so you obviously can't be getting an interrupt every 1 ms. At 9600 baud it takes 1 ms. just to send a single character. To really see what is going on, take the printf (and anything else that consumes a lot of time) out of the ISR and put it in the main program. Of course you can't get a printout of every single reading no matter how you do it. But for purposes of checking that the readings are correct, it would be good enough to print whatever reading is current at the time you happen to look.

So after you fix those things, then tell us what is being printed out and what you think should be printed out.

Robert Scott
Real-Time Specialties
Matro
Guest







PostPosted: Thu Apr 17, 2008 8:22 am     Reply with quote

Code:

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
//code continue
set_timer0(60533);  //will overflow after 1ms


Matro.[/code]
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Thanks guys
PostPosted: Thu Apr 17, 2008 8:34 am     Reply with quote

Hi Matro,
How did you get to 60533?
I thought at 20MHZ clock and @ 1ms, the math will be as follows.
Code:
ReloadTime = (65536 - 20*10^6*0.001/(4*256))
                  = (65536 - 19.5)
                  = 65536 - 20
                  = 65516

or did you use prescaler of 1?
kind regards,
S.Kein
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Apr 17, 2008 8:58 am     Reply with quote

A good rule is to never put a printf in an isr unless you are debugging and are willing to accept that the printf will mess up horribly any speed or timing .
Matro
Guest







Re: Thanks guys
PostPosted: Thu Apr 17, 2008 9:18 am     Reply with quote

kein wrote:
Hi Matro,
How did you get to 60533?
I thought at 20MHZ clock and @ 1ms, the math will be as follows.
Code:
ReloadTime = (65536 - 20*10^6*0.001/(4*256))
                  = (65536 - 19.5)
                  = 65536 - 20
                  = 65516

or did you use prescaler of 1?
kind regards,
S.Kein

I look at CCS Wizard that indicates an overflow of 13.1ms for a PIC16F877 with 20MHz clock and prescaler of 256.
And just calculate (65536 * 12.1 / 13.1) to obtain a 1ms overflow.

Matro.
Matro
Guest







PostPosted: Thu Apr 17, 2008 9:35 am     Reply with quote

The correct calculation is :
65536 - 65536 * time * Fosc / (4 * 256 * prescaler)

In your case :
65536 - 65536 * 0.001 * 20000000 / (4 * 256 * 256) = 60536

Matro.
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Thank you
PostPosted: Sat Apr 19, 2008 10:31 am     Reply with quote

Thanks matro
Kind regards
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

No no no it' does not work at all
PostPosted: Tue Apr 22, 2008 4:10 am     Reply with quote

Guys I've removed printf() from the interrupt sub routine and now the signal I'm getting is really worst.
Signal from the signal generator is 0-5v and offsetted at 2.5V.
Its frequency is 4Hz and my sampling frequency Fs is 100Hz.
my crystal frequency is 20MHz.
I've modified a code by PCM programmer. Why can't I get a nice sign wave output into the comm?

I've tried to increase the baud rate with no improvement!! Embarassed
Code:
#include <16F877A.h>
#device *=16
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


//----------------------------------------------------------------------
// DEFINES
//
// With a 20 MHz oscillator, a RTCC pre-scaler of 256, and a RTCC
// preload of 196,  we get an rtcc interrupt rate of 100.16 Hz (Approx.
// every 10 ms).
// This will be our "tick" clock that we use for various event timers.
#define RTCC_PRELOAD (256 - 196)

// Multiply the following values x 10 ms to get the delay times,
// since each timer tick is 10 ms.
#define BUTTONS_TIMER_TICKS      2       // 20 ms
#define IRDA_TIMER_TICKS         10      // 100 ms
#define LED_TIMER_TICKS          50      // 500 ms
#define UART_TIMER_TICKS         100     // 1000 ms


#byte   PORTB = 0x06   // PortB lives in File 6 (data bus)
#byte   PORTC = 0x07   // PortC lives in File 7 (address bus A12 to A8, RX, TX & R/W)
#byte   PORTD = 0x08   // PortD lives in File 8 (address bus A0 to A7)
#byte   PORTE = 0x09   // PortE lives in File 9 (used for DIP switches)

#include <stdio.h>
#include <2416.C>
#include <stdlib.h>
#BIT ADFM = 0xFC0.7
#byte timer0low = 0xfd6

#use    fast_io(B)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(C)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(D)     // Fast access to PortD (don't fiddle with TRISD)
#use    fast_io(E)     // Fast access to PortE (don't fiddle with TRISE)

// GLOBALS
char gc_buttons_timer;
char gc_IRDA_timer;
char gc_LED_timer;
char gc_uart_timer;
unsigned int16 dc;
int16 data;
int1 flag;


#include <LCD4X20.C>

void AD_isr(void );
void TIMER0_isr(void);
void DispData();
void BlinkLed();
void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm);

void main()
{
   unsigned int16 result;   
   int16 res =0L;
   data = 0L;
   result= 0L;
   flag = 0;
 
 
   set_tris_b(0x17);             // TRISB = 00010111; RB4,RB2,RB1 and RB0 TTL Inputs
   port_b_pullups(FALSE);        // Don't use internal pull up resistors   
   setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
   setup_adc(ADC_CLOCK_DIV_64); 
prescaler
   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_256);
   set_adc_channel(1);  // select the required channel //
   delay_us(10);
   ADFM = 1;
   set_timer0(RTCC_PRELOAD);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_AD);
   enable_interrupts(GLOBAL);
   dc = 0L;
   flag = 0;

   // TODO: USER CODE!!
   // This is the main loop.  You put your "tasks" here.
   while(1)
   {
     DispData();
     BlinkLed();     
   }
 }

void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm)

    int i;
    for(i = 0; i < tm; i++ )
    {
     output_low(PIN_B5);
     delay_ms(on); 
     
     output_high(PIN_B5);
     delay_ms(off);
    }
}


void DispData()
{

   if(gc_buttons_timer)
       return;
   else
      gc_buttons_timer = BUTTONS_TIMER_TICKS;
      printf("%.2f,\t%0Ld \r\n",(dc*0.01) ,data);
}
void BlinkLed()
{
   if(gc_LED_timer)
      return;
   else
      gc_LED_timer  = LED_TIMER_TICKS;
   // Put your LED blinking state machine here.
         ADLX330ACCELBlinkLED(50, 50, 3);
}

//--------------------------------------------------------
// The rtcc interrupt occurs when the rtcc rolls over from FF to 00.
// I have programmed it to interrupt at a 100 Hz rate.
//
// RTCC interrupt rate = Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//                     = 20 MHz / (4 * 256 * 196)
//
//                     = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms  (9.98 ms actually).


#int_TIMER0
void  TIMER0_isr(void)
{
 
   // Reload the RTCC, so it will keep overflowing every 10 ms.
   //set_rtcc(RTCC_PRELOAD);
   
   timer0low = timer0low + RTCC_PRELOAD;
   read_adc(ADC_START_ONLY); //only starts the conversion read_adc(); start a
   dc++;
   // Decrement any timers that are running.
   if(gc_buttons_timer)
       gc_buttons_timer--;

   if(gc_IRDA_timer)
      gc_IRDA_timer--;

   if(gc_LED_timer)
      gc_LED_timer--;

   if(gc_uart_timer)
      gc_uart_timer--;
   
}

#int_AD
void AD_isr(void )
{
   int16 tmp;
    tmp=read_adc(ADC_READ_ONLY); //reads the result of the last conversion and store it in value
    data = (tmp - 512L);     
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: No no no it' does not work at all
PostPosted: Tue Apr 22, 2008 4:35 am     Reply with quote

kein wrote:
Guys I've removed printf() from the interrupt sub routine and now the signal I'm getting is really worst....I've tried to increase the baud rate with no improvement!!


What you do mean the signals are worst? What did you expect to get? What are you really getting? Show us the data.

Robert Scott
Real-Time Specialties
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

alias signal
PostPosted: Tue Apr 22, 2008 4:39 am     Reply with quote

signal is affected very much by aliasing.I was expecting a nice sign wave singal coz my sampling frequecny is 25X my signal frequency
kind regards
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

I'm running nuts!
PostPosted: Tue Apr 22, 2008 5:34 am     Reply with quote

Is there a function that can be placed inside an interrupt subroutine that will send the data to the PC other then printf() function which is known to take too much time?
This thing is driving me nut!
Matro
Guest







Re: I'm running nuts!
PostPosted: Tue Apr 22, 2008 5:58 am     Reply with quote

kein wrote:
Is there a function that can be placed inside an interrupt subroutine that will send the data to the PC other then printf() function which is known to take too much time?
This thing is driving me nut!

That will ever be better to use putchar() and to send just one character with the value you want to scan.

Matro.
Ttelmah
Guest







PostPosted: Tue Apr 22, 2008 7:32 am     Reply with quote

First of all, do a search here about 'INT_AD', and see why you want to avoid this. I have posted quite a bit about this. Use it by all means, but _only_ if you are triggering the ADC, using the CCP. Otherwise all you are doing, is wasting processor time.
You would be better, in the code you have posted, to _read_ the ADC, when you enter the timer interrupt, then re-trigger it. This way the sampling will happen between each timer interrupt, _without_ the overhead associated with another interrupt.
On sending data, it is not inherently printf, but the actual time taken to _send_ characters. If you even just putc, a single character, if the output hardware buffer is full, you will have to wait for an entire character time. Printf, makes this 'worse', because it'll almost always end up sending multiple characters, and you then add the overhead of working out what to send as well... Do a search here on 'bputc'. Buffered serial _transmit_ routines, using a software buffer. In your case, you can (again) save the overhead associated with another interrupt for this, by using your timer 'tick'. So:
Code:

#bit TXIF=0xC.4
#define TXBUFF_SIZE (32) //set to suit your worst case
int8 TXBuff[TXBUFF_SIZE];
int8 in=0,out=0,count=0; //use separate counter for speed
#define incr(x) if(++x==TXBUFF_SIZE)x=0
#byte TXREG=0x19
void bputc(char chr) {
   TXBuff[in] = chr;
   incr(in);
   DISABLE_INTERRUPTS(INT_TIMER0);
   if (++count==TXBUFF_SIZE) {
      --count;
      incr(out);
      //throw away oldest character if overflow
   }
   ENABLE_INTERRUPTS(INT_TIMER0);
}


//--------------------------------------------------------
// The rtcc interrupt occurs when the rtcc rolls over from FF to 00.
// I have programmed it to interrupt at a 100 Hz rate.
//
// RTCC interrupt rate = Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//                     = 20 MHz / (4 * 256 * 196)
//
//                     = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms  (9.98 ms actually).
#int_TIMER0
void  TIMER0_isr(void)
{   
   timer0low = timer0low + RTCC_PRELOAD;
   //Get rid of the INT_AD
   data=(signed int16)(read_adc(ADC_READ_ONLY)) - 512L;
   //read last ADC
   read_adc(ADC_START_ONLY); //start the next conversion
   dc++;
   // Decrement any timers that are running.
   if(gc_buttons_timer)
       gc_buttons_timer--;

   if(gc_IRDA_timer)
      gc_IRDA_timer--;

   if(gc_LED_timer)
      gc_LED_timer--;

   if(gc_uart_timer)
      gc_uart_timer--;
   //Now handle serial transmission of buffered character
   if (count!=0) {
       //A character is waiting
       if (TXIF) {
           //The output buffer has space
           TXREG=TXBuff[out];
           incr(out);
           count--;
           TXIF=0;
      }
   }
   //Now 'key' is that if a character is waiting in the output buffer
   //it checks to see if the hardware can take a character. If it can,
   //just one character is sent.
   //The 'send' overhead is then very small indeed in the timer interrupt.
}

Now, with this, you can send data inside an interrupt (though you will still need to be careful if you send very much....). Just use:

printf(bputc,"what you want to send",vals);

This sends a maximum of 100 characters per second, with minimal delays. Note it also shows how to read the ADC, without using the 'INT_AD', and without wasting time waiting for a reading.
One other comment. You should not read 'data' in a printf, as you are doing. The problem is that printf takes quite a time, and the interrupt could update after half the value is read. Read data like:

int16 local_data;
disable_interrupts(GLOBAL);
local_data=data;
enable_interrupts(GLOBAL);

and printf this 'local' copy. This may be part of the reason for erratic results.

Best Wishes
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Thanks Ttelmah
PostPosted: Wed Apr 23, 2008 2:55 am     Reply with quote

Hi Ttelmah,
It same behaviour as printf() far much and very slow. If I used inside interrupt subroutine, nothing is print out of the terminal. Secondly if I used inside main(0, performance is really poor!
I don't know what I'm doing wrong?
Code:
#include <16F877A.h>
#device *=16
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


//----------------------------------------------------------------------
// DEFINES
//
// With a 4 MHz oscillator, a RTCC pre-scaler of 256, and a RTCC
// preload of 39,  we get an rtcc interrupt rate of 100.16 Hz (Approx.
// every 10 ms).
// This will be our "tick" clock that we use for various event timers.
#define RTCC_PRELOAD (256 - 196)
#define TXBUFF_SIZE (32) //set to suit your worst case

#define incr(x) if(++x==TXBUFF_SIZE)x=0
// Multiply the following values x 10 ms to get the delay times,
// since each timer tick is 10 ms.
#define BUTTONS_TIMER_TICKS      4       // 40 ms
#define IRDA_TIMER_TICKS         10      // 100 ms
#define LED_TIMER_TICKS          50      // 500 ms
#define UART_TIMER_TICKS         100     // 1000 ms


#byte   PORTB = 0x06   // PortB lives in File 6 (data bus)
#byte   PORTC = 0x07   // PortC lives in File 7 (address bus A12 to A8, RX, TX & R/W)
#byte   PORTD = 0x08   // PortD lives in File 8 (address bus A0 to A7)
#byte   PORTE = 0x09   // PortE lives in File 9 (used for DIP switches)

#use    fast_io(B)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(C)     // Fast access to PortB (don't fiddle with TRISB)
#use    fast_io(D)     // Fast access to PortD (don't fiddle with TRISD)
#use    fast_io(E)     // Fast access to PortE (don't fiddle with TRISE)

#include <stdio.h>
#include <24256.C>
#include <LCD4X20.C>
#include <stdlib.h>

#bit  TXIF=0xC.4
#BIT  ADFM = 0xFC0.7
#byte timer0low = 0xfd6
#byte TXREG=0x19


void AD_isr(void );
void TIMER0_isr(void);
void DispData();
void BlinkLed();
void bputc(char chr);
void DispDataAdxl330();
void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm);

unsigned int16 result;   
   int16 res =0L;
   data = 0L;
   result= 0L;
   flag = 0;
 
 
   set_tris_b(0x17);             // TRISB = 00010111; RB4,RB2,RB1 and RB0 TTL Inputs
   port_b_pullups(FALSE);        // Don't use internal pull up resistors   
   setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
   setup_adc(ADC_CLOCK_DIV_64); 
prescaler
   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_256);
   set_adc_channel(1);  // select the required channel //
   delay_us(10);
   ADFM = 1;
   set_timer0(RTCC_PRELOAD);
   enable_interrupts(INT_TIMER0);
   //enable_interrupts(INT_AD);
   enable_interrupts(GLOBAL);
   dc = 0L;
   flag = 0;

   // TODO: USER CODE!!
   // This is the main loop.  You put your "tasks" here.
   while(1)
   {
      int16 local_data = 0L, cnt =0;
     DispData();
     BlinkLed();   

      disable_interrupts(GLOBAL);
      local_data=data;
      cnt = dc;
      enable_interrupts(GLOBAL);
      printf(bputc,"%0Ld,%0Ld\n\r", cnt, local_data);   
   }
 }

void ADLX330ACCELBlinkLED(unsigned char on, unsigned char off, unsigned char tm)

    int i;
    for(i = 0; i < tm; i++ )
    {
     output_low(PIN_B5);
     delay_ms(on); 
     
     output_high(PIN_B5);
     delay_ms(off);
    }
}

//==============================
// If the button debounce delay has not counted down yet,
// then just return.  If it has counted down to 0,
// then reload the timer and execute the rest of
// this function.
// The timer tick is set for a 10 ms period, so let's
// say a suitable debounce time would be 20 ms or more.
// So we'll set CHECK_BUTTONS_TICKS = 2.
// So this function will execute approximately every 2 ticks,
// or 20 ms.

void DispData()
{
   int16 local_data = 0L, cnt =0;

   if(gc_buttons_timer)
       return;
   else
      gc_buttons_timer = BUTTONS_TIMER_TICKS;     
      /*disable_interrupts(GLOBAL);
        local_data=data;
        cnt = dc;
        enable_interrupts(GLOBAL);
        printf(bputc,"%0Ld,%0Ld\n\r",dc,local_data); */
 
}


void BlinkLed()
{
   if(gc_LED_timer)
      return;
   else
      gc_LED_timer  = LED_TIMER_TICKS;
   // Put your LED blinking state machine here.
         ADLX330ACCELBlinkLED(50, 50, 3);
}

void bputc(char chr)
{
   TXBuff[in] = chr;
   incr(in);
   DISABLE_INTERRUPTS(INT_TIMER0);
   if (++count==TXBUFF_SIZE) {
      --count;
      incr(out);
      //throw away oldest character if overflow
   }
   ENABLE_INTERRUPTS(INT_TIMER0);
}


//--------------------------------------------------------
// The rtcc interrupt occurs when the rtcc rolls over from FF to 00.
// I have programmed it to interrupt at a 100 Hz rate.
//
// RTCC interrupt rate = Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//                     = 20 MHz / (4 * 256 * 196)
//
//                     = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms  (9.98 ms actually).
#int_TIMER0
void  TIMER0_isr(void)
{   
   timer0low = timer0low + RTCC_PRELOAD;
   //Get rid of the INT_AD
   data=(signed int16)(read_adc(ADC_READ_ONLY) - 0x0266);    //read last ADC
   read_adc(ADC_START_ONLY); //start the next conversion
   dc++;
   
   // Decrement any timers that are running.
   if(gc_buttons_timer)
       gc_buttons_timer--;

   if(gc_IRDA_timer)
      gc_IRDA_timer--;

   if(gc_LED_timer)
      gc_LED_timer--;

   if(gc_uart_timer)
      gc_uart_timer--;
     
   //Now handle serial transmission of buffered character
   if (count!=0) {
       //A character is waiting
       if (TXIF) {
           //The output buffer has space
           TXREG=TXBuff[out];
           incr(out);
           count--;
           TXIF=0;
      }
   }
 
}


#int_AD
void AD_isr(void )
{
     
    //write_ext_eeprom(dc,(int8)tmp);
     /* disable_interrupts(GLOBAL);
      local_data=data;
      enable_interrupts(GLOBAL);
      printf(bputc,"%0Ld,%0Ld\n\r",dc,local_data); */
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group