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

trouble with PWM

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



Joined: 02 Apr 2004
Posts: 13
Location: TURKEY

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

trouble with PWM
PostPosted: Sun Nov 19, 2006 3:06 pm     Reply with quote

Hi Everybody...
I try to motor speed control by pwm in my centrifuge prototype.Basic functions are Read keypad, Refresh 7 segment display, Read Motor Rpm, Drive motor by PWM, Count down work time. Centrifuge work fine many times. But sometimes PWM doesn't clear at the end of work time .Does anybody can explain what's wrong in my codes.
My best regards.

Aycan

[/code]
//*******************************************************//
// //
// MEDICAL CENTRIFUGE SPEED CONTROL //
// //
//*******************************************************//

#include <16F876>
#use DELAY(CLOCK=20000000)
#fuses HS,NOWDT,PUT,BROWNOUT,PROTECT,NOLVP

.
.
.
.


#include <DispDrv>
#include <KBD3X2>


//********************************************************
// INIT TIMER0 FOR INTERRUPT
//********************************************************
void Timer_Init(){
.
.
}

//********************************************************
// INIT TIMER1 For CAPTURE
//********************************************************
void Capture_Init(){
.
.
}
//********************************************************
// INIT TIMER 2 FOR PWM MODE
//********************************************************
void Pwm_Init(){

SETUP_CCP2(CCP_PWM); //select pwm mode
SETUP_TIMER_2(T2_DIV_BY_16, 250 , 1); //load period value
SET_PWM2_DUTY(0); //load duty cycle value
}

//********************************************************
// ISR Timer1 for low rpm
//********************************************************
#Int_Timer1
void Timer1_Isr() {
.
.
.
}

//********************************************************
// ISR (CAPTURE) FOR MOTOR RPM MEASUREMENT
//********************************************************
#int_ccp1
void Capture_Isr() {
.
.
.
}

//********************************************************
// ISR FOR TIME INTERVAL
//********************************************************
#INT_RTCC
void CLOCK_ISR(){

SET_RTCC(60);
if(++Counter>=200){
Counter=0; RpmAvrg=1;
if(Start){
if(Second==0){
if(Minute==0) {
EOT=1;
}
else {
Second=59; --Minute;
}
}
else {
--Second;
}
}
}
DispUpdate(); // refresh seven segment display
}
//********************************************************
// MAIN ROUTINE
//********************************************************
void main(){


Timer_Init();
Pwm_Init();
Capture_Init();

ENABLE_INTERRUPTS(INT_RTCC);
ENABLE_INTERRUPTS(INT_CCP1);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);

while (1){

KbChr=KBD_GETC();
if(KbChr!=0) Menu();


if(Eot){ // when count down timer up
Set_Pwm2_Duty(0); // Clear Pwm, motor stop
Eot=0;
}

if(Start){ // when motor running

.
.
calculate rpm using captured time value
.
.

.
.
calculate motor drive pwm value
.
.

}
}
}
Ttelmah
Guest







PostPosted: Sun Nov 19, 2006 3:16 pm     Reply with quote

Without seeing more of the code, hard to be sure, but I don't see 'start' being set to false or 0 anywhere. As such, when 'eot' changes, the PWM duty will be set to zero, anf then eot cleared. Because 'start' is still true, the pwm cycle will then be output again to keep the motor running.

Best Wishes
Aycan



Joined: 02 Apr 2004
Posts: 13
Location: TURKEY

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

PostPosted: Thu Nov 23, 2006 3:17 am     Reply with quote

Dear Ttelmah
I found my mistake and fixed problem. Thanks for interest.
My best regards.
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