Skip to content
Snippets Groups Projects
Commit 78e3baf5 authored by jamesimmanuel.magsino@stud.h-da.de's avatar jamesimmanuel.magsino@stud.h-da.de
Browse files

???

parent 64e197b4
No related branches found
No related tags found
No related merge requests found
...@@ -120,21 +120,54 @@ void set_progress(double percentage) ...@@ -120,21 +120,54 @@ void set_progress(double percentage)
void callback(uint gpio, uint32_t events) void callback(uint gpio, uint32_t events)
{ {
int b = 4;
int c = 9;
volatile uint another_slice_num = pwm_gpio_to_slice_num(27);
if (events & GPIO_IRQ_EDGE_RISE) // reset pwm counter uint32_t event3 = events;
/* volatile uint another_slice_num = pwm_gpio_to_slice_num(27);
if (events & GPIO_IRQ_LEVEL_HIGH)
{ {
pwm_set_counter(another_slice_num, 0); volatile uint16_t test = pwm_get_counter(another_slice_num);
} }
else if (events & GPIO_IRQ_EDGE_FALL)
else if (events & GPIO_IRQ_LEVEL_LOW)
{ {
volatile uint16_t test = pwm_get_counter(another_slice_num); pwm_set_counter(another_slice_num, 0);
set_progress(100);
} }
*/
// volatile uint16_t test = pwm_get_counter(another_slice_num);
// volatile float distance = (test * 314) / (20000);
// if (distance > 20)
// {
// distance = 20;
// }
// distance = 20 - distance;
// volatile int percentage = (distance / 10) * 100;
// set_progress(percentage);
// pwm_set_counter(another_slice_num, 0);
} }
void init_pwm()
{
gpio_set_function(28, GPIO_FUNC_PWM);
volatile uint slice_num = pwm_gpio_to_slice_num(28);
pwm_set_clkdiv(slice_num, 133);
pwm_set_wrap(slice_num, 0xFFFF);
pwm_set_chan_level(slice_num, PWM_CHAN_A, 10);
pwm_set_enabled(slice_num, true);
}
void pwm_echo_init()
{
volatile uint slice_num = pwm_gpio_to_slice_num(27);
pwm_set_clkdiv(slice_num, 1);
pwm_set_wrap(slice_num, 0xFFFF);
pwm_set_clkdiv_mode(slice_num, PWM_DIV_FREE_RUNNING);
pwm_set_enabled(slice_num, true);
}
int a = 0; int a = 0;
int main() int main()
...@@ -163,23 +196,13 @@ int main() ...@@ -163,23 +196,13 @@ int main()
i2c_write_blocking(i2c_default, 0x70, empty, 17, false); i2c_write_blocking(i2c_default, 0x70, empty, 17, false);
gpio_set_function(28, GPIO_FUNC_PWM); init_pwm();
pwm_echo_init();
volatile uint slice_num = pwm_gpio_to_slice_num(28);
pwm_set_clkdiv(slice_num, 133);
pwm_set_wrap(slice_num, 0xFFFF);
pwm_set_chan_level(slice_num, PWM_CHAN_A, 10);
pwm_set_enabled(slice_num, true);
volatile uint another_slice_num = pwm_gpio_to_slice_num(27);
pwm_set_clkdiv(another_slice_num, 1); gpio_set_irq_enabled_with_callback(27, GPIO_IRQ_LEVEL_LOW, true, &callback);
pwm_set_wrap(another_slice_num, 0xFFFF);
pwm_set_clkdiv_mode(another_slice_num, PWM_DIV_FREE_RUNNING);
pwm_set_enabled(another_slice_num, true);
set_progress(0);
gpio_set_irq_enabled_with_callback(27, GPIO_IRQ_LEVEL_LOW | GPIO_IRQ_LEVEL_HIGH | GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE, true, &callback); while (1)
;
/* /*
timer_hw->dbgpause = 0; timer_hw->dbgpause = 0;
gpio_init(27); gpio_init(27);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment