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

pwm

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pandi



Joined: 17 Sep 2007
Posts: 9
Location: Chennai-India

View user's profile Send private message Send e-mail

pwm
PostPosted: Thu Sep 20, 2007 1:43 am     Reply with quote

--------------------------------------------------------------------------------

hi...

i sent some sine wave index(99 values for one half cycle) . i need for sent index value equal to 10ms

this my program

for (index =0; index<99; index++)
{
set_pwm1_duty( pwmtab[index] );
set_pwm2_duty( pwmtab[index] );

if ( index == 98 )
{
index = 0;
}
}
the above loop will be exeute at eual to 10msec not for each values

l help me sir
Ttelmah
Guest







PostPosted: Thu Sep 20, 2007 2:46 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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