Ttelmah Guest
|
|
Posted: Thu Sep 20, 2007 2:46 am |
|
|
Do you want 99 values, or 100?. If you want to generate a 1Hz signal, you would need 100 values at 10mSec intervals.
Now, one or the other of the tests is 'redundant'. The for loop itself, will reset the counter, but you are then doing it yourself, inside the loop.
Then, as it currently stands, the code will output the data as fast as possible, not at 10mSec intervals. This is probably the main problem:
Code: |
int8 index=0; //esure the counter is initialised
while (TRUE) {
//for a permanent loop
set_pwm1_duty( pwmtab[index] );
set_pwm2_duty( pwmtab[index] );
if (++index>=98) index=0;
delay_ms(10);
}
|
Key difference is the delay.
This will output the data very slightly slower than the specified interval, because of the time taken by the loop. If you want accuracy, then the solution is to use a hardware timer.
If you look at the thread 'a problem wth interrupt_external', running a cople of days ago, you will see how I use a timer interrupt to output data at an interval. The same basic code (with the timer adjusted to give exactly 10mSec, and the array containing 99 values, instead of 4), would do what you want.
Best Wishes |
|