line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
725
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
|
|
|
|
|
|
package Device::Chip::MAX31855; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw/Device::Chip/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
492
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Device::Chip::MAX31855 - chip driver for MAX31855 thermocouple amplifier |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Device::Chip::MAX31855; |
14
|
|
|
|
|
|
|
my $chip = Device::Chip:MAX31855->new; |
15
|
|
|
|
|
|
|
$chip->mount(Device::Chip::Adapter::...->new)->get; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $temp = $chip->read_thermocouple()->get; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Device::Chip::MAX31855 communicates with the MAX31855 SPI thermocouple amplifier. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The MAX31855 is a digital thermocouple amplifier and converter |
24
|
|
|
|
|
|
|
containing a thermocouple measurement circuit, cold junction |
25
|
|
|
|
|
|
|
compensator, and digital SPI interface. It provides temperature |
26
|
|
|
|
|
|
|
measurements of an attached K-type thermocouple and the local cold |
27
|
|
|
|
|
|
|
junction sensor, and can detect faults such as open circuit and short |
28
|
|
|
|
|
|
|
to ground (reading faults is not implemented yet). |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
13525
|
use constant PROTOCOL => 'SPI'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
229
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub SPI_options { |
35
|
0
|
|
|
0
|
0
|
|
return ( mode => 0, |
36
|
|
|
|
|
|
|
max_bitrate => 1000000 ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _read_data { |
40
|
0
|
|
|
0
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @bytes = unpack('C*', $self->protocol->read(4)->get); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return ($bytes[0] << 24) + ($bytes[1] << 16) + ($bytes[2] << 8) + $bytes[3]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 read_thermocouple |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns the termperature of the attached thermocouple in degrees Celsius. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub read_thermocouple { |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $reg = $self->_read_data(); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $temp = ($reg >> 18) & 0x3fff; |
61
|
0
|
0
|
|
|
|
|
$temp = -(16384 - $temp) if ($temp & 0x2000); |
62
|
0
|
|
|
|
|
|
$temp /= 4; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
Future->done($temp); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 read_cold_junction |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns the temperature of the local (cold) junction in degrees Celsius. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub read_cold_junction { |
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $reg = $self->_read_data(); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $localtemp = ($reg >> 4) & 0xfff; |
79
|
0
|
0
|
|
|
|
|
$localtemp = -(4096 - $localtemp) if ($localtemp & 0x800); |
80
|
0
|
|
|
|
|
|
$localtemp /= 16; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
Future->done($localtemp); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Stephen Cavilia |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |