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 with 16F88, spike on power down

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



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PWM with 16F88, spike on power down
PostPosted: Wed Dec 24, 2008 1:55 am     Reply with quote

I'm using a 16F88 chip to control motor speed with PWM. 0% duty cycle is full off, and 100% duty cycle full on, as you would expect. The PWM output of the PIC is connected to a NPN transistor to provide inverting and an open collector output that the motor control circuitry expects.

I've noticed that when I pull power from the circuit, there's a spike on the PWM output, which causes the motor to get a brief pulse of power (command duty cycle is at 0% when this happens). I can think of ways in hardware to prevent this, but I don't understand why the PIC would output this spike on the PWM channel. Any ideas? The code:

Code:

#include <16f88.h>
#byte WDTCON=0x105 // the WDT configuration register on the 16F88, has to be manually set due to a CCS compiler error in setup_counters and setup_timer0
#DEVICE ADC=10
#device *=16
#fuses NOWDT,NOPROTECT,NOMCLR,NOLVP,HS,CCPB3
#use delay(clock=20000000)

float get_throttle_reading();


void main() {
     float throttle_reading;
     long PWM_duty_cycle;
 
     setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM

     setup_timer_2(T2_DIV_BY_1, 249, 1); // about 20kHz.  In set_pwm1_duty, 0 is fully off, and 1000 fully on.
                                        // It will also be ensured to start out off.
     // The 249 value was chosen instead of 250 to ensure a full-on stream with a value of 1000 for the PWM.
     set_pwm1_duty(0);


     setup_adc(  ADC_CLOCK_INTERNAL  );
     setup_adc_ports( sAN0 | sAN1 | sAN3 );
     
     set_adc_channel(3);
     
  //   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256); // not using right now
     WDTCON = 0x11; // 0x15; // 0x14 turns WDT off, set for approximately 1s WDT w/ 0x15, 1/16th of a second with 0x11
     
     throttle_reading = get_throttle_reading();
     
     // high pedal disable, the pedal outputs 0.8V when fully off
     while( throttle_reading > 0.80) {
          restart_wdt();
          throttle_reading = get_throttle_reading();
          delay_ms(20);
     }

     while( TRUE ) {
          restart_wdt();
         
          throttle_reading = get_throttle_reading();

          if(throttle_reading < 0.85) PWM_duty_cycle = 0;
          else if(throttle_reading > 4.0) PWM_duty_cycle = 1000;
          else {
               PWM_duty_cycle = (long)(((HEPA_reading - 0.85) / 3.15 ) * 1000.0);

          }

          set_pwm1_duty(PWM_duty_cycle);
  }

}

float get_throttle_reading() {
     long value;
     int i;
     
     value = 0;
     
     for(i=0;i<10;i++) {
          value+=read_adc();
          restart_wdt();
     }
     return (5.0 * ((float)value / 10230.0)); // the 10230.0 takes into account the divide by 10 for the accumulation of 10 readings
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Dec 24, 2008 2:35 am     Reply with quote

Does the pulse also appear on reset? If not, activation of brown-out reset may help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 24, 2008 2:39 am     Reply with quote

It's possibly caused by back-EMF. Do you have a diode connected
across the motor, as shown in this schematic ? If not, add one.
http://www.cpemma.co.uk/555pwm.html
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Wed Dec 24, 2008 3:06 am     Reply with quote

You may also consider adding a decoupling capacitor 0.1uF in // with the diode.
Ttelmah
Guest







PostPosted: Wed Dec 24, 2008 3:29 am     Reply with quote

It won't be back-emf, if the duty is at 0% when he switches off (as he says).
My thoughts would be:
Supply sequencing. How is the PIC supply generated, relative to the power rail feeding the motor?. What sort of size motor is involved (current/voltage). One thing that could happen, is that if the motor supply drops before the PIC supply, you could be generating a reverse voltage across your voltage regulator (potentially damaging), and depending what internal diode structures are 'around' the circuit, currents may be flowing to places you don't expect.
How is the NPN transistor driven?. Is there anything to ensure the transistor switches 'off', if connected to an open circuit?. If you have brownout reset selected, the chip will reset, before the supply disappears.
What does the circuit do, when power is initially applied?. Would it enable the PWM then?. Thought here is that as the supply is dropping, the circuit is resetting, then restarting, then resetting again.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

seconding tlemah
PostPosted: Thu Dec 25, 2008 1:54 pm     Reply with quote

be sure that in the event of TRIS being wrong ( as it will be at power on OR after reset ) - even momentarily - that there is some biasing resistor to insure the switch element is biased OFF - this is especially critical with mosfet switches - even 10K ohms is usually plenty - a PWM duty of 0% is nOT enuf by itself.
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

Re: seconding tlemah
PostPosted: Sat Dec 27, 2008 8:40 pm     Reply with quote

asmboy wrote:
be sure that in the event of TRIS being wrong ( as it will be at power on OR after reset ) - even momentarily - that there is some biasing resistor to insure the switch element is biased OFF - this is especially critical with mosfet switches - even 10K ohms is usually plenty - a PWM duty of 0% is nOT enuf by itself.


This is all good information - I left on vacation right after posting the original question, so will try some of this out when I get back.

A little additional info, the motor is being driven with a IGBT module from a bank of batteries isolated from the PIC power supply. The IGBT module has an isolated gate driver circuit. The PIC is responsible for sending the PWM signal. The NPN transistor being used to achieve an open collector output and inverting to the gate driver circuit did not have a resistor biasing the input to the transistor to ground, so this might be the problem. However, the momentary "on" pulse I was talking about does not occur on startup.

Max motor current is 1000A, at 170V, with 100-200A continuous being pulled, so noise could certainly be an issue!
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