 |
 |
| View previous topic :: View next topic |
| Author |
Message |
kein
Joined: 23 Jul 2007 Posts: 103
|
| No not higher than MAX-SIZE |
Posted: Tue May 06, 2008 8:02 am |
|
|
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
|
| Re: No not higher than MAX-SIZE |
Posted: Tue May 06, 2008 8:28 am |
|
|
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
|
| Yeah |
Posted: Tue May 06, 2008 6:18 pm |
|
|
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
|
| Quick question |
Posted: Tue May 06, 2008 6:27 pm |
|
|
| 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
|
|
Posted: Wed May 07, 2008 7:37 am |
|
|
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 |
|
 |
|
|
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
|