Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embedded-systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Immanuel Magsino
embedded-systems
Commits
1eb61c88
Commit
1eb61c88
authored
3 months ago
by
Pascal Koch
Browse files
Options
Downloads
Patches
Plain Diff
prak3 aufgabe2
parent
32a437a9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+34
-26
34 additions, 26 deletions
src/main.c
with
34 additions
and
26 deletions
src/main.c
+
34
−
26
View file @
1eb61c88
...
...
@@ -2,7 +2,8 @@
#include
<hardware/i2c.h>
#include
<stdio.h>
#include
<unistd.h>
#include
"hardware/pwm.h"
#include
<hardware/pwm.h>
const
uint8_t
init
[
4
]
=
{
0x21
,
0xa0
,
0xe1
,
0x81
};
const
uint8_t
zeile
[
8
]
=
{
0x00
,
0x02
,
0x04
,
0x06
,
0x08
,
0x10
,
0x12
,
0x14
};
const
uint8_t
fill
[
17
]
=
{
0x00
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
};
...
...
@@ -105,26 +106,24 @@ const uint8_t better_matrix[65][17] = {
{
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0xff
,
0x00
,
0
b11111111
,
0x00
},
};
void
set_progress
(
int
percentage
)
void
set_progress
(
double
percentage
)
{
int
numerator
=
(
percentage
*
32
)
/
100
;
for
(
int
i
=
0
;
i
<=
numerator
;
i
++
)
{
i2c_write_blocking
(
i2c_default
,
0x70
,
better_matrix
[
i
],
17
,
false
);
// sleep
// for (int j = 0; j < 100000; j++)
// {
// volatile int i = 0;
// }
}
}
int
a
=
0
;
void
callback
()
{
a
=
1
;
int
b
=
4
;
int
c
=
9
;
}
int
a
=
0
;
int
main
()
{
// clock enable: 100000 baud (bit/s)
...
...
@@ -151,33 +150,42 @@ int main()
i2c_write_blocking
(
i2c_default
,
0x70
,
empty
,
17
,
false
);
set_progress
(
200
);
set_progress
(
30
);
gpio_set_function
(
28
,
GPIO_FUNC_PWM
);
uint
slice_num
=
pwm_gpio_to_slice_num
(
28
);
// 133 Mhz / 133 = 1 Mhz => 1 cycle = 1 us
// 10 mikrosekunden
pwm_set_clkdiv
(
slice_num
,
133
);
pwm_set_wrap
(
slice_num
,
65000
);
pwm_set_wrap
(
slice_num
,
0xFFFF
);
pwm_set_chan_level
(
slice_num
,
PWM_CHAN_A
,
10
);
pwm_set_enabled
(
slice_num
,
true
);
uint
test
=
500
;
set_progress
(
0
);
uint
another_slice_num
=
pwm_gpio_to_slice_num
(
27
);
// 65000 * 133 * 10^6 10 meters
// 65000 max cycles
pwm_set_clkdiv
(
another_slice_num
,
133
);
pwm_set_wrap
(
another_slice_num
,
65000
);
pwm_set_clkdiv_mode
(
another_slice_num
,
PWM_DIV_
B_HIGH
);
pwm_set_wrap
(
another_slice_num
,
0xFFFF
);
pwm_set_clkdiv_mode
(
another_slice_num
,
PWM_DIV_
FREE_RUNNING
);
pwm_set_enabled
(
slice_num
,
true
);
int
b
=
7
;
gpio_set_irq_enabled_with_callback
(
27
,
GPIO_IRQ_EDGE_FALL
,
true
,
callback
);
set_progress
(
100
);
timer_hw
->
dbgpause
=
0
;
gpio_init
(
27
);
gpio_init
(
28
);
gpio_set_dir
(
28
,
GPIO_OUT
);
while
(
1
)
{
gpio_put
(
28
,
true
);
sleep_us
(
10
);
gpio_put
(
28
,
false
);
while
(
!
gpio_get
(
27
))
;
uint32_t
start
=
time_us_32
();
while
(
gpio_get
(
27
))
;
uint32_t
end
=
time_us_32
();
uint32_t
duration
=
end
-
start
;
volatile
float
distance
=
duration
*
314
/
2000
;
}
a
=
3
;
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment