Created
August 25, 2024 12:30
-
-
Save Lukelectro/f4fb0651556fa8e680eb9100c265161f to your computer and use it in GitHub Desktop.
First experiment with Raspberry Pi Pico PIO: Waveform for Dickson charge pump https://en.wikipedia.org/wiki/Voltage_multiplier#Dickson_charge_pump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.program chargepump | |
;// this makes the waveshapes for a Dickson charge pump. Frequency can be set by setting PIO state machine clock frequency | |
.wrap_target | |
set pins 0 | |
set pins 2 [10] | |
set pins 0 | |
set pins 1 [10] | |
.wrap | |
% c-sdk { | |
#include "hardware/clocks.h" | |
static inline void chargepump_program_init_and_start(PIO pio, uint sm, uint offset, uint basepin, uint frequency) { | |
pio_sm_config c = chargepump_program_get_default_config(offset); | |
//set pins for use with SET | |
sm_config_set_set_pins(&c,basepin,2); | |
// Set this pin's GPIO function (connect PIO to the pad) | |
pio_gpio_init(pio, basepin); | |
pio_gpio_init(pio, (basepin+1)); | |
// Set the pin direction to output at the PIO | |
pio_sm_set_consecutive_pindirs(pio,sm,basepin,2,true); | |
float div = clock_get_hz(clk_sys) / (frequency*24); // (1 cycle + 1 cycle plus 10 wait)*2 = 24 cycles | |
sm_config_set_clkdiv(&c,div); | |
// Load our configuration, and jump to the start of the program | |
pio_sm_init(pio, sm, offset, &c); | |
// Set the state machine running | |
pio_sm_set_enabled(pio, sm, true); | |
} | |
// functions to stop the charge pump (it just starts after init) | |
static inline void charchgepump_program_stop(PIO pio, uint sm, uint basepin){ | |
pio_sm_set_enabled(pio,sm,false); | |
gpio_set_function(basepin, GPIO_FUNC_SIO); | |
gpio_set_function((basepin+1)%32, GPIO_FUNC_SIO); | |
gpio_put(basepin,0); | |
gpio_put((basepin+1)%32,0);\ | |
} | |
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "pico/stdlib.h" | |
#include "hardware/gpio.h" | |
#include "chargepump.pio.h" | |
int main() | |
{ | |
stdio_init_all(); | |
PIO pio = pio0; | |
uint offset_ch = pio_add_program(pio, &chargepump_program); | |
uint sm_ch = pio_claim_unused_sm(pio, true); | |
chargepump_program_init_and_start(pio,sm_ch,offset_ch,12,50000);// charge pump waveforms on pins 12 and 13, 50 kHz | |
while (1) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment