Hello there,
Does anyone know how to read a 10 bit serial-synchronous output from a digital wind vane (Thies First Class 4.3150.00.001) with a Campbell CR1000 or CR3000 and to what ports shall I connect it to?
There are two signals which I should connect to the logger (Clock signal and data signal).
The wind vane datasheet is here:
Thanks in advance
'CR1000 Series Datalogger
'Example program for interfacing to Thies 4.3150
' First Class Wind Direction Transmitter
'date: November 29, 2012
'program author: Jacob
'Wiring
'pin 2 to CR1000 G
'pin 3 to CR1000 12v
'pin 4 to CR1000 C1
'pin 5 to CR1000 C2
'pin 6 to CR1000 G
ConstTable
Const Startpulse_uS = 2000
Const Pulsewidth_uS = 1000
Const clockline = 1
Const dataline = 2
EndConstTable
'Declare Public Variables
Public PTemp, batt_volt
Public WindDir
Units WindDir = degrees
Public DirFine As Boolean 'True if code and inverse match
Public WindCode(16) As Boolean 'Bits in code
Public tempInteger As Long, Sector As Long
Public parity As Long
'Public BinBits(8) As Boolean
'Public GrayValue As Long
Dim k As Long
Dim LookupArray(1023) As Long
DataLong 1,3,2,6,7,5,4,12,13,15,14,10,11,9,8,24,25,27,26,30,31,29,28,20,21,23,22,18,19,17,16,48,49,51,50,54,55,53,52,60,61,63,62,58,59,57,56,40,41,43,42,46,47,45,44,36,37,39,38,34,35,33,32,96,97,99,98,102,103,101,100,108,109,111,110
DataLong 106,107,105,104,120,121,123,122,126,127,125,124,116,117,119,118,114,115,113,112,80,81,83,82,86,87,85,84,92,93,95,94,90,91,89,88,72,73,75,74,78,79,77,76,68,69,71,70,66,67,65,64,192,193,195,194,198,199,197,196,204,205,207,206,202,203,201
DataLong 200,216,217,219,218,222,223,221,220,212,213,215,214,210,211,209,208,240,241,243,242,246,247,245,244,252,253,255,254,250,251,249,248,232,233,235,234,238,239,237,236,228,229,231,230,226,227,225,224,160,161,163,162,166,167,165,164,172,173,175,174
DataLong 170,171,169,168,184,185,187,186,190,191,189,188,180,181,183,182,178,179,177,176,144,145,147,146,150,151,149,148,156,157,159,158,154,155,153,152,136,137,139,138,142,143,141,140,132,133,135,134,130,131,129,128,384,385,387,386,390,391,389
DataLong 388,396,397,399,398,394,395,393,392,408,409,411,410,414,415,413,412,404,405,407,406,402,403,401,400,432,433,435,434,438,439,437,436,444,445,447,446,442,443,441,440,424,425,427,426,430,431,429,428,420,421,423,422,418,419,417,416,480,481,483,482
DataLong 486,487,485,484,492,493,495,494,490,491,489,488,504,505,507,506,510,511,509,508,500,501,503,502,498,499,497,496,464,465
DataLong 467,466,470,471,469,468,476,477,479,478,474,475,473,472,456,457,459,458,462,463,461,460,452,453,455,454,450,451,449,448,320,321,323,322,326,327,325,324,332,333,335,334,330,331,329,328,344,345,347,346,350,351,349,348,340,341,343,342,338,339,337,336
DataLong 368,369,371,370,374,375,373,372,380,381,383,382,378,379,377,376,360,361,363,362,366,367,365,364,356,357,359,358,354,355,353,352,288,289,291,290,294,295,293,292,300,301,303,302,298,299,297,296,312,313,315,314,318,319,317,316,308,309,311,310,306,307,305
DataLong 304,272,273,275,274,278,279,277,276,284,285,287,286,282,283,281,280,264,265,267,266,270,271,269,268,260,261,263,262,258,259,257,256,768,769,771,770,774,775,773,772,780,781,783,782,778,779,777,776,792,793,795,794,798,799,797,796,788,789,791,790,786,787
DataLong 785,784,816,817,819,818,822,823,821,820,828,829,831,830,826,827,825,824,808,809,811,810,814,815,813,812,804,805,807,806,802,803,801,800,864,865,867,866,870,871,869,868,876,877,879,878,874,875,873,872,888,889,891,890,894,895,893,892,884,885,887,886,882
DataLong 883,881,880,848,849,851,850,854,855,853,852,860,861,863,862,858,859,857,856,840,841,843,842,846,847,845,844,836,837,839,838,834,835,833,832,960,961,963,962,966,967,965,964,972,973,975,974,970,971,969,968,984,985,987,986,990,991,989,988,980,981,983,982,978,979
DataLong 977,976,1008,1009,1011,1010,1014,1015,1013,1012,1020,1021,1023,1022,1018,1019,1017,1016,1000,1001,1003,1002,1006,1007,1005,1004,996,997,999,998,994,995,993,992,928,929,931,930,934,935,933,932,940,941,943,942,938,939,937,936,952,953,955,954,958,959,957,956
DataLong 948,949,951,950,946,947,945,944,912,913,915,914,918,919,917,916,924,925,927,926,922,923,921,920,904,905,907,906,910,911,909,908,900,901,903,902,898,899,897,896,640,641,643,642,646,647,645,644,652,653,655,654,650,651,649,648,664,665,667,666,670,671,669,668,660
DataLong 661,663,662,658,659,657,656,688,689,691,690,694,695,693,692,700,701,703,702,698,699,697,696,680,681,683,682,686,687,685,684,676,677,679,678,674,675,673,672,736,737,739,738,742,743,741,740,748,749,751,750,746,747,745,744,760,761,763,762,766,767,765,764,756,757
DataLong 759,758,754,755,753,752,720,721,723,722,726,727,725,724,732,733,735,734,730,731,729,728,712,713,715,714,718,719,717,716,708,709,711,710,706,707,705,704,576,577,579,578,582,583,581,580,588,589,591,590,586,587,585,584,600,601,603,602,606,607,605,604,596,597,599
DataLong 598,594,595,593,592,624,625,627,626,630,631,629,628,636,637,639,638,634,635,633,632,616,617,619,618,622,623,621,620,612,613,615,614,610,611,609,608,544,545,547,546,550,551,549,548,556,557,559,558,554,555,553,552,568,569,571,570,574,575
DataLong 573,572,564,565,567,566,562,563,561,560,528,529,531,530,534,535,533,532,540,541,543,542,538,539,537,536,520,521,523,522,526,527,525,524,516,517,519,518,514,515,513,512
DataTable (tracker,True,1000)
DataInterval (0,1,Sec,10)
Sample (1,WindDir,FP2)
EndTable
'Main Program
BeginProg
For k = 1 To 1023
Read LookupArray(k)
Next k
Scan (1,Sec,0,0)
'Read binary code and inverse from Thies 4.3150
' must be in main scan
'C1 is clock line
'C2 is data line
' PortSet (clockline ,0)
' For k = 1 To 16
' PulsePort (1 ,1000)
' PortGet (WindCode(k),2)
' Next k
PortSet (clockline ,0)
k=1
PortSet (ClockLine ,1 )
Delay (0,StartPulse_uS,uSec)
PortSet (ClockLine ,0)
Delay (0,PulseWidth_uS,uSec)
PortGet (WindCode(k),DataLine)
SubScan (0,Sec,15)
k = k + 1
PortSet (ClockLine ,1 )
Delay (0,PulseWidth_uS,uSec)
PortSet (ClockLine ,0)
Delay (0,PulseWidth_uS,uSec)
PortGet (WindCode(k),DataLine)
NextSubScan
'Convert binary code to integer
tempInteger = 0
If WindCode(2) Then tempInteger = tempInteger OR 1
If WindCode(3) Then tempInteger = tempInteger OR 2
If WindCode(4) Then tempInteger = tempInteger OR 4
If WindCode(5) Then tempInteger = tempInteger OR 8
If WindCode(6) Then tempInteger = tempInteger OR 16
If WindCode(7) Then tempInteger = tempInteger OR 32
If WindCode(8) Then tempInteger = tempInteger OR 64
If WindCode(9) Then tempInteger = tempInteger OR 128
If WindCode(10) Then tempInteger=tempInteger OR 256
If WindCode(11) Then tempInteger=tempInteger OR 512
parity=0
For k = 1 To 16
If WindCode(k) Then parity = parity+1
Next k
If parity MOD 2 Then
DirFine=false
Else
DirFine = true
endif
'Lookup gray code value
If tempInteger = 0 Then
Sector = 0
Else
For k = 1 To 1023
If tempInteger = LookupArray(k) Then
Sector = k
ExitFor
EndIf
Next k
EndIf
' BinBits(8) = WindCode(8)
' For k = 7 To 1 Step - 1
' BinBits(k) = BinBits(k + 1) XOR WindCode(k)
' Next k
'
' GrayValue = 0
' If BinBits(1) Then GrayValue = GrayValue OR 1
' If BinBits(2) Then GrayValue = GrayValue OR 2
' If BinBits(3) Then GrayValue = GrayValue OR 4
' If BinBits(4) Then GrayValue = GrayValue OR 8
' If BinBits(5) Then GrayValue = GrayValue OR 16
' If BinBits(6) Then GrayValue = GrayValue OR 32
' If BinBits(7) Then GrayValue = GrayValue OR 64
' If BinBits(8) Then GrayValue = GrayValue OR 128
'Calculate direction if data checked ok
If DirFine Then
WindDir = Sector * .35
Else
WindDir = NAN
EndIf
calltable tracker
NextScan
EndProg
Thanks JDavis.
Do you know if it would be possible to connect two wind vanes with a common clock signal?
E.g.
Pin 4 Wind vane 1 --> CR1000 C1
Pin 5 Wind vane 1 --> CR1000 C2
Pin 4 Wind vane 2 --> CR1000 C1
Pin 5 Wind vane 2 --> CR1000 C3
Thanks in advance
It might be possible to drive two of them on a common clock line. The length of cables would have an affect.
The only way to be certain would be to connect the sensors and test it.
Hi JDavis,
I have a question regarding the example code: What is the LookupArray(1023) for? What is the meaning of reading the values afterwards with the Read LookupArray(k) command?
Very much interested to understand the code.
KR,
Mathias
The Data and Read commands are not used very often, but are well suited for use in this program.
For more explanation of the instruction, you can look at the help in CRBasic. Data sets up the data, and Read loads it into variables.
The LookupArray is used as a lookup table to convert the gray code to direction.
OK. Got it in parts. So the Lookup array is the gray code table (or vector of values) to which the values are compared. What I do not understand is the sequence of the numbers in the lookup array (1,3,2,6,7,...). Sorry for my ignorance.
Just got it (I guess). That is from Binary to Gray Code, right?
WindCode is the binary, which I convert to the gray code in tempInteger. Then I look up the gray code in the LookupArray to get the direction.
Quick question regarding use with a CR1000X. Would it cause problems to use a C port for the Clock (C4 for example) and a Pulse port for the data line (P1 for example)?. I need the C ports for other applications, so was wondering if I could mix up the channels a bit.
The above program is using PortGet to find the status of the line (0 or 5V).The PortGet instruction allows you to use a Pulse Port in it, so using a Pulse Port for the Dataline input should be fine.
You are correct, the ClockLine has to be a Control Port.
Thanks!
You mention that the length of the cable would have an influence here. Can you specify what would be the effect if one cable is 20 m shorter than the other?
Other question: Could you also use the VX channels as clock line here?
With long cables, you might need to increase the Pulsewidth_uS constant some.
Hi,
May I have your help to enhance the above program to receive 8-bit grey code from a digital wind direction transmitter.
Thanks.
This post is under review.
This post is under review.