Now I am reading the GuzuntyPi's 8p8i PWM code in the demo program.
Guzunty Pi gz_8p8i waveform - Last edited by campbellsan, 13 days ago 2013masr25
https://github.com/Guzunty/Pi/wiki/gz_8p8i-waveform
In this core, ... the 'pwms' output bus switches each bit dynamically between logic '1' and logic '0' as an internal counter passes the value of a cached
value for each pwm output bit. When the internal counter rolls over, the output bits are set back to logic '1' and the cycle repeats.
To control the PWM outputs, write a pwm number (0 - 7) to the SPI bus followed by a duty cycle value (0 - 32).
... To support this, the core needs its own clock.
In the Guzunty Pi, we use one of the GPIO special out functions (GPCLK0 on GPIO4). The Pi hardware clock output is wired to the 'clk' signal ...
Pin Signal
1 pwms<0>
2 pwms<1>
3 pwms<2>
4 pwms<3>
8 pwms<4>
9 pwms<5>
35 pwms<6>
36 pwms<7>
19 inputs<0>
20 inputs<1>
22 inputs<3>
24 inputs<2>
25 inputs<4>
26 inputs<5>
6 inputs<6>
7 inputs<7>
* gz_8p8i.c - 8 way 5 bit pwm plus eight input Guzunty core.
unsigned char reg = 4;
char dir = 1;
unsigned char values[8] = {0,0,0,0,0,0,0,0};
void exercise_pwms() {
unsigned char payload[2];
reg += dir;
if (reg == 7 || reg == 0) {
dir = -dir;
}
values[reg] = 0x1f;
int i;
for(i = 0; i < 8; i++) {
payload[0] = i;
payload[1] = 0x1f - values[i];
if (values[i] > 1) {
values[i] -= 2;
}
else {
values[i] = 0;
}
gz_spi_write(payload);
}
usleep(100000);
}
main()
gz_clock_ena(GZ_CLK_5MHz, 0x02); // 2.5 Mhz
printw("Modulating PWMs.\n");
exercise_pwms();
.END
No comments:
Post a Comment