Atmel Tiny driving Mosfet to PWM Motor

Thread Starter

Leigh

Joined Feb 11, 2010
20
There are many posts about this I know. I have a circuit that works, but is unreliable. I have a Tiny circuit that I use for many projects with outputs and a status LED. I have set up Timer/Counter 0 in PWM mode, and the output of this circuit drives the mosfet as per the diagram. The PWM is used to slow the motor (obviously). Whenever the motor is turned on and off the status LED goes on and off.

The control program is turning on the motor for a few seconds, then turning it off for a few seconds, repeatedly. Sometimes the motor does not turn off, but the status LED goes off, indicating that the program has done it's bit. Why might the motor sometimes stay on. It speeds up instead, indicating that it is not being controlled by the PWM. I am happiest in digital environment, so motors and mosfets don't have to try hard to confuse me.

Any help is appreciated.
 

Attachments

eblc1388

Joined Nov 28, 2008
1,542
There are several short comings in your design.

1. Wrong MOSFET selected. The STP16NF06 MOSFET needs at least 10V gate-source voltage to fully turns ON but the Tiny AVR port can only provide about 4.8V max.

2. The gate resistor 100K is too high, virtually useless in this case.

3. The Tiny port pin output capacity is only in the ~20mA range and cannot drive the MOSFET ON/OFF fully at required PWM frequency. You'll need to use a current booster to drive it properly.

The following is a circuit designed by one of our senior members to address the problem. You'll also need to use a "logic level" MOSFET in your design, these will turn fully ON with gate voltage of 4.5V or less.

 

Attachments

Thread Starter

Leigh

Joined Feb 11, 2010
20
Thank you for the comments and advice. I was lucky that my circuit worked at all.. actually no, if it hadn't worked at all I might have been forced to re-visit my design earlier.
 

hgmjr

Joined Jan 28, 2005
9,027
Rich (BB code):
/*******************************************************************
** Program to control Dave Bell's robotic dog
**  with status LED on pin11, PD6 and MX PWM on pin14, PB2 / OC0A
*******************************************************************/
#include "DavesDog.h"
 
void init(void) {
    //init Watchdog, reset on watchdog ovfl, reset time =~ 2 s (seems to need 1<<WDIE??)
   WDTCSR |= (1<<WDE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0); // | (1<<WDIE)
   //init progFlags & globals
   initFlags_Globals();
    //prep Port D for LED O/P
   DDRD = (1<<StatusLED);
  //prep Port B for MX control currently on Pin 0, Port B
   DDRB |= (1<<MX_PWM);  
 
  //prep for PWM.. need to use MX_START & MX_STOP in program to run
   TCCR0A = (1<<COM0A1) | (1<<WGM00); //phase correct, o/p OC0A
   OCR0A = 0x20;      //default speed, half
  //enable Global Interrupts
   asm("sei");
} 
 
int main(void) {
   init();
   flashFor(10);
   delay(100);
   while(1) {
    wdt_reset();
  /*  PORTB |= (1<<MX_PWM); //On
    delay(1);
    PORTB &= ~(1<<MX_PWM); //Off
    delay(1);*/
    MX_START;
    delay(100);
    MX_STOP;
    delay(500);
   }
}
 
 
void delay(long x) {
     for(int i = 0; i < x; ++i) {
     wdt_reset();
     _delay_ms(10);  // Wait for about .01 sec times x cycles
     }
}
 
 
void flashFor(int tenths) {
    PORTD |= (1<<StatusLED); //On
    //PORTA |= (1<<PA2); //temp to test using RESET as output
    delay(tenths);    //delay
    PORTD &= ~(1<<StatusLED); //Off
    //PORTA &= ~(1<<PA2); //temp to test using RESET as output
}
 
void initFlags_Globals(void){
      ;
}
I have tried to do a bit of cleanup to your code and place it between
Rich (BB code):
 tags to aid in making it readable.
 
hgmjr
 
Top