Chapter 10: C Structures
signed char as arguments and returning a pointer to a pwm structure.
irst Let’s redo the struct:
struct
unsigned Widt
then we rite
m m ePWM nt p , un gned ulseWidth)
ruct pwm temp;
.pulseFreq = pulseFreq;
this function we reuse the names pulseFreq and pulseWidth and cause no
e
pulser1k50 = makePWM(1000,128);//make a 50% duty 1000 kHz pulse
pulser1k25 = makePWM(1000,64);//make a 25% duty 1000 kHz pulse
puls
When of the
structure to the function. For tiny structures, this won’t matter much, but for large
structures we can eat a lot of RAM, since the entire structure will be pushed onto
the stac idth in a list of
pwm structs:
We will write a function makePWM to initialize a PWM structure by accepting an
int and an un
F
{
int pulseFreq;
pulse h;
}pwm;
w our function:
struct pw ak (i ulseFreq si char p
{
st
temp
temp.pulseWidth = pulseWidth;
return temp;
}
In
conflict because one set is bound to the struct and the other is bound to th
function.
We can use makePWM to dynamically initialize structures:
struct pwm pulser1k50;
struct pwm pulser1k25;
struct pwm pulser4k10;
er4k10 = makePWM(4000,25);//make a 10% duty 4000 kHz pulse
we use a structure as an argument in a function we send a copy
k. Let’s write a function to find the pulse with the greatest w
3