PWM with MOSFET relays

Thread Starter

Kadav

Joined May 11, 2018
158
Hello i am using arduino to drive a Power MOSFET Photovoltaic Relay Single-Pole, Normally-Open, 0-60V, 2.0A AC / 4.0A DC where its datasheet can be seen here , and i am having trouble doing it with PWM to change the load voltage. i want to use it for a higher appliance but i tried to start out with LED because , i wanted to figure out , how it works with changing the brightness of the light. by changing PWM . from the code below you will se that the output can not be driven until the PWM is 242 and is off when the PWM is above 255 . but as the PWM gets to 242 the LED acts like active HIGH the brightness doesn't change as the PWM increases to 255 or deacreases to 242 .
how can i produce this effect ?

1597135667490.png

datsheet
1597135817995.png


common arduino code in the examples analoginoutserial:
/*

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

double sensorValue = 0;        // value read from the pot
float outputValue = 0;        // value output to the PWM (analog out)
void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 242, 257);

  outputValue+=0.5;

  // change the analog out value:
  analogWrite(analogOutPin,outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  delay(1000);
}
Thanks
 

Alec_t

Joined Sep 17, 2013
14,280
Even allowing for the IC symbol being incorrect, your connection of the load (LED) doesn't seem to correspond to option B or C in Fig 1 of the datasheet and doesn't provide any isolation between the drive circuit and the load. Is that intentional?
What PWM frequency are you using? The IC has a turn-on time of 3.5mA (max) and a turn-off time of 0.5mS (max), suggesting a minimum PWM period > 4mS; i.e a maximum frequency < 250Hz.
 

dendad

Joined Feb 20, 2016
4,451
I think you have chosen a part that has a slow response.
It cannot be switched rapidly so the PWM will not work.
At least that is what I think from just a quick look at the data sheet.

Ah, @Alec_t just pipped me at the post!
 

Thread Starter

Kadav

Joined May 11, 2018
158
Even allowing for the IC symbol being incorrect, your connection of the load (LED) doesn't seem to correspond to option B or C in Fig 1 of the datasheet and doesn't provide any isolation between the drive circuit and the load. Is that intentional?
What PWM frequency are you using? The IC has a turn-on time of 3.5mA (max) and a turn-off time of 0.5mS (max), suggesting a minimum PWM period > 4mS; i.e a maximum frequency < 250Hz.
Yeah the ic circuit is intentional , because i could not find the circuit to replace it , but about the isolation it connected to the arduino and i know i have to isolate it, because i will be using a 2A power supply and load .

About the frequency i am using arduino's frequency for PWM , how can i change it ?
 

Thread Starter

Kadav

Joined May 11, 2018
158
I think you have chosen a part that has a slow response.
It cannot be switched rapidly so the PWM will not work.
At least that is what I think from just a quick look at the data sheet.

Ah, @Alec_t just pipped me at the post!
is there a way to make the Pwm have slow response to .
 

Thread Starter

Kadav

Joined May 11, 2018
158
Yeah the ic circuit is intentional , because i could not find the circuit to replace it , but about the isolation it connected to the arduino and i know i have to isolate it, because i will be using a 2A power supply and load .

About the frequency i am using arduino's frequency for PWM , how can i change it ?
can i connect a bjt to increase the current capacity ?
 

dendad

Joined Feb 20, 2016
4,451
I found this site...
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c
You can play around with reducing the PWM frequency.
It says, in part...


Add this line of code:

TCCR2B = TCCR2B & 0b11111000 | setting;


Where setting is the value of the setting for the respective prescaler.


============================================
|| Frequency [Hz] || Prescaler || Setting ||
============================================
|| 31373.55 || 1 || 0x01 ||
|| 3921.57 || 8 || 0x02 ||
|| 980.39 || 32 || 0x03 ||
|| 490.20 || 64 || 0x04 ||
|| 245.10 || 128 || 0x05 ||
|| 122.55 || 256 || 0x06 ||
|| 30.64 || 1024 || 0x07 ||
============================================
 

Alec_t

Joined Sep 17, 2013
14,280
i know i have to isolate it, because i will be using a 2A power supply and load .
The 2A requirement is independent of the isolation requirement. If the ground connection of the load is connected to the ground connection of the Arduino, as shown, then there is no galvanic isolation. If your load supply is high, such as mains voltage, then for safety you need galvanic isolation. If not, then the common ground arrangement would be safe.
 

Thread Starter

Kadav

Joined May 11, 2018
158
I found this site...
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c
You can play around with reducing the PWM frequency.
It says, in part...


Add this line of code:

TCCR2B = TCCR2B & 0b11111000 | setting;


Where setting is the value of the setting for the respective prescaler.


============================================
|| Frequency [Hz] || Prescaler || Setting ||
============================================
|| 31373.55 || 1 || 0x01 ||
|| 3921.57 || 8 || 0x02 ||
|| 980.39 || 32 || 0x03 ||
|| 490.20 || 64 || 0x04 ||
|| 245.10 || 128 || 0x05 ||
|| 122.55 || 256 || 0x06 ||
|| 30.64 || 1024 || 0x07 ||
============================================
common arduino code in the examples analoginoutserial:
/*

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

double sensorValue = 0;        // value read from the pot
float outputValue = 0;        // value output to the PWM (analog out)
void setup() {
  Serial.begin(9600);
}

void loop() {
  TCCR2B = TCCR2B & 0b11111000;

  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 242, 257);

  outputValue+=0.5;

  // change the analog out value:
  analogWrite(analogOutPin,outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  delay(1000);
}
Like that on line 13?
 

Thread Starter

Kadav

Joined May 11, 2018
158
common arduino code in the examples analoginoutserial:
/*

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

double sensorValue = 0;        // value read from the pot
float outputValue = 0;        // value output to the PWM (analog out)
void setup() {
  Serial.begin(9600);
}

void loop() {
  TCCR2B = TCCR2B & 0b11111000;

  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 242, 257);

  outputValue+=0.5;

  // change the analog out value:
  analogWrite(analogOutPin,outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  delay(1000);
}
Like that on line 13?

How do i deal with the input current that apparently the relay can not go under ? because at probably low duty cycles , i would assume the the arduino realeases low currents that probably could not drive the MOSFET
 

Alec_t

Joined Sep 17, 2013
14,280
because at probably low duty cycles , i would assume the the arduino realeases low currents that probably could not drive the MOSFET
The Arduino puts out 5V pulses. The solid state relay draws an instantaneous current which would normally be determined by a series input resistor of fixed value, hence can be more than 5mA and not related to duty cycle. The average current would, however, depend on duty cycle.
 

Thread Starter

Kadav

Joined May 11, 2018
158
Hello
I have another problem , with my other setting with my Mosfet Relay(datasheet) and power source (5V 3A)
but when i put even an LED between the negative of the source and the MOSFET , the motor( heater in actual sense) doesn't heat . while when i connect immediately like this , the heater heats immediately .

How to fix that ?
1597163622903.png
 
Top