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
3394fa63
Commit
3394fa63
authored
Jul 27, 2018
by
Anders Blomdell
Browse files
Change to fast PWM
parent
114a55bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
ball_and_beam-2018/avr/ball_and_beam-2018.c
View file @
3394fa63
...
@@ -7,7 +7,8 @@
...
@@ -7,7 +7,8 @@
/*
/*
* Serial I/O assignments:
* Serial I/O assignments:
*
*
* DI 0 -- Motor Overtemp
* DI 0 -- Ball On Beam
* DI 1 -- Motor Overtemp
*
*
* DO 0 -- Motor Brake
* DO 0 -- Motor Brake
* DO 1 -- Accelerometer Self-Test
* DO 1 -- Accelerometer Self-Test
...
@@ -124,18 +125,18 @@ SIGNAL(USART_RXC_vect)
...
@@ -124,18 +125,18 @@ SIGNAL(USART_RXC_vect)
switch
(
serialio_RXC
(
ch
))
{
switch
(
serialio_RXC
(
ch
))
{
case
serialio_clearbit
:
{
case
serialio_clearbit
:
{
switch
(
serialio_channel
)
{
switch
(
serialio_channel
)
{
case
0
:
{
PORTB
&=
~
0x08
;
}
break
;
case
0
:
{
PORTB
&=
~
0x08
;
}
break
;
// motorBrake
case
1
:
{
PORTC
&=
~
0x80
;
}
break
;
case
1
:
{
PORTC
&=
~
0x80
;
}
break
;
// accelerometerSelfTest
}
}
}
break
;
}
break
;
case
serialio_setbit
:
{
case
serialio_setbit
:
{
switch
(
serialio_channel
)
{
switch
(
serialio_channel
)
{
case
0
:
{
PORTB
|=
0x08
;
}
break
;
case
0
:
{
PORTB
|=
0x08
;
}
break
;
// motorBrake
case
1
:
{
PORTC
|=
0x80
;
}
break
;
case
1
:
{
PORTC
|=
0x80
;
}
break
;
// accelerometerSelfTest
}
}
}
break
;
}
break
;
case
serialio_pollbit
:
{
case
serialio_pollbit
:
{
if
(
serialio_channel
<
1
)
{
if
(
serialio_channel
<
2
)
{
serial_readbits
|=
(
1
<<
serialio_channel
);
serial_readbits
|=
(
1
<<
serialio_channel
);
}
}
}
break
;
}
break
;
...
@@ -176,15 +177,15 @@ int main()
...
@@ -176,15 +177,15 @@ int main()
serial_readconfig
=
0
;
serial_readconfig
=
0
;
PORTA
=
0x00
;
// PortA, pull-ups
PORTA
=
0x00
;
// PortA, pull-ups
DDRA
=
0x00
;
// PortA, all inputs
DDRA
=
0x00
;
// PortA, all inputs
PORTB
=
0x
0
0
;
// PortB, pull-ups / initial values
PORTB
=
0x
1
0
;
// PortB, pull-ups / initial values
DDRB
=
0x0a
;
// PortB, bits 1 & 3 outputs
DDRB
=
0x0a
;
// PortB, bits 1 & 3 outputs
PORTC
=
0x00
;
// PortC, pull-ups / initial values
PORTC
=
0x00
;
// PortC, pull-ups / initial values
DDRC
=
0x80
;
// PortC, bit 7 output
DDRC
=
0x80
;
// PortC, bit 7 output
PORTD
=
0x00
;
// PortD, pull-ups / initial values
PORTD
=
0x00
;
// PortD, pull-ups / initial values
DDRD
=
0x20
;
// PortD, bit 5 output
DDRD
=
0x20
;
// PortD, bit 5 output
TCCR0
=
0x05
;
// Timer0, Clock / 1024
TCCR0
=
0x05
;
// Timer0, Clock / 1024
TCCR1A
=
0x83
;
// OC1A 10 bit PWM (
Phase Correct), clear A on matc
h
TCCR1A
=
0x83
;
// OC1A 10 bit PWM (
fast), active hig
h
TCCR1B
=
0x0
1
;
// Clock / 1
TCCR1B
=
0x0
9
;
// Clock / 1
OCR1A
=
0
&
0x3ff
;
OCR1A
=
0
&
0x3ff
;
UCSRA
=
0x00
;
// USART:
UCSRA
=
0x00
;
// USART:
UCSRB
=
0x98
;
// USART: RxIntEnable|RxEnable|TxEnable
UCSRB
=
0x98
;
// USART: RxIntEnable|RxEnable|TxEnable
...
@@ -215,9 +216,17 @@ int main()
...
@@ -215,9 +216,17 @@ int main()
if
(
channels
&
0x08
)
{
serialio_putchannel
(
3
,
local
.
accelerometerY
);
}
if
(
channels
&
0x08
)
{
serialio_putchannel
(
3
,
local
.
accelerometerY
);
}
if
(
channels
&
0x10
)
{
serialio_putchannel
(
4
,
local
.
accelerometerZ
);
}
if
(
channels
&
0x10
)
{
serialio_putchannel
(
4
,
local
.
accelerometerZ
);
}
if
(
channels
&
0x20
)
{
serialio_putchannel
(
5
,
local
.
motorEncoder
);
}
if
(
channels
&
0x20
)
{
serialio_putchannel
(
5
,
local
.
motorEncoder
);
}
if
(
bits
&
0x01
)
{
serialio_putbit
(
0
,
PORTB
&
0x10
);
}
// thermalFlag
if
(
bits
&
0x01
)
{
// ballOnBeam
serialio_putbit
(
0
,
PINB
&
0x01
);
}
if
(
bits
&
0x02
)
{
// thermalFlag
serialio_putbit
(
1
,
!
(
PINB
&
0x10
));
}
if
(
config
)
{
if
(
config
)
{
CONF_DIGITAL_IN
(
0
,
CONF_RESOLUTION
(
1
));
// motorTemp
CONF_DIGITAL_IN
(
0
,
CONF_RESOLUTION
(
1
));
// ballOnBeam
CONF_DIGITAL_IN
(
1
,
CONF_RESOLUTION
(
1
));
// motorTemp
CONF_DIGITAL_OUT
(
0
,
CONF_RESOLUTION
(
1
));
// motorBrake
CONF_DIGITAL_OUT
(
0
,
CONF_RESOLUTION
(
1
));
// motorBrake
CONF_DIGITAL_OUT
(
1
,
CONF_RESOLUTION
(
1
));
// accelerometerSelfTest
CONF_DIGITAL_OUT
(
1
,
CONF_RESOLUTION
(
1
));
// accelerometerSelfTest
...
...
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