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

missed pulses from PWM when changing timer 2 period

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



Joined: 06 Jul 2007
Posts: 15
Location: Montreal Canada

View user's profile Send private message Visit poster's website

missed pulses from PWM when changing timer 2 period
PostPosted: Thu Sep 20, 2007 1:18 pm     Reply with quote

Hi.
I'm using a 16f886 to control a bipoler stepper via an A3984 ic (step/dir/analog pwr signals). I am using ccp1 along with timer2 in PWM config. to provide the step pulse.

I need to change the frequency on the fly to accelerate the stepper. I do this by changing my PR2 register directly (timer2 period). I have found that sometimes I seem to lose a pulse or two when changing the period (about 2.4ms without a pulse). Has anyone else encountered this?

Since I am trying to accerate a stepper quite quickly, missing step signals is really not an option.
matt_at_hanbay



Joined: 06 Jul 2007
Posts: 15
Location: Montreal Canada

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 20, 2007 4:59 pm     Reply with quote

Problem resolved. Maybe this will help someone else.

So.. the issue was that I was increasing the frequency by decreasing the value of PR2. For example, the current period may be 65, and I was decreasing it to 55. the PR2 value is double buffered, and the logic is smart enough that if TMR2 is very close to the current PR2 (eg 65), the new PR2 value will not be written into the register. This prevents PR2 from being updated while it is being read. However... it does not protect against weak code! If for example TMR2 is 56, and you try to change PR2 to 55, it will be updated, but TMR2 has already passed 55, so it will count all the way to 255 before restarting and counting up to our period of 55. This will cause a period of 255+55 instead of just 55. (3x the correct period). This cause sufficient missed step pulses to stall the stepper.

In my case the solution was to wait for TMR2 to reset before updating PR2.

Anyways, hope this saves someone else some headache.

-Matt
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