2
\$\begingroup\$

I am trying to control the speed of motor using ADC value received using ATMega16, the system works well with 12V. But when I go for 24V the motor runs continuously, even when ADC value is 0.

I have checked with oscilloscope, the PWM output suddenly goes HIGH and remains HIGH even when ADC input is 0.

enter image description here

I believe that the code is correct since the system works perfect in case of 12V.

#include<avr\io.h>
#include<avr\interrupt.h>
#define F_CPU 1000000UL
#include <util/delay.h>

int del;
int x,x1,z,z1;
int rpm = 0;

int main (void)
{
    DDRA = 0X00;
    DDRD = 0xFF;
    DDRC = 0xFF;    
    DDRB = 0xFF;
    ADCSRA = 0x87;
    ADMUX = 0xC0;                   // Selecting ADC0

    while (1)
    {   


        ADCSRA |= (1<<ADSC);
        while ((ADCSRA & (1<<ADIF)) == 0);
        {
            x = ADCL;
            PORTD = x;
            x1 = ADCH;
            PORTC = x1;
            del = ADCL;
            del |= ADCH << 8;
            del = (del-512)/50;

            if (del > 0)
            {
            PORTB = 0x08;
            _delay_ms(del);
            PORTB = 0x00;
            _delay_ms(10-del);
            }

            else
            {
            PORTB = 0x00;
            }
        }

MOSFET Datasheet: http://www.mouser.com/ds/2/205/ixys_98625-342386.pdf

enter image description here

Link to setup

\$\endgroup\$
  • \$\begingroup\$ wrt edited question : something the motor is doing is interfering with the CPU (crashing it or latching it up). I see far too little decoupling on the PSU for a start, and no protection on PortB.3 against spikes fed back (e.g. via the Miller capacitance) through the MOSFET gate. Also, the MOSFET is big and slow; what is your PWM frequency? \$\endgroup\$ – Brian Drummond Jan 6 '18 at 16:18
  • \$\begingroup\$ PWM frequency: 1Khz. The MOSFET is big because later this circuit will be used to run a 60V motor, with a heavy load. How do you suggest I proceed with the interference part ? \$\endgroup\$ – David Flo Jan 6 '18 at 16:20
  • 2
    \$\begingroup\$ @KanishakKatahra Why haven't you added a series resistor to the MOSFET gate (limit oscillation and current limit) and a resistor from gate to ground (MOSFETs at low gate voltages look like constant-current sinks instead of switches that are OFF.) \$\endgroup\$ – jonk Jan 6 '18 at 17:25
  • \$\begingroup\$ What values should the resistors be ? You are suggesting that the MOSFET be in OFF state unless a resistor from gate to ground is added ? \$\endgroup\$ – David Flo Jan 6 '18 at 17:28
  • \$\begingroup\$ @KanishakKatahra Since MCUs often have about \$50-100\:\Omega\$ series impedance anyway, and your MOSFET gate is in the nF range, try \$220\:\Omega\$ for the series resistance. Also tie the gate down to ground with perhaps \$10\:\text{k}\Omega\$? I don't know your switching requirements, but as far as guesses go those are as good as any. If that doesn't help, then it's a different problem or else you need an even more extreme driver change. \$\endgroup\$ – jonk Jan 6 '18 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.