Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mattdr
supermileage_2018
Commits
55855310
Commit
55855310
authored
Mar 17, 2019
by
thcl
Browse files
Setup Pot read interval timer
parent
a955f421
Changes
3
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy35/src/encoder.cpp
View file @
55855310
...
...
@@ -65,7 +65,7 @@ void encoder_setup(void)
//xPosn.zeroFTM(); //This zeros the counter
//setup the speed timer to run ever 1 sec
//setup the speed timer to run ever
y
1 sec
speed_timer
.
begin
(
print_speed_ISR
,
1000000
);
delay
(
5000
);
//sit tight for a bit
...
...
source_code/Teensy35/src/motor_ctrl.cpp
View file @
55855310
...
...
@@ -32,10 +32,15 @@ float PERIOD = 1/((float) FREQ);
// this helps in calculatations of the lower limit of pwm
float
PERIOD_OVER_255
=
PERIOD
/
255.0
;
//Interrupt for reading potentiometer 0 to determine
//when to change the throttle
IntervalTimer
pot_0_timer
;
int
POT_0_VALUE
=
0
;
void
pot_0_speed_ISR
();
void
turn_all_off
();
int
one_to_scaleFactor
(
int
x
);
void
set_phase
(
int
high1
,
int
high2
,
int
high3
,
int
low1
,
int
low2
,
int
low3
);
...
...
@@ -80,6 +85,14 @@ void motor_setup(void) {
//setup led
pinMode
(
led
,
OUTPUT
);
digitalWrite
(
led
,
HIGH
);
pinMode
(
12
,
OUTPUT
);
//setup the pot_0_timer to run every thirty times a second
pot_0_timer
.
begin
(
pot_0_speed_ISR
,
33333
);
}
void
pot_0_speed_ISR
()
{
POT_0_VALUE
=
get_pot_0_scaled
(
SCALE_FACTOR
,
PERIOD_OVER_255
);
}
void
turn_all_off
()
{
...
...
@@ -177,7 +190,7 @@ void set_phase_float(float f1, float f2, float f3)
// NOTE: The scale factor of is the max value we want out of
// the potentiometer
//digitalWrite(led, HIGH);// start a timer
int
potval
=
get_pot_0_scaled
(
SCALE_FACTOR
,
PERIOD_OVER_255
)
;
int
potval
=
POT_0_VALUE
;
//digitalWrite(led, LOW);// stop a timer
...
...
@@ -240,6 +253,9 @@ void motor_butt_control_precalculated(void)
while
(
1
)
{
//used to check the speed of this function
digitalWrite
(
12
,
HIGH
);
// get the current encoder tics (this does the math to offset)
int
position
=
get_wheel_position_ticks
();
// get position within current electrical revolution
...
...
@@ -250,6 +266,8 @@ void motor_butt_control_precalculated(void)
set_phase_float
(
f1
,
f2
,
f3
);
//used to check the speed of this function
digitalWrite
(
12
,
LOW
);
}
}
...
...
source_code/Teensy35/src/utils.cpp
View file @
55855310
...
...
@@ -43,12 +43,12 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
volatile
float
raw_potval
=
analogRead
(
A0
);
float
potval
=
raw_potval
;
if
((
potval
-
UPWARD_ROC_PREV_VALUE
)
>
UPWARD_ROC_LIMITER
)
{
potval
=
UPWARD_ROC_PREV_VALUE
+
UPWARD_ROC_LIMITER
;
}
else
if
((
potval
-
UPWARD_ROC_PREV_VALUE
)
<
UPWARD_ROC_LIMITER
)
{
potval
=
UPWARD_ROC_PREV_VALUE
-
UPWARD_ROC_LIMITER
;
}
//
if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) {
//
potval = UPWARD_ROC_PREV_VALUE + UPWARD_ROC_LIMITER;
//
}
//
else if ((potval - UPWARD_ROC_PREV_VALUE) < UPWARD_ROC_LIMITER) {
//
potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER;
//
}
UPWARD_ROC_PREV_VALUE
=
potval
;
...
...
@@ -136,9 +136,6 @@ void debug_low_state_by_state(void)
Serial
.
println
(
"Hit space to call turn_all_off()"
);
block_until_spacebar
();
turn_all_off
();
Serial
.
println
(
"Hit space to call setphase(1,0,0,0,0,0"
);
block_until_spacebar
();
set_phase
(
1
,
0
,
0
,
0
,
0
,
0
);
Serial
.
println
(
"Hit space to call setphase(0,0,0,0,0,0)"
);
block_until_spacebar
();
set_phase
(
0
,
0
,
0
,
0
,
0
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment