Hey guys,
I was trying to make a pulse generator for a project. My goal was to create a square pulse generator of 150 kHz and 5V, using this code:
void setup(){
Serial.begin(9600);
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
}
The purpose of this pulse generator is to connect it to a IRF540N transistor in a DC-DC booster; however, the PWM generated only 2.5V and not the desired value of 5V.
I was wondering whether there is a code I can use to make the PWM generate 5V pulses with frequencies of at least 150 KHz.
#include <TimerOne.h>
// This example creates a PWM signal with 25 kHz carrier.
//
// Arduino's analogWrite() gives you PWM output, but no control over the
// carrier frequency. The default frequency is low, typically 490 or
// 3920 Hz. Sometimes you may need a faster carrier frequency.
//
// The specification for 4-wire PWM fans recommends a 25 kHz frequency
// and allows 21 to 28 kHz. The default from analogWrite() might work
// with some fans, but to follow the specification we need 25 kHz.
//
// http://www.formfactors.org/developer/specs/REV1_2_Public.pdf
//
// Connect the PWM pin to the fan's control wire (usually blue). The
// board's ground must be connected to the fan's ground, and the fan
// needs +12 volt power from the computer or a separate power supply.
const int fanPin = 4;
void setup(void)
{
Timer1.initialize(40); // 40 us = 25 kHz <<<<< 6us = 166kHz Serial.begin(9600);
}
void loop(void)
{
// slowly increase the PWM fan speed
//
for (float dutyCycle = 30.0; dutyCycle < 100.0; dutyCycle++) {
Serial.print("PWM Fan, Duty Cycle = ");
Serial.println(dutyCycle);
Timer1.pwm(fanPin, (dutyCycle / 100) * 1023);
delay(500);
}
}
That way of timing events depends on the controller system clock. 8, 16 or more MHz.... the result will be different, very different.
We used such code at the micro computer first experiments 50 years ago....