User Manual

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* RC 3pi
*
* This 3pi robot program reads two standard radio-control (RC) channels and mixes
* them into motor control. Channel zero (connected to the PD0 input)
* handles forward and reverse, and channel one (connected to the
* PC5 input) handles turning.
*
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <pololu/3pi.h>
/**
* Receiver pulse timings
*
* Standard RC receivers output high pulses between 0.5 ms and 2.5 ms with a neutral
* position of about 1.5 ms. If your RC receiver operates with different pulse
* widths, change these constants below.
*
* The units of these constants is ticks of Timer1 which is set to tick every 3.2
* microseconds.
*
*/
const int minPulseTime = 156; // 0.5 ms
const int neutralPulseTime = 469; // 1.5 ms
const int maxPulseTime = 782; // 2.5ms
const int maxLowPulseTime = 3000; // 9.6ms
struct ChannelStruct
{
volatile unsigned int prevTime;
volatile unsigned int lowDur;
volatile unsigned int highDur;
volatile unsigned char newPulse;
unsigned int pulse;
unsigned char error;
};
struct ChannelStruct ch[2];
/*
* Pin Change interrupts
* PCI0 triggers on PCINT7..0
* PCI1 triggers on PCINT14..8
* PCI2 triggers on PCINT23..16
* PCMSK2, PCMSK1, PCMSK0 registers control which pins contribute.
*
* The following table is useful:
*
* AVR pin PCINT # PCI #
* --------- ----------------- -----
* PB0 - PB5 PCINT0 - PCINT5 PCI0
* PC0 - PC5 PCINT8 - PCINT13 PCI1
* PD0 - PD7 PCINT16 - PCINT23 PCI2
*
*/
// This interrupt service routine is for the channel connected to PD0
ISR(PCINT2_vect)
{
?
Sample Project: RC 3pi © 2001–2019 Pololu Corporation
4. Software Page 10 of 16