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 CCS Technical Support

Sampling frequency with timer0 interrupts problem
Goto page Previous  1, 2, 3, 4
 
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

No not higher than MAX-SIZE
PostPosted: Tue May 06, 2008 8:02 am     Reply with quote

No not higher than MAX-SIZE! it prints from x=0 to 1023 and then repeat the same thing all over again without stopping when x equals 1023!
What I need is take 1023 samples once a button is pressed and display that on the computer from arr[x=0] to arr[x=1023] and the program should return no further printing/display until the button is pressed next..
Code:
for(x = 0; x < MAX_SIZE; x++)
                 printf("%04Lu,\t%02d\r\n",x, data.Buf[x]);
if(x==MAX_SIZE) //should exit from here until the next button pressed

however it's not doing that
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: No not higher than MAX-SIZE
PostPosted: Tue May 06, 2008 8:28 am     Reply with quote

Ah, then DispData is stopping at x=1024 just like it is supposed to. Your problem then is that DispData is getting called over and over again. That is where you should focus your attention: Why is DispData being called over and over.

Robert Scott
Real-Time Specialties
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Yeah
PostPosted: Tue May 06, 2008 6:18 pm     Reply with quote

I thought it won't matter as long as the condition that x==MAX_SIZE is true...
I can't get a solution to this, my project is due in 3weeks.
Kind regards
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

Quick question
PostPosted: Tue May 06, 2008 6:27 pm     Reply with quote

Ttelmah wrote:
Use Timer2, or change your crystal frequency.

Best Wishes

Hi Ttelmah,
I'm going to use Timer2 as you recommended however I'm not sure if setting timer2 as follow is right...
Code:
Rload = 48*10^6 * t/(4*Prescaler*Poscaler)
         = 48*10^6 * t/(4*P16*16)
         = 468.75
         = 469
and then
setup_timer_2(T2_DIV_BY_16,469,16);      // (48000000*0.01/(4*16*16)) interrupts every 1ms

This correct?
Ttelmah
Guest







PostPosted: Wed May 07, 2008 7:37 am     Reply with quote

No.
Timer2, is an _8bit_ counter. So highest value in the counter reset, is _255_ (giving 256 counts).
The 'point' about it is that it has a programmable reset, so that you can generate nice counts, but you still have to select a 'tick' that suits it to some extent.
Realistically, if you _must_ have 10mSec ticks, you are going to have to use another clock rate (possibly on timer 1). Alternatively, You can generate a tick that itself will be called at a 'subdivision' of your target time, and just only execute the required code very few calls.
So for Timer2, you can use:

setup_timer_2(T2_DIV_BY_16,249,10);

Then in the interrupt have:
Code:

   static int8 tick=3;
   if (--tick==0) {
      tick=3;
      //execute code here


   }


This gives code execution every 3*250*16*10*4 cycles of the main clock. The required 10mSec.

Best Wishes
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 Previous  1, 2, 3, 4
Page 4 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