Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
processer
Commits
f37894bd
Commit
f37894bd
authored
Sep 13, 2018
by
Anders Blomdell
Browse files
Add encoder handling to ball_and_beam-2018
parent
cbd863ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
ball_and_beam-2018/avr/ball_and_beam-2018.c
View file @
f37894bd
...
...
@@ -18,10 +18,11 @@
* AI 2 -- Accelerometer X
* AI 3 -- Accelerometer Y
* AI 4 -- Accelerometer Z
* EI 5 -- Motor Position
*
* AO 0 -- Motor Speed
*/
* EI 0 -- Motor Position
*
*/
/*
* Used I/O pins
...
...
@@ -70,7 +71,6 @@ struct values {
int32_t
motorEncoder
;
int8_t
motorThermalFlag
;
int8_t
ballOnBeam
;
uint8_t
timer
;
};
volatile
struct
values
global
;
...
...
@@ -79,12 +79,6 @@ SIGNAL(ADC_vect)
unsigned
char
channel
=
ADMUX
&
0x0f
;
unsigned
int
value
=
ADCW
;
if
(
global
.
timer
)
{
global
.
timer
--
;
PORTD
&=
~
0x40
;
}
else
{
PORTD
|=
0x40
;
}
switch
(
channel
)
{
case
0
:
{
channel
=
1
;
...
...
@@ -121,7 +115,6 @@ SIGNAL(USART_RXC_vect)
{
char
ch
=
UDR
;
global
.
timer
=
0xff
;
switch
(
serialio_RXC
(
ch
))
{
case
serialio_clearbit
:
{
switch
(
serialio_channel
)
{
...
...
@@ -169,6 +162,39 @@ SIGNAL(USART_RXC_vect)
}
}
SIGNAL
(
TIMER1_OVF_vect
)
{
static
unsigned
char
encoder
;
unsigned
char
e
;
e
=
PIND
&
0x0c
;
// Ignore Z for now
switch
((
encoder
)
|
(
e
>>
2
))
{
case
0x0
:
case
0x5
:
case
0xa
:
case
0xf
:
{
// No change
}
break
;
case
0x1
:
case
0x7
:
case
0xe
:
case
0x8
:
{
global
.
motorEncoder
++
;
}
break
;
case
0x2
:
case
0x4
:
case
0xd
:
case
0xb
:
{
global
.
motorEncoder
--
;
}
break
;
default:
{
// error = 1;
}
break
;
}
encoder
=
e
;
}
int
main
()
{
serialio_init
();
...
...
@@ -181,11 +207,11 @@ int main()
DDRB
=
0x0a
;
// PortB, bits 1 & 3 outputs
PORTC
=
0x00
;
// PortC, pull-ups / initial values
DDRC
=
0x80
;
// PortC, bit 7 output
PORTD
=
0x0
0
;
// PortD, pull-ups / initial values
PORTD
=
0x0
c
;
// PortD, pull-ups / initial values
DDRD
=
0x20
;
// PortD, bit 5 output
TCCR0
=
0x05
;
// Timer0, Clock / 1024
TCCR1A
=
0x83
;
// OC1A 10 bit PWM (fast), active high
TCCR1B
=
0x09
;
// Clock / 1
TIMSK
=
0x04
;
// Enable Timer1 interrupts
OCR1A
=
0
&
0x3ff
;
UCSRA
=
0x00
;
// USART:
UCSRB
=
0x98
;
// USART: RxIntEnable|RxEnable|TxEnable
...
...
@@ -196,6 +222,8 @@ int main()
ADMUX
=
0x0e
;
// Vref = external, right adjust, read 1.22V (Vbg)
ADCSRA
=
0xcf
;
// Enable ADC interrupts, Clock/128
global
.
motorEncoder
=
0x80000000
;
SREG
=
0x80
;
// Global interrupt enable
while
(
1
)
{
unsigned
char
bits
,
channels
,
config
;
...
...
ball_and_beam-2018/matlab/process_test.mdl
View file @
f37894bd
...
...
@@ -6,7 +6,7 @@ Model {
NumRootInports 0
NumRootOutports 0
ParameterArgumentNames ""
ComputedModelVersion "1.
9
"
ComputedModelVersion "1.
11
"
NumModelReferences 0
NumTestPointedSignals 0
}
...
...
@@ -28,9 +28,9 @@ Model {
ModifiedByFormat "%<Auto>"
LastModifiedBy "andersb"
ModifiedDateFormat "%<Auto>"
LastModifiedDate "
Fri Jul 27 17:25:58
2018"
RTWModifiedTimeStamp 45
4541743
ModelVersionFormat "1.%<AutoIncrement:
9
>"
LastModifiedDate "
Thu Sep 13 13:46:49
2018"
RTWModifiedTimeStamp 45
8747140
ModelVersionFormat "1.%<AutoIncrement:
11
>"
ConfigurationManager "None"
SampleTimeColors off
SampleTimeAnnotations off
...
...
@@ -690,7 +690,7 @@ Model {
}
System {
Name "process_test"
Location [7
7
4, 2
8
0, 14
8
9,
926
]
Location [7
6
4, 20
6
, 14
7
9,
852
]
Open on
ModelBrowserVisibility off
ModelBrowserWidth 200
...
...
@@ -704,12 +704,12 @@ Model {
ShowPageBoundaries off
ZoomFactor "100"
ReportName "simulink-default.rpt"
SIDHighWatermark "2
1
"
SIDHighWatermark "2
5
"
Block {
BlockType Constant
Name "Constant1"
SID "2"
Position [375,
25
5, 400,
27
5]
Position [375,
33
5, 400,
35
5]
Value "2.5"
}
Block {
...
...
@@ -737,7 +737,16 @@ Model {
Name "Display"
SID "5"
Ports [1]
Position [510, 317, 605, 393]
Position [510, 397, 605, 473]
Decimation "1"
Lockdown off
}
Block {
BlockType Display
Name "Display1"
SID "24"
Ports [1]
Position [555, 127, 650, 203]
Decimation "1"
Lockdown off
}
...
...
@@ -746,10 +755,10 @@ Model {
Name "Inputs"
SID "6"
Ports [1]
Position [590, 2
0
0, 620,
2
30]
Position [590, 2
8
0, 620, 3
1
0]
Floating off
Location [
10
3,
106
, 8
6
3, 5
6
7]
Open o
n
Location [
7
3,
93
, 8
4
3, 57
9
]
Open o
ff
NumInputPorts "1"
TickLabels "on"
List {
...
...
@@ -772,6 +781,38 @@ Model {
YMax "10"
SampleTime "0"
}
Block {
BlockType Scope
Name "Inputs1"
SID "25"
Ports [1]
Position [590, 55, 620, 85]
Floating off
Location [217, 355, 977, 816]
Open off
NumInputPorts "1"
TickLabels "on"
List {
ListType AxesTitles
axes1 "%<SignalLabel>"
}
List {
ListType ScopeGraphics
FigureColor "[0.5 0.5 0.5]"
AxesColor "[0 0 0]"
AxesTickColor "[1 1 1]"
LineColors "[1 1 0;1 0 1;0 1 1;1 0 0;0 1 0;0 0 1]"
LineStyles "-|-|-|-|-|-"
LineWidths "[0.5 0.5 0.5 0.5 0.5 0.5]"
MarkerStyles "none|none|none|none|none|none"
}
ShowLegends off
TimeRange "100"
YMin "-50"
YMax "60"
SaveName "ScopeData1"
SampleTime "0"
}
Block {
BlockType Mux
Name "Mux1"
...
...
@@ -785,7 +826,7 @@ Model {
Name "Mux2"
SID "9"
Ports [2, 1]
Position [530,
19
7, 565,
2
33]
Position [530,
27
7, 565, 3
1
3]
Inputs "2"
}
Block {
...
...
@@ -803,8 +844,8 @@ Model {
Ports [1]
Position [290, 240, 320, 270]
Floating off
Location [
3
9, 5
60
, 4
9
5, 7
94
]
Open o
n
Location [
1
9, 5
44
, 4
7
5, 7
78
]
Open o
ff
NumInputPorts "1"
TickLabels "on"
List {
...
...
@@ -831,7 +872,7 @@ Model {
Name "S-Function"
SID "12"
Ports [1, 2]
Position [425,
15
6, 485,
18
9]
Position [425,
23
6, 485,
26
9]
FunctionName "analogin"
Parameters "h [30 31 32 33 34]"
EnableBusSupport off
...
...
@@ -856,6 +897,16 @@ Model {
Parameters "h"
EnableBusSupport off
}
Block {
BlockType S-Function
Name "S-Function3"
SID "22"
Ports [1, 2]
Position [420, 141, 480, 174]
FunctionName "encoderin"
Parameters "h [30]"
EnableBusSupport off
}
Block {
BlockType S-Function
Name "S-Function4"
...
...
@@ -871,7 +922,7 @@ Model {
Name "S-Function5"
SID "16"
Ports [1, 2]
Position [420, 2
4
6, 480,
27
9]
Position [420,
3
26, 480,
35
9]
FunctionName "digitalin"
Parameters "h [30 31]"
EnableBusSupport off
...
...
@@ -903,7 +954,7 @@ Model {
Ports [0, 1]
Position [15, 80, 45, 110]
Amplitude "10"
Frequency "0.
1
"
Frequency "0.
5
"
SampleTime "h"
}
Block {
...
...
@@ -945,13 +996,6 @@ Model {
DstBlock "Outputs"
DstPort 1
}
Line {
SrcBlock "S-Function"
SrcPort 2
Points [10, 0; 0, 25]
DstBlock "Mux2"
DstPort 1
}
Line {
SrcBlock "Mux2"
SrcPort 1
...
...
@@ -965,13 +1009,6 @@ Model {
DstBlock "S-Function"
DstPort 1
}
Line {
SrcBlock "S-Function"
SrcPort 1
Points [0, -40; -275, 0]
DstBlock "S-Function1"
DstPort 1
}
Line {
SrcBlock "S-Function1"
SrcPort 1
...
...
@@ -1012,5 +1049,40 @@ Model {
DstBlock "S-Function5"
DstPort 1
}
Line {
SrcBlock "S-Function"
SrcPort 1
Points [0, -50; -85, 0]
DstBlock "S-Function3"
DstPort 1
}
Line {
SrcBlock "S-Function3"
SrcPort 1
Points [0, -35; -270, 0]
DstBlock "S-Function1"
DstPort 1
}
Line {
SrcBlock "S-Function3"
SrcPort 2
Points [30, 0]
Branch {
DstBlock "Display1"
DstPort 1
}
Branch {
Points [0, -95]
DstBlock "Inputs1"
DstPort 1
}
}
Line {
SrcBlock "S-Function"
SrcPort 2
Points [10, 0; 0, 25]
DstBlock "Mux2"
DstPort 1
}
}
}
Write
Preview
Supports
Markdown
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