Test
Dependencies: mbed-dev-OS5_10_4
Main/Dac8532.cpp@0:014fad4dfb9d, 2020-08-07 (annotated)
- Committer:
- kevman
- Date:
- Fri Aug 07 07:24:21 2020 +0000
- Revision:
- 0:014fad4dfb9d
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:014fad4dfb9d | 1 | /* |
kevman | 0:014fad4dfb9d | 2 | ------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 3 | Programm Name: DaMethoden.C |
kevman | 0:014fad4dfb9d | 4 | Version: 1.0 |
kevman | 0:014fad4dfb9d | 5 | Sprache: C |
kevman | 0:014fad4dfb9d | 6 | Compiler: CrossStudio Ver. 2.0 |
kevman | 0:014fad4dfb9d | 7 | Autor: PS |
kevman | 0:014fad4dfb9d | 8 | Copyright: PS |
kevman | 0:014fad4dfb9d | 9 | |
kevman | 0:014fad4dfb9d | 10 | |
kevman | 0:014fad4dfb9d | 11 | Funktion: Init und Io fuer den D/A Wandler |
kevman | 0:014fad4dfb9d | 12 | |
kevman | 0:014fad4dfb9d | 13 | 28.10.2012: |
kevman | 0:014fad4dfb9d | 14 | |
kevman | 0:014fad4dfb9d | 15 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 16 | /*------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 17 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 18 | #include "Headers.h" |
kevman | 0:014fad4dfb9d | 19 | |
kevman | 0:014fad4dfb9d | 20 | |
kevman | 0:014fad4dfb9d | 21 | // Private Definitionen |
kevman | 0:014fad4dfb9d | 22 | /** Max buffer length */ |
kevman | 0:014fad4dfb9d | 23 | |
kevman | 0:014fad4dfb9d | 24 | |
kevman | 0:014fad4dfb9d | 25 | // Rev B und C |
kevman | 0:014fad4dfb9d | 26 | |
kevman | 0:014fad4dfb9d | 27 | |
kevman | 0:014fad4dfb9d | 28 | // Private Variablen |
kevman | 0:014fad4dfb9d | 29 | |
kevman | 0:014fad4dfb9d | 30 | int nDCounter; |
kevman | 0:014fad4dfb9d | 31 | unsigned char Low, High; |
kevman | 0:014fad4dfb9d | 32 | |
kevman | 0:014fad4dfb9d | 33 | |
kevman | 0:014fad4dfb9d | 34 | |
kevman | 0:014fad4dfb9d | 35 | |
kevman | 0:014fad4dfb9d | 36 | /*------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 37 | Initialisieren der Pins fuer den DA Wandler |
kevman | 0:014fad4dfb9d | 38 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 39 | int InitDac(void) |
kevman | 0:014fad4dfb9d | 40 | { |
kevman | 0:014fad4dfb9d | 41 | int i; |
kevman | 0:014fad4dfb9d | 42 | /* |
kevman | 0:014fad4dfb9d | 43 | Initialisieren der Pins fuer den D/A Zugriff: |
kevman | 0:014fad4dfb9d | 44 | Mosi = 0; // Mosi für den D/A Wandler |
kevman | 0:014fad4dfb9d | 45 | CsDac = 1; // CS für den D/A Wandler, 0 = Cs aktiv, (low active) |
kevman | 0:014fad4dfb9d | 46 | Sck = 0; // SCK für den D/A Wandler |
kevman | 0:014fad4dfb9d | 47 | |
kevman | 0:014fad4dfb9d | 48 | */ |
kevman | 0:014fad4dfb9d | 49 | DacCs = 0; |
kevman | 0:014fad4dfb9d | 50 | DacSck = 1; |
kevman | 0:014fad4dfb9d | 51 | DacMosi = 0; |
kevman | 0:014fad4dfb9d | 52 | |
kevman | 0:014fad4dfb9d | 53 | for(i=0;i<3;i++) |
kevman | 0:014fad4dfb9d | 54 | { |
kevman | 0:014fad4dfb9d | 55 | DacSck = 0; |
kevman | 0:014fad4dfb9d | 56 | DacSck = 1; // D23 bis D21 auf 0 |
kevman | 0:014fad4dfb9d | 57 | } |
kevman | 0:014fad4dfb9d | 58 | DacMosi = 1; // D20 auf 1, load DAC A |
kevman | 0:014fad4dfb9d | 59 | DacSck = 0; |
kevman | 0:014fad4dfb9d | 60 | DacSck = 1; |
kevman | 0:014fad4dfb9d | 61 | DacMosi = 0; |
kevman | 0:014fad4dfb9d | 62 | |
kevman | 0:014fad4dfb9d | 63 | for(i=4;i<24;i++) |
kevman | 0:014fad4dfb9d | 64 | { |
kevman | 0:014fad4dfb9d | 65 | DacSck= 0; |
kevman | 0:014fad4dfb9d | 66 | DacSck = 1; // D19 bis D0 auf 0 |
kevman | 0:014fad4dfb9d | 67 | } |
kevman | 0:014fad4dfb9d | 68 | Low = 0x00; |
kevman | 0:014fad4dfb9d | 69 | High = 0x00; |
kevman | 0:014fad4dfb9d | 70 | return(true); |
kevman | 0:014fad4dfb9d | 71 | } |
kevman | 0:014fad4dfb9d | 72 | /*------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 73 | Testen des D/A Wandlers |
kevman | 0:014fad4dfb9d | 74 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 75 | int TestDac(void) |
kevman | 0:014fad4dfb9d | 76 | { |
kevman | 0:014fad4dfb9d | 77 | Low++; |
kevman | 0:014fad4dfb9d | 78 | SpiSendDa (0, 0); |
kevman | 0:014fad4dfb9d | 79 | if(Low == 0xFF) |
kevman | 0:014fad4dfb9d | 80 | { |
kevman | 0:014fad4dfb9d | 81 | High++; |
kevman | 0:014fad4dfb9d | 82 | } |
kevman | 0:014fad4dfb9d | 83 | return(true); |
kevman | 0:014fad4dfb9d | 84 | } |
kevman | 0:014fad4dfb9d | 85 | /* ******************************************************************** |
kevman | 0:014fad4dfb9d | 86 | macht das komplette Out fuer 24 Bit |
kevman | 0:014fad4dfb9d | 87 | ***********************************************************************/ |
kevman | 0:014fad4dfb9d | 88 | int SpiSendDa (uint8_t Channel, uint16_t Mode) |
kevman | 0:014fad4dfb9d | 89 | { |
kevman | 0:014fad4dfb9d | 90 | uint32_t WData0, WData1,WData2; |
kevman | 0:014fad4dfb9d | 91 | uint16_t n; |
kevman | 0:014fad4dfb9d | 92 | uint32_t Mask; |
kevman | 0:014fad4dfb9d | 93 | uint32_t tmp; |
kevman | 0:014fad4dfb9d | 94 | |
kevman | 0:014fad4dfb9d | 95 | DacSck = 0; |
kevman | 0:014fad4dfb9d | 96 | DacCs = 0; |
kevman | 0:014fad4dfb9d | 97 | |
kevman | 0:014fad4dfb9d | 98 | // 2016-06 UFa: Aenderungen aufgrund HW-Revision |
kevman | 0:014fad4dfb9d | 99 | short_delay(1); |
kevman | 0:014fad4dfb9d | 100 | |
kevman | 0:014fad4dfb9d | 101 | n = 0; |
kevman | 0:014fad4dfb9d | 102 | WData0 = 0x10; |
kevman | 0:014fad4dfb9d | 103 | WData1 = High; |
kevman | 0:014fad4dfb9d | 104 | WData2 = Low; |
kevman | 0:014fad4dfb9d | 105 | Mask = 0x0800000; |
kevman | 0:014fad4dfb9d | 106 | tmp = 0; |
kevman | 0:014fad4dfb9d | 107 | tmp = ((WData0 << 16) | (WData1 << 8) | (WData2)); |
kevman | 0:014fad4dfb9d | 108 | for(n=0;n<24;n++) |
kevman | 0:014fad4dfb9d | 109 | { |
kevman | 0:014fad4dfb9d | 110 | DaSckUp(); |
kevman | 0:014fad4dfb9d | 111 | short_delay(1); |
kevman | 0:014fad4dfb9d | 112 | if(tmp & Mask) |
kevman | 0:014fad4dfb9d | 113 | DaMosiUp(); |
kevman | 0:014fad4dfb9d | 114 | else |
kevman | 0:014fad4dfb9d | 115 | DaMosiDown(); |
kevman | 0:014fad4dfb9d | 116 | short_delay(1); |
kevman | 0:014fad4dfb9d | 117 | DaSckDown(); |
kevman | 0:014fad4dfb9d | 118 | short_delay(1); |
kevman | 0:014fad4dfb9d | 119 | Mask >>= 1; |
kevman | 0:014fad4dfb9d | 120 | } |
kevman | 0:014fad4dfb9d | 121 | // 2016-06 UFa: Aenderungen aufgrund HW-Revision |
kevman | 0:014fad4dfb9d | 122 | DacCs = 1; |
kevman | 0:014fad4dfb9d | 123 | DacSck = 1; |
kevman | 0:014fad4dfb9d | 124 | short_delay(1); |
kevman | 0:014fad4dfb9d | 125 | |
kevman | 0:014fad4dfb9d | 126 | return (0); |
kevman | 0:014fad4dfb9d | 127 | } |
kevman | 0:014fad4dfb9d | 128 | |
kevman | 0:014fad4dfb9d | 129 | /*------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 130 | Berechnen der Daten an den DA Wandler. Wird erst mal für die Anschlussbox berechnet, |
kevman | 0:014fad4dfb9d | 131 | bei der jeweils 2 Kanäle auf einen Ausgang addiert werden |
kevman | 0:014fad4dfb9d | 132 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 133 | void CalcDa(double SourceVal, UINT8 Chn) |
kevman | 0:014fad4dfb9d | 134 | { |
kevman | 0:014fad4dfb9d | 135 | // DigitalOut CsTest(PTC16); // nur wegen dekativierung durch Ethernet. Ich hoffe, das wird wieder anders |
kevman | 0:014fad4dfb9d | 136 | unsigned int OutValue; |
kevman | 0:014fad4dfb9d | 137 | double Counts; |
kevman | 0:014fad4dfb9d | 138 | double SrcVal; |
kevman | 0:014fad4dfb9d | 139 | |
kevman | 0:014fad4dfb9d | 140 | |
kevman | 0:014fad4dfb9d | 141 | SrcVal = SourceVal; |
kevman | 0:014fad4dfb9d | 142 | |
kevman | 0:014fad4dfb9d | 143 | Counts = SrcVal * 13.107; |
kevman | 0:014fad4dfb9d | 144 | |
kevman | 0:014fad4dfb9d | 145 | OutValue = (uint16_t)(Counts); |
kevman | 0:014fad4dfb9d | 146 | |
kevman | 0:014fad4dfb9d | 147 | Low = OutValue; |
kevman | 0:014fad4dfb9d | 148 | High = (OutValue >> 8); |
kevman | 0:014fad4dfb9d | 149 | SpiSendDa(0,1); |
kevman | 0:014fad4dfb9d | 150 | } |
kevman | 0:014fad4dfb9d | 151 | |
kevman | 0:014fad4dfb9d | 152 | /*------------------------------------------------------------------------------- |
kevman | 0:014fad4dfb9d | 153 | Senden der Daten an den DA Wandler |
kevman | 0:014fad4dfb9d | 154 | -------------------------------------------------------------------------------*/ |
kevman | 0:014fad4dfb9d | 155 | void SendDataDa(void) |
kevman | 0:014fad4dfb9d | 156 | { |
kevman | 0:014fad4dfb9d | 157 | SpiSendDa(0,3); |
kevman | 0:014fad4dfb9d | 158 | } |
kevman | 0:014fad4dfb9d | 159 | |
kevman | 0:014fad4dfb9d | 160 | |
kevman | 0:014fad4dfb9d | 161 | |
kevman | 0:014fad4dfb9d | 162 | |
kevman | 0:014fad4dfb9d | 163 | |
kevman | 0:014fad4dfb9d | 164 | |
kevman | 0:014fad4dfb9d | 165 | |
kevman | 0:014fad4dfb9d | 166 |