# FunctionGen

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Problem Statement

Function generators are expensive. Since I moved away from the university, I can no longer pillage the senior design lab for design tools, and I'd like to have a variable frequency / duty cycle mosfet driver for designing power converters with. All I need is a square wave, and with enough current capability to be able to drive a power MOSFET directly. Since its a piece of test equiptment, it doesn't make sense to make it battery powered so I would like to use some of the small transformers in the junk box and build a switching regulator to bring the voltage down to a reasonable and adjustable drive level.

## Design

I used a left-over MSP430F1132 chip with a 4Mhz crystal. 10-bit ADC inputs sample two trim pots for frequency and duty cycle. These are converted from the 0-1023 range to a clock divider for the 16-bit Timer_A via the following equation, which is designed to give a logrithmic control over the entire frequency range of 2Mhz - 61Hz with only a single knob. An LCD display was added to show the current freq / duty cycle setting and a button to enable a fine tuning mode as well as a 'locked' mode.

The following M-code shows the process:

```freq = 4e6; %clock frequency
div_max = 65535; %not currently used in the calculations
fdial = 0:1:1023; %input range of the frequency trimpot

%freq_desired = (freq/2).*(10.^(fdial./226.5)./(10^(1023/226.5))); %226.5 results in a 65535 end point
%divisor_modeled = freq ./ freq_desired;
%When simplified becomes...
divisor_modeled = 2.*(1.010226.^(1023+fdial));
divisor_modeled = uint16(divisor_modeled);

subplot(2,1,1);
stairs(fdial, freq ./ uint32(divisor_modeled));
set(gca, 'YScale', 'log')
axis ([0 1023 0 freq]);
subplot(2,1,2);
stairs(fdial, uint32(divisor_modeled));
set(gca, 'YScale', 'log')
axis ([0 1023 0 65535]);
```