Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of JTNucleo06PulsedPS_Encoder_RS232 by
main.cpp@8:ecdfc4582186, 2018-03-23 (annotated)
- Committer:
- pravinautosys
- Date:
- Fri Mar 23 14:05:58 2018 +0000
- Revision:
- 8:ecdfc4582186
- Parent:
- 2:b60cb847489c
JTPulsedPS
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| screamer | 0:005629fe3609 | 1 | #include "mbed.h" | 
| pravinautosys | 8:ecdfc4582186 | 2 | #include "TextLCD.h" | 
| pravinautosys | 8:ecdfc4582186 | 3 | #include "CRotaryEncoder.h" | 
| pravinautosys | 8:ecdfc4582186 | 4 | |
| pravinautosys | 8:ecdfc4582186 | 5 | #define DAC_ADDR (0xc0) | 
| pravinautosys | 8:ecdfc4582186 | 6 | #define ADC_ADDR (0xD0) | 
| pravinautosys | 8:ecdfc4582186 | 7 | #define BlankString " " | 
| pravinautosys | 8:ecdfc4582186 | 8 | |
| pravinautosys | 8:ecdfc4582186 | 9 | //bool DEBUGON = 1; | 
| pravinautosys | 8:ecdfc4582186 | 10 | bool DEBUGON = 0; | 
| pravinautosys | 8:ecdfc4582186 | 11 | |
| pravinautosys | 8:ecdfc4582186 | 12 | bool TxEmpty = 0; | 
| pravinautosys | 8:ecdfc4582186 | 13 | bool SerialAvailable = 0; | 
| pravinautosys | 8:ecdfc4582186 | 14 | uint8_t r0,r1,r2,r3,r4,r5,r6,r7; | 
| pravinautosys | 8:ecdfc4582186 | 15 | uint8_t ChRead; | 
| pravinautosys | 8:ecdfc4582186 | 16 | char SerialBuffer[50]; | 
| pravinautosys | 8:ecdfc4582186 | 17 | |
| pravinautosys | 8:ecdfc4582186 | 18 | Ticker OneSecTicker; | 
| pravinautosys | 8:ecdfc4582186 | 19 | uint8_t CursorPos = 0; | 
| pravinautosys | 8:ecdfc4582186 | 20 | |
| pravinautosys | 8:ecdfc4582186 | 21 | I2C i2c(D4,D5); //I2C i2c(I2C_SDA, I2C_SCL); | 
| pravinautosys | 8:ecdfc4582186 | 22 | |
| pravinautosys | 8:ecdfc4582186 | 23 | //InterruptIn EncoderButton(PA_7); | 
| pravinautosys | 8:ecdfc4582186 | 24 | DigitalIn EncoderButton(PA_7); | 
| pravinautosys | 8:ecdfc4582186 | 25 | |
| pravinautosys | 8:ecdfc4582186 | 26 | TextLCD lcd(D12, D11, D10, D9, D8, D7,TextLCD::LCD20x4); // rs, e, d4-d7 | 
| pravinautosys | 8:ecdfc4582186 | 27 | CRotaryEncoder Encoder(D3,D6); //PinA,PinB | 
| pravinautosys | 8:ecdfc4582186 | 28 | int EncoderCount = 0; | 
| pravinautosys | 8:ecdfc4582186 | 29 | |
| pravinautosys | 8:ecdfc4582186 | 30 | DigitalOut MCP4728Ldac(PA_6,1); | 
| pravinautosys | 8:ecdfc4582186 | 31 | DigitalIn MCP4728Rdy(PA_5); | 
| pravinautosys | 8:ecdfc4582186 | 32 | static uint16_t DACvalue = 0; | 
| pravinautosys | 8:ecdfc4582186 | 33 | |
| pravinautosys | 8:ecdfc4582186 | 34 | Ticker HMSec; | 
| pravinautosys | 8:ecdfc4582186 | 35 | uint8_t NowChannel=0; | 
| pravinautosys | 8:ecdfc4582186 | 36 | |
| pravinautosys | 8:ecdfc4582186 | 37 | char Buffer[21]; | 
| screamer | 0:005629fe3609 | 38 | |
| screamer | 0:005629fe3609 | 39 | DigitalOut myled(LED1); | 
| screamer | 0:005629fe3609 | 40 | |
| pravinautosys | 8:ecdfc4582186 | 41 | //Serial pc(SERIAL_TX, SERIAL_RX); | 
| pravinautosys | 8:ecdfc4582186 | 42 | Serial Rs232(PA_9, PA_10); | 
| pravinautosys | 8:ecdfc4582186 | 43 | |
| pravinautosys | 8:ecdfc4582186 | 44 | /* | 
| pravinautosys | 8:ecdfc4582186 | 45 | typedef struct { | 
| pravinautosys | 8:ecdfc4582186 | 46 | __IO uint32_t FIODIR; | 
| pravinautosys | 8:ecdfc4582186 | 47 | uint32_t RESERVED0[3]; | 
| pravinautosys | 8:ecdfc4582186 | 48 | __IO uint32_t FIOMASK; | 
| pravinautosys | 8:ecdfc4582186 | 49 | __IO uint32_t FIOPIN; | 
| pravinautosys | 8:ecdfc4582186 | 50 | __IO uint32_t FIOSET; | 
| pravinautosys | 8:ecdfc4582186 | 51 | __O uint32_t FIOCLR; | 
| pravinautosys | 8:ecdfc4582186 | 52 | } LPC_GPIO_TypeDef; | 
| pravinautosys | 8:ecdfc4582186 | 53 | */ | 
| pravinautosys | 8:ecdfc4582186 | 54 | typedef struct { | 
| pravinautosys | 8:ecdfc4582186 | 55 | uint16_t Ch0; | 
| pravinautosys | 8:ecdfc4582186 | 56 | uint16_t Ch1; | 
| pravinautosys | 8:ecdfc4582186 | 57 | uint16_t Ch2; | 
| pravinautosys | 8:ecdfc4582186 | 58 | uint16_t Ch3; | 
| pravinautosys | 8:ecdfc4582186 | 59 | } StructDAC; | 
| pravinautosys | 8:ecdfc4582186 | 60 | |
| pravinautosys | 8:ecdfc4582186 | 61 | typedef struct { | 
| pravinautosys | 8:ecdfc4582186 | 62 | uint16_t HexData[4]; | 
| pravinautosys | 8:ecdfc4582186 | 63 | float RealData[4]; | 
| pravinautosys | 8:ecdfc4582186 | 64 | float CalibData[4]; | 
| pravinautosys | 8:ecdfc4582186 | 65 | } StructADC; | 
| pravinautosys | 8:ecdfc4582186 | 66 | |
| pravinautosys | 8:ecdfc4582186 | 67 | StructADC ADCData; | 
| pravinautosys | 8:ecdfc4582186 | 68 | StructDAC DACData; | 
| pravinautosys | 8:ecdfc4582186 | 69 | |
| pravinautosys | 8:ecdfc4582186 | 70 | |
| pravinautosys | 8:ecdfc4582186 | 71 | bool mcp4728_setChannel(uint8_t channel, bool UseInternalVRef, uint8_t powerDownMode, bool use2xGain, uint16_t value){ | 
| pravinautosys | 8:ecdfc4582186 | 72 | char buf[3]; | 
| pravinautosys | 8:ecdfc4582186 | 73 | buf[0] = 0x40 | ((channel & 0x3) << 1); | 
| pravinautosys | 8:ecdfc4582186 | 74 | |
| pravinautosys | 8:ecdfc4582186 | 75 | buf[1] = ((uint8_t)UseInternalVRef << 7) | ((powerDownMode & 0x3) << 5) | ((uint8_t)use2xGain << 4); | 
| pravinautosys | 8:ecdfc4582186 | 76 | buf[1] |= (value & 0x0f00)>>8; | 
| pravinautosys | 8:ecdfc4582186 | 77 | |
| pravinautosys | 8:ecdfc4582186 | 78 | buf[2] = value & 0xff; | 
| pravinautosys | 8:ecdfc4582186 | 79 | |
| pravinautosys | 8:ecdfc4582186 | 80 | return i2c.write(DAC_ADDR, buf, 3, 0) == 0; | 
| pravinautosys | 8:ecdfc4582186 | 81 | } | 
| pravinautosys | 8:ecdfc4582186 | 82 | |
| pravinautosys | 8:ecdfc4582186 | 83 | int dac_test(void){ | 
| pravinautosys | 8:ecdfc4582186 | 84 | // static uint16_t value = 0; | 
| pravinautosys | 8:ecdfc4582186 | 85 | int ret; | 
| pravinautosys | 8:ecdfc4582186 | 86 | |
| pravinautosys | 8:ecdfc4582186 | 87 | // MCP4728Ldac = 0; | 
| pravinautosys | 8:ecdfc4582186 | 88 | if(DACvalue == 0xfff) DACvalue = 0; | 
| pravinautosys | 8:ecdfc4582186 | 89 | else DACvalue = 0xfff; | 
| pravinautosys | 8:ecdfc4582186 | 90 | ret = mcp4728_setChannel(0, 1, 0, 1, DACvalue); | 
| pravinautosys | 8:ecdfc4582186 | 91 | // DACvalue += 4; | 
| pravinautosys | 8:ecdfc4582186 | 92 | // MCP4728Ldac = 1; | 
| pravinautosys | 8:ecdfc4582186 | 93 | |
| pravinautosys | 8:ecdfc4582186 | 94 | if(!ret) return -2; | 
| pravinautosys | 8:ecdfc4582186 | 95 | |
| pravinautosys | 8:ecdfc4582186 | 96 | return 1; | 
| pravinautosys | 8:ecdfc4582186 | 97 | } | 
| pravinautosys | 8:ecdfc4582186 | 98 | |
| pravinautosys | 8:ecdfc4582186 | 99 | void EncoderButtonPressed(){ | 
| pravinautosys | 8:ecdfc4582186 | 100 | int cnt; | 
| pravinautosys | 8:ecdfc4582186 | 101 | cnt = Encoder.Get(); | 
| pravinautosys | 8:ecdfc4582186 | 102 | cnt += 10; | 
| pravinautosys | 8:ecdfc4582186 | 103 | Encoder.Set(cnt); | 
| pravinautosys | 8:ecdfc4582186 | 104 | if(DEBUGON) DEBUGON = 0; | 
| pravinautosys | 8:ecdfc4582186 | 105 | else DEBUGON = 1; | 
| pravinautosys | 8:ecdfc4582186 | 106 | } | 
| pravinautosys | 8:ecdfc4582186 | 107 | void SetDAC(uint8_t ChNo,uint16_t Value){ | 
| pravinautosys | 8:ecdfc4582186 | 108 | switch(ChNo){ | 
| pravinautosys | 8:ecdfc4582186 | 109 | case 0: | 
| pravinautosys | 8:ecdfc4582186 | 110 | DACData.Ch0 = Value; | 
| pravinautosys | 8:ecdfc4582186 | 111 | mcp4728_setChannel(0, 1, 0, 1, Value); | 
| pravinautosys | 8:ecdfc4582186 | 112 | break; | 
| pravinautosys | 8:ecdfc4582186 | 113 | case 1: | 
| pravinautosys | 8:ecdfc4582186 | 114 | DACData.Ch1 = Value; | 
| pravinautosys | 8:ecdfc4582186 | 115 | mcp4728_setChannel(1, 1, 0, 1, Value); | 
| pravinautosys | 8:ecdfc4582186 | 116 | break; | 
| pravinautosys | 8:ecdfc4582186 | 117 | case 2: | 
| pravinautosys | 8:ecdfc4582186 | 118 | DACData.Ch2 = Value; | 
| pravinautosys | 8:ecdfc4582186 | 119 | mcp4728_setChannel(2, 1, 0, 1, Value); | 
| pravinautosys | 8:ecdfc4582186 | 120 | break; | 
| pravinautosys | 8:ecdfc4582186 | 121 | case 3: | 
| pravinautosys | 8:ecdfc4582186 | 122 | DACData.Ch3 = Value; | 
| pravinautosys | 8:ecdfc4582186 | 123 | mcp4728_setChannel(3, 1, 0, 1, Value); | 
| pravinautosys | 8:ecdfc4582186 | 124 | break; | 
| pravinautosys | 8:ecdfc4582186 | 125 | } | 
| pravinautosys | 8:ecdfc4582186 | 126 | } | 
| pravinautosys | 8:ecdfc4582186 | 127 | void UpdateDAC(){ | 
| pravinautosys | 8:ecdfc4582186 | 128 | mcp4728_setChannel(0, 1, 0, 1, DACData.Ch0); | 
| pravinautosys | 8:ecdfc4582186 | 129 | mcp4728_setChannel(1, 1, 0, 1, DACData.Ch1); | 
| pravinautosys | 8:ecdfc4582186 | 130 | mcp4728_setChannel(2, 1, 0, 1, DACData.Ch2); | 
| pravinautosys | 8:ecdfc4582186 | 131 | mcp4728_setChannel(3, 1, 0, 1, DACData.Ch3); | 
| pravinautosys | 8:ecdfc4582186 | 132 | } | 
| pravinautosys | 8:ecdfc4582186 | 133 | void ResetDAC(){ | 
| pravinautosys | 8:ecdfc4582186 | 134 | DACData.Ch0 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 135 | DACData.Ch1 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 136 | DACData.Ch2 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 137 | DACData.Ch3 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 138 | UpdateDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 139 | } | 
| pravinautosys | 8:ecdfc4582186 | 140 | void FullDAC(){ | 
| pravinautosys | 8:ecdfc4582186 | 141 | DACData.Ch0 = 0xfff; | 
| pravinautosys | 8:ecdfc4582186 | 142 | DACData.Ch1 = 0xfff; | 
| pravinautosys | 8:ecdfc4582186 | 143 | DACData.Ch2 = 0xfff; | 
| pravinautosys | 8:ecdfc4582186 | 144 | DACData.Ch3 = 0xfff; | 
| pravinautosys | 8:ecdfc4582186 | 145 | UpdateDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 146 | } | 
| pravinautosys | 8:ecdfc4582186 | 147 | bool mcp3428_writeConfig(uint8_t conf){ | 
| pravinautosys | 8:ecdfc4582186 | 148 | return i2c.write(ADC_ADDR, (char*) &conf, 1, 0) == 0; | 
| pravinautosys | 8:ecdfc4582186 | 149 | } | 
| pravinautosys | 8:ecdfc4582186 | 150 | |
| pravinautosys | 8:ecdfc4582186 | 151 | bool mcp3428_read(uint16_t* data, uint8_t* conf){ | 
| pravinautosys | 8:ecdfc4582186 | 152 | char buf[3]; | 
| pravinautosys | 8:ecdfc4582186 | 153 | int ret = i2c.read(ADC_ADDR, buf, 3, 0); | 
| pravinautosys | 8:ecdfc4582186 | 154 | if(ret != 0) | 
| pravinautosys | 8:ecdfc4582186 | 155 | return false; | 
| pravinautosys | 8:ecdfc4582186 | 156 | *data = buf[0] << 8 | buf[1]; | 
| pravinautosys | 8:ecdfc4582186 | 157 | *conf = buf[2]; | 
| pravinautosys | 8:ecdfc4582186 | 158 | return true; | 
| pravinautosys | 8:ecdfc4582186 | 159 | } | 
| pravinautosys | 8:ecdfc4582186 | 160 | |
| pravinautosys | 8:ecdfc4582186 | 161 | int ReadADC(uint8_t ChNo){ | 
| pravinautosys | 8:ecdfc4582186 | 162 | uint8_t conf = 0x98; | 
| pravinautosys | 8:ecdfc4582186 | 163 | uint16_t data = 0; | 
| pravinautosys | 8:ecdfc4582186 | 164 | |
| pravinautosys | 8:ecdfc4582186 | 165 | |
| pravinautosys | 8:ecdfc4582186 | 166 | switch(ChNo){ | 
| pravinautosys | 8:ecdfc4582186 | 167 | case 0: | 
| pravinautosys | 8:ecdfc4582186 | 168 | conf = 0x98; | 
| pravinautosys | 8:ecdfc4582186 | 169 | break; | 
| pravinautosys | 8:ecdfc4582186 | 170 | case 1: | 
| pravinautosys | 8:ecdfc4582186 | 171 | conf = 0xb8; | 
| pravinautosys | 8:ecdfc4582186 | 172 | break; | 
| pravinautosys | 8:ecdfc4582186 | 173 | case 2: | 
| pravinautosys | 8:ecdfc4582186 | 174 | conf = 0xd8; | 
| pravinautosys | 8:ecdfc4582186 | 175 | break; | 
| pravinautosys | 8:ecdfc4582186 | 176 | case 3: | 
| pravinautosys | 8:ecdfc4582186 | 177 | conf = 0xf8; | 
| pravinautosys | 8:ecdfc4582186 | 178 | break; | 
| pravinautosys | 8:ecdfc4582186 | 179 | } | 
| pravinautosys | 8:ecdfc4582186 | 180 | if(!mcp3428_writeConfig(conf)) return -1; | 
| pravinautosys | 8:ecdfc4582186 | 181 | wait(0.1); | 
| pravinautosys | 8:ecdfc4582186 | 182 | int ret = mcp3428_read(&data, &conf); | 
| pravinautosys | 8:ecdfc4582186 | 183 | //if(DEBUGON) Rs232.printf("CONF: %02x ChannelNo: %02d \n",conf,ChNo); | 
| pravinautosys | 8:ecdfc4582186 | 184 | if(!ret) return -2; | 
| pravinautosys | 8:ecdfc4582186 | 185 | return data; | 
| pravinautosys | 8:ecdfc4582186 | 186 | } | 
| pravinautosys | 8:ecdfc4582186 | 187 | void ConvertNegative(uint8_t ChNo,int d){ | 
| pravinautosys | 8:ecdfc4582186 | 188 | if(d & 0x8000) { | 
| pravinautosys | 8:ecdfc4582186 | 189 | d &= 0x7fff; | 
| pravinautosys | 8:ecdfc4582186 | 190 | d = (d ^ 0x07fff) + 1; | 
| pravinautosys | 8:ecdfc4582186 | 191 | ADCData.HexData[ChNo] = d; | 
| pravinautosys | 8:ecdfc4582186 | 192 | ADCData.RealData[ChNo] = ADCData.HexData[ChNo] * ADCData.CalibData[1] / 32768.0; | 
| pravinautosys | 8:ecdfc4582186 | 193 | ADCData.RealData[ChNo] *= (-1.0); | 
| pravinautosys | 8:ecdfc4582186 | 194 | } | 
| pravinautosys | 8:ecdfc4582186 | 195 | else{ | 
| pravinautosys | 8:ecdfc4582186 | 196 | ADCData.HexData[ChNo] = d; | 
| pravinautosys | 8:ecdfc4582186 | 197 | ADCData.RealData[ChNo] = ADCData.HexData[ChNo] * ADCData.CalibData[ChNo] / 32768.0; | 
| pravinautosys | 8:ecdfc4582186 | 198 | } | 
| pravinautosys | 8:ecdfc4582186 | 199 | } | 
| pravinautosys | 8:ecdfc4582186 | 200 | void ReadADCConverted(){ | 
| pravinautosys | 8:ecdfc4582186 | 201 | int adData=0; | 
| pravinautosys | 8:ecdfc4582186 | 202 | bool Negative=0; | 
| pravinautosys | 8:ecdfc4582186 | 203 | |
| pravinautosys | 8:ecdfc4582186 | 204 | adData = ReadADC(0); | 
| pravinautosys | 8:ecdfc4582186 | 205 | if ( (adData == -1) || (adData == -2) ) goto next1; | 
| pravinautosys | 8:ecdfc4582186 | 206 | ConvertNegative(0,adData); | 
| pravinautosys | 8:ecdfc4582186 | 207 | next1: | 
| pravinautosys | 8:ecdfc4582186 | 208 | adData = ReadADC(1); | 
| pravinautosys | 8:ecdfc4582186 | 209 | if ( (adData == -1) || (adData == -2) ) goto next2; | 
| pravinautosys | 8:ecdfc4582186 | 210 | ConvertNegative(1,adData); | 
| pravinautosys | 8:ecdfc4582186 | 211 | next2: | 
| pravinautosys | 8:ecdfc4582186 | 212 | adData = ReadADC(2); | 
| pravinautosys | 8:ecdfc4582186 | 213 | if ( (adData == -1) || (adData == -2) ) goto next3; | 
| pravinautosys | 8:ecdfc4582186 | 214 | ConvertNegative(2,adData); | 
| pravinautosys | 8:ecdfc4582186 | 215 | next3: | 
| pravinautosys | 8:ecdfc4582186 | 216 | adData = ReadADC(3); | 
| pravinautosys | 8:ecdfc4582186 | 217 | if ( (adData == -1) || (adData == -2) ) goto next4; | 
| pravinautosys | 8:ecdfc4582186 | 218 | ConvertNegative(3,adData); | 
| pravinautosys | 8:ecdfc4582186 | 219 | next4: | 
| pravinautosys | 8:ecdfc4582186 | 220 | return; | 
| pravinautosys | 8:ecdfc4582186 | 221 | } | 
| pravinautosys | 8:ecdfc4582186 | 222 | /* | 
| pravinautosys | 8:ecdfc4582186 | 223 | void ReadADCTicker(){ | 
| pravinautosys | 8:ecdfc4582186 | 224 | uint8_t conf = 0x98; | 
| pravinautosys | 8:ecdfc4582186 | 225 | uint16_t data = 0; | 
| pravinautosys | 8:ecdfc4582186 | 226 | |
| pravinautosys | 8:ecdfc4582186 | 227 | switch(NowChannel){ | 
| pravinautosys | 8:ecdfc4582186 | 228 | case 0:conf = 0x98;break; | 
| pravinautosys | 8:ecdfc4582186 | 229 | case 1:conf = 0xb8;break; | 
| pravinautosys | 8:ecdfc4582186 | 230 | case 2:conf = 0xd8;break; | 
| pravinautosys | 8:ecdfc4582186 | 231 | case 3:conf = 0xf8;break; | 
| pravinautosys | 8:ecdfc4582186 | 232 | } | 
| pravinautosys | 8:ecdfc4582186 | 233 | |
| pravinautosys | 8:ecdfc4582186 | 234 | int ret = mcp3428_read(&data, &conf); | 
| pravinautosys | 8:ecdfc4582186 | 235 | if(!ret) goto NextCh; | 
| pravinautosys | 8:ecdfc4582186 | 236 | // mcp3428_read(&data, &conf); | 
| pravinautosys | 8:ecdfc4582186 | 237 | ADCData.HexData[NowChannel] = data & 0x7fff; | 
| pravinautosys | 8:ecdfc4582186 | 238 | |
| pravinautosys | 8:ecdfc4582186 | 239 | ADCData.RealData[NowChannel] = ( (ADCData.HexData[NowChannel] * ADCData.CalibData[NowChannel] / 32768.0) ); | 
| pravinautosys | 8:ecdfc4582186 | 240 | NextCh: | 
| pravinautosys | 8:ecdfc4582186 | 241 | NowChannel++; | 
| pravinautosys | 8:ecdfc4582186 | 242 | if(NowChannel > 3) NowChannel = 0; | 
| pravinautosys | 8:ecdfc4582186 | 243 | |
| pravinautosys | 8:ecdfc4582186 | 244 | switch(NowChannel){ | 
| pravinautosys | 8:ecdfc4582186 | 245 | case 0:conf = 0x98;break; | 
| pravinautosys | 8:ecdfc4582186 | 246 | case 1:conf = 0xb8;break; | 
| pravinautosys | 8:ecdfc4582186 | 247 | case 2:conf = 0xd8;break; | 
| pravinautosys | 8:ecdfc4582186 | 248 | case 3:conf = 0xf8;break; | 
| pravinautosys | 8:ecdfc4582186 | 249 | } | 
| pravinautosys | 8:ecdfc4582186 | 250 | mcp3428_writeConfig(conf); | 
| pravinautosys | 8:ecdfc4582186 | 251 | |
| pravinautosys | 8:ecdfc4582186 | 252 | } | 
| pravinautosys | 8:ecdfc4582186 | 253 | */ | 
| pravinautosys | 8:ecdfc4582186 | 254 | int adc_test(void){ | 
| pravinautosys | 8:ecdfc4582186 | 255 | // uint8_t conf = 0x90; | 
| pravinautosys | 8:ecdfc4582186 | 256 | uint8_t conf = 0x98; | 
| pravinautosys | 8:ecdfc4582186 | 257 | uint16_t data = 0; | 
| pravinautosys | 8:ecdfc4582186 | 258 | |
| pravinautosys | 8:ecdfc4582186 | 259 | if(!mcp3428_writeConfig(conf)) return -1; | 
| pravinautosys | 8:ecdfc4582186 | 260 | |
| pravinautosys | 8:ecdfc4582186 | 261 | int ret = mcp3428_read(&data, &conf); | 
| pravinautosys | 8:ecdfc4582186 | 262 | |
| pravinautosys | 8:ecdfc4582186 | 263 | if(!ret) return -2; | 
| pravinautosys | 8:ecdfc4582186 | 264 | |
| pravinautosys | 8:ecdfc4582186 | 265 | return data; | 
| pravinautosys | 8:ecdfc4582186 | 266 | |
| pravinautosys | 8:ecdfc4582186 | 267 | } | 
| pravinautosys | 8:ecdfc4582186 | 268 | void HMSecRoutine(){ | 
| pravinautosys | 8:ecdfc4582186 | 269 | // ReadADCTicker(); | 
| pravinautosys | 8:ecdfc4582186 | 270 | } | 
| pravinautosys | 8:ecdfc4582186 | 271 | void LCDPrintDataADC(){ | 
| pravinautosys | 8:ecdfc4582186 | 272 | // lcd.cls(); | 
| pravinautosys | 8:ecdfc4582186 | 273 | sprintf(Buffer,"Ch1: %6.3f V",ADCData.RealData[0]); | 
| pravinautosys | 8:ecdfc4582186 | 274 | lcd.locate(0,0); | 
| pravinautosys | 8:ecdfc4582186 | 275 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 276 | lcd.locate(0,0); | 
| pravinautosys | 8:ecdfc4582186 | 277 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 278 | |
| pravinautosys | 8:ecdfc4582186 | 279 | sprintf(Buffer,"Ch2: %6.3f V",ADCData.RealData[1]); | 
| pravinautosys | 8:ecdfc4582186 | 280 | lcd.locate(0,1); | 
| pravinautosys | 8:ecdfc4582186 | 281 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 282 | lcd.locate(0,1); | 
| pravinautosys | 8:ecdfc4582186 | 283 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 284 | |
| pravinautosys | 8:ecdfc4582186 | 285 | sprintf(Buffer,"Ch3: %6.3f V",ADCData.RealData[2]); | 
| pravinautosys | 8:ecdfc4582186 | 286 | lcd.locate(0,2); | 
| pravinautosys | 8:ecdfc4582186 | 287 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 288 | lcd.locate(0,2); | 
| pravinautosys | 8:ecdfc4582186 | 289 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 290 | |
| pravinautosys | 8:ecdfc4582186 | 291 | sprintf(Buffer,"Ch4: %6.3f V",ADCData.RealData[3]); | 
| pravinautosys | 8:ecdfc4582186 | 292 | lcd.locate(0,3); | 
| pravinautosys | 8:ecdfc4582186 | 293 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 294 | lcd.locate(0,3); | 
| pravinautosys | 8:ecdfc4582186 | 295 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 296 | |
| pravinautosys | 8:ecdfc4582186 | 297 | // Rs232printf("adc_test: %5.3f %5.3f %5.3f %5.3f\n", ADCData.RealData[0],ADCData.RealData[1],ADCData.RealData[2],ADCData.RealData[3]); | 
| pravinautosys | 8:ecdfc4582186 | 298 | |
| pravinautosys | 8:ecdfc4582186 | 299 | |
| pravinautosys | 8:ecdfc4582186 | 300 | } | 
| pravinautosys | 8:ecdfc4582186 | 301 | void LCDPrintDataDAC(){ | 
| pravinautosys | 8:ecdfc4582186 | 302 | // lcd.cls(); | 
| pravinautosys | 8:ecdfc4582186 | 303 | sprintf(Buffer," Ch1: %4d",DACData.Ch0); | 
| pravinautosys | 8:ecdfc4582186 | 304 | lcd.locate(0,0); | 
| pravinautosys | 8:ecdfc4582186 | 305 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 306 | lcd.locate(0,0); | 
| pravinautosys | 8:ecdfc4582186 | 307 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 308 | |
| pravinautosys | 8:ecdfc4582186 | 309 | sprintf(Buffer," Ch2: %4d",DACData.Ch1); | 
| pravinautosys | 8:ecdfc4582186 | 310 | lcd.locate(0,1); | 
| pravinautosys | 8:ecdfc4582186 | 311 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 312 | lcd.locate(0,1); | 
| pravinautosys | 8:ecdfc4582186 | 313 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 314 | |
| pravinautosys | 8:ecdfc4582186 | 315 | sprintf(Buffer," Ch3: %4d",DACData.Ch2); | 
| pravinautosys | 8:ecdfc4582186 | 316 | lcd.locate(0,2); | 
| pravinautosys | 8:ecdfc4582186 | 317 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 318 | lcd.locate(0,2); | 
| pravinautosys | 8:ecdfc4582186 | 319 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 320 | |
| pravinautosys | 8:ecdfc4582186 | 321 | sprintf(Buffer," Ch4: %4d",DACData.Ch3); | 
| pravinautosys | 8:ecdfc4582186 | 322 | lcd.locate(0,3); | 
| pravinautosys | 8:ecdfc4582186 | 323 | lcd.printf(BlankString); | 
| pravinautosys | 8:ecdfc4582186 | 324 | lcd.locate(0,3); | 
| pravinautosys | 8:ecdfc4582186 | 325 | lcd.printf(Buffer); | 
| pravinautosys | 8:ecdfc4582186 | 326 | |
| pravinautosys | 8:ecdfc4582186 | 327 | while(EncoderButton == 0); | 
| pravinautosys | 8:ecdfc4582186 | 328 | |
| pravinautosys | 8:ecdfc4582186 | 329 | } | 
| pravinautosys | 8:ecdfc4582186 | 330 | |
| pravinautosys | 8:ecdfc4582186 | 331 | void DisplayCursor(){ | 
| pravinautosys | 8:ecdfc4582186 | 332 | |
| pravinautosys | 8:ecdfc4582186 | 333 | switch(CursorPos){ | 
| pravinautosys | 8:ecdfc4582186 | 334 | case 0: | 
| pravinautosys | 8:ecdfc4582186 | 335 | lcd.locate(0,0);lcd.printf(">"); | 
| pravinautosys | 8:ecdfc4582186 | 336 | lcd.locate(0,1);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 337 | lcd.locate(0,2);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 338 | lcd.locate(0,3);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 339 | break; | 
| pravinautosys | 8:ecdfc4582186 | 340 | case 1: | 
| pravinautosys | 8:ecdfc4582186 | 341 | lcd.locate(0,0);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 342 | lcd.locate(0,1);lcd.printf(">"); | 
| pravinautosys | 8:ecdfc4582186 | 343 | lcd.locate(0,2);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 344 | lcd.locate(0,3);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 345 | break; | 
| pravinautosys | 8:ecdfc4582186 | 346 | case 2: | 
| pravinautosys | 8:ecdfc4582186 | 347 | lcd.locate(0,0);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 348 | lcd.locate(0,1);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 349 | lcd.locate(0,2);lcd.printf(">"); | 
| pravinautosys | 8:ecdfc4582186 | 350 | lcd.locate(0,3);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 351 | break; | 
| pravinautosys | 8:ecdfc4582186 | 352 | case 3: | 
| pravinautosys | 8:ecdfc4582186 | 353 | lcd.locate(0,0);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 354 | lcd.locate(0,1);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 355 | lcd.locate(0,2);lcd.printf(" "); | 
| pravinautosys | 8:ecdfc4582186 | 356 | lcd.locate(0,3);lcd.printf(">"); | 
| pravinautosys | 8:ecdfc4582186 | 357 | break; | 
| pravinautosys | 8:ecdfc4582186 | 358 | } | 
| pravinautosys | 8:ecdfc4582186 | 359 | } | 
| pravinautosys | 8:ecdfc4582186 | 360 | void ProcessEncoder(){ | 
| pravinautosys | 8:ecdfc4582186 | 361 | uint16_t val; | 
| pravinautosys | 8:ecdfc4582186 | 362 | switch(CursorPos){ | 
| pravinautosys | 8:ecdfc4582186 | 363 | case 0: val = DACData.Ch0;break; | 
| pravinautosys | 8:ecdfc4582186 | 364 | case 1: val = DACData.Ch1;break; | 
| pravinautosys | 8:ecdfc4582186 | 365 | case 2: val = DACData.Ch2;break; | 
| pravinautosys | 8:ecdfc4582186 | 366 | case 3: val = DACData.Ch3;break; | 
| pravinautosys | 8:ecdfc4582186 | 367 | } | 
| pravinautosys | 8:ecdfc4582186 | 368 | Encoder.Set(val); | 
| pravinautosys | 8:ecdfc4582186 | 369 | here: | 
| pravinautosys | 8:ecdfc4582186 | 370 | val = Encoder.Get(); | 
| pravinautosys | 8:ecdfc4582186 | 371 | lcd.locate(0,3); | 
| pravinautosys | 8:ecdfc4582186 | 372 | lcd.printf("%04d",val); | 
| pravinautosys | 8:ecdfc4582186 | 373 | if(Encoder.Get() < 0) Encoder.Set(0); | 
| pravinautosys | 8:ecdfc4582186 | 374 | if(Encoder.Get() > 4095) Encoder.Set(4095); | 
| pravinautosys | 8:ecdfc4582186 | 375 | if(EncoderButton == 0){ | 
| pravinautosys | 8:ecdfc4582186 | 376 | while(EncoderButton == 0); | 
| pravinautosys | 8:ecdfc4582186 | 377 | val = Encoder.Get(); | 
| pravinautosys | 8:ecdfc4582186 | 378 | switch(CursorPos) { | 
| pravinautosys | 8:ecdfc4582186 | 379 | case 0: | 
| pravinautosys | 8:ecdfc4582186 | 380 | DACData.Ch0 = val; | 
| pravinautosys | 8:ecdfc4582186 | 381 | SetDAC(0,DACData.Ch0); | 
| pravinautosys | 8:ecdfc4582186 | 382 | break; | 
| pravinautosys | 8:ecdfc4582186 | 383 | case 1: | 
| pravinautosys | 8:ecdfc4582186 | 384 | DACData.Ch1 = val; | 
| pravinautosys | 8:ecdfc4582186 | 385 | SetDAC(1,DACData.Ch1); | 
| pravinautosys | 8:ecdfc4582186 | 386 | break; | 
| pravinautosys | 8:ecdfc4582186 | 387 | case 2: | 
| pravinautosys | 8:ecdfc4582186 | 388 | DACData.Ch2 = val; | 
| pravinautosys | 8:ecdfc4582186 | 389 | SetDAC(2,DACData.Ch2); | 
| pravinautosys | 8:ecdfc4582186 | 390 | break; | 
| pravinautosys | 8:ecdfc4582186 | 391 | case 3: | 
| pravinautosys | 8:ecdfc4582186 | 392 | DACData.Ch3 = val; | 
| pravinautosys | 8:ecdfc4582186 | 393 | SetDAC(3,DACData.Ch3); | 
| pravinautosys | 8:ecdfc4582186 | 394 | break; | 
| pravinautosys | 8:ecdfc4582186 | 395 | } | 
| pravinautosys | 8:ecdfc4582186 | 396 | return; | 
| pravinautosys | 8:ecdfc4582186 | 397 | } | 
| pravinautosys | 8:ecdfc4582186 | 398 | goto here; | 
| pravinautosys | 8:ecdfc4582186 | 399 | } | 
| pravinautosys | 8:ecdfc4582186 | 400 | void SetTheDacData(){ | 
| pravinautosys | 8:ecdfc4582186 | 401 | lcd.cls(); | 
| pravinautosys | 8:ecdfc4582186 | 402 | lcd.locate(0,2); | 
| pravinautosys | 8:ecdfc4582186 | 403 | switch(CursorPos){ | 
| pravinautosys | 8:ecdfc4582186 | 404 | case 0:lcd.printf("Set CH%02d Value",CursorPos+1);break; | 
| pravinautosys | 8:ecdfc4582186 | 405 | case 1:lcd.printf("Set CH%02d Value",CursorPos+1);break; | 
| pravinautosys | 8:ecdfc4582186 | 406 | case 2:lcd.printf("Set CH%02d Value",CursorPos+1);break; | 
| pravinautosys | 8:ecdfc4582186 | 407 | case 3:lcd.printf("Set CH%02d Value",CursorPos+1);break; | 
| pravinautosys | 8:ecdfc4582186 | 408 | } | 
| pravinautosys | 8:ecdfc4582186 | 409 | ProcessEncoder(); | 
| pravinautosys | 8:ecdfc4582186 | 410 | } | 
| pravinautosys | 8:ecdfc4582186 | 411 | void SetDac(){ | 
| pravinautosys | 8:ecdfc4582186 | 412 | int ECount; | 
| pravinautosys | 8:ecdfc4582186 | 413 | CursorPos = 0; | 
| pravinautosys | 8:ecdfc4582186 | 414 | here1: | 
| pravinautosys | 8:ecdfc4582186 | 415 | Encoder.Set(CursorPos); | 
| pravinautosys | 8:ecdfc4582186 | 416 | LCDPrintDataDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 417 | while(1){ | 
| pravinautosys | 8:ecdfc4582186 | 418 | ECount = Encoder.Get(); | 
| pravinautosys | 8:ecdfc4582186 | 419 | if(ECount > 3){ECount = 0;CursorPos = 0;Encoder.Set(CursorPos);return;} | 
| pravinautosys | 8:ecdfc4582186 | 420 | else { CursorPos = ECount;Encoder.Set(CursorPos);} | 
| pravinautosys | 8:ecdfc4582186 | 421 | DisplayCursor(); | 
| pravinautosys | 8:ecdfc4582186 | 422 | if(EncoderButton == 0){ | 
| pravinautosys | 8:ecdfc4582186 | 423 | while(EncoderButton == 0); | 
| pravinautosys | 8:ecdfc4582186 | 424 | SetTheDacData(); | 
| pravinautosys | 8:ecdfc4582186 | 425 | goto here1; | 
| pravinautosys | 8:ecdfc4582186 | 426 | } | 
| pravinautosys | 8:ecdfc4582186 | 427 | } | 
| pravinautosys | 8:ecdfc4582186 | 428 | } | 
| pravinautosys | 8:ecdfc4582186 | 429 | |
| pravinautosys | 8:ecdfc4582186 | 430 | void PushToBuffer(){ | 
| pravinautosys | 8:ecdfc4582186 | 431 | r0 = r1; | 
| pravinautosys | 8:ecdfc4582186 | 432 | r1 = r2; | 
| pravinautosys | 8:ecdfc4582186 | 433 | r2 = r3; | 
| pravinautosys | 8:ecdfc4582186 | 434 | r3 = r4; | 
| pravinautosys | 8:ecdfc4582186 | 435 | r4 = r5; | 
| pravinautosys | 8:ecdfc4582186 | 436 | r5 = r6; | 
| pravinautosys | 8:ecdfc4582186 | 437 | r6 = r7; | 
| pravinautosys | 8:ecdfc4582186 | 438 | r7 = ChRead; | 
| pravinautosys | 8:ecdfc4582186 | 439 | if((r0==':')&&(r7==';')) SerialAvailable = 1; | 
| pravinautosys | 8:ecdfc4582186 | 440 | } | 
| pravinautosys | 8:ecdfc4582186 | 441 | |
| pravinautosys | 8:ecdfc4582186 | 442 | void Rx_interrupt() { | 
| pravinautosys | 8:ecdfc4582186 | 443 | while(Rs232.readable()){ | 
| pravinautosys | 8:ecdfc4582186 | 444 | ChRead = Rs232.getc(); | 
| pravinautosys | 8:ecdfc4582186 | 445 | PushToBuffer(); | 
| pravinautosys | 8:ecdfc4582186 | 446 | } | 
| pravinautosys | 8:ecdfc4582186 | 447 | } | 
| pravinautosys | 8:ecdfc4582186 | 448 | |
| pravinautosys | 8:ecdfc4582186 | 449 | void Tx_interrupt() { | 
| pravinautosys | 8:ecdfc4582186 | 450 | // TxEmpty = 1; | 
| pravinautosys | 8:ecdfc4582186 | 451 | return; | 
| pravinautosys | 8:ecdfc4582186 | 452 | } | 
| pravinautosys | 8:ecdfc4582186 | 453 | |
| pravinautosys | 8:ecdfc4582186 | 454 | void SendSerial(){ | 
| pravinautosys | 8:ecdfc4582186 | 455 | uint8_t ch,i; | 
| pravinautosys | 8:ecdfc4582186 | 456 | TxEmpty = 1; | 
| pravinautosys | 8:ecdfc4582186 | 457 | for(i=0;i<=49;i++){ | 
| pravinautosys | 8:ecdfc4582186 | 458 | ch = SerialBuffer[i]; | 
| pravinautosys | 8:ecdfc4582186 | 459 | if(ch == 0){ | 
| pravinautosys | 8:ecdfc4582186 | 460 | while(!TxEmpty); | 
| pravinautosys | 8:ecdfc4582186 | 461 | TxEmpty = 0; | 
| pravinautosys | 8:ecdfc4582186 | 462 | Rs232.putc(0x0d); | 
| pravinautosys | 8:ecdfc4582186 | 463 | while(!TxEmpty); | 
| pravinautosys | 8:ecdfc4582186 | 464 | TxEmpty = 0; | 
| pravinautosys | 8:ecdfc4582186 | 465 | Rs232.putc(0x0a); | 
| pravinautosys | 8:ecdfc4582186 | 466 | return; | 
| pravinautosys | 8:ecdfc4582186 | 467 | } | 
| pravinautosys | 8:ecdfc4582186 | 468 | while(!TxEmpty); | 
| pravinautosys | 8:ecdfc4582186 | 469 | TxEmpty = 0; | 
| pravinautosys | 8:ecdfc4582186 | 470 | Rs232.putc(ch); | 
| pravinautosys | 8:ecdfc4582186 | 471 | } | 
| pravinautosys | 8:ecdfc4582186 | 472 | |
| pravinautosys | 8:ecdfc4582186 | 473 | } | 
| pravinautosys | 8:ecdfc4582186 | 474 | void SerialDataSend(){ | 
| pravinautosys | 8:ecdfc4582186 | 475 | Rs232.printf("ADCChannels: %6.3f %6.3f %6.3f %6.3f\n", ADCData.RealData[0],ADCData.RealData[1],ADCData.RealData[2],ADCData.RealData[3]); | 
| pravinautosys | 8:ecdfc4582186 | 476 | } | 
| pravinautosys | 8:ecdfc4582186 | 477 | void PrintRs232(){ | 
| pravinautosys | 8:ecdfc4582186 | 478 | lcd.cls(); | 
| pravinautosys | 8:ecdfc4582186 | 479 | lcd.locate(0,2);lcd.printf("SerialCommand"); | 
| pravinautosys | 8:ecdfc4582186 | 480 | lcd.locate(0,3);lcd.putc(r0); | 
| pravinautosys | 8:ecdfc4582186 | 481 | lcd.locate(1,3);lcd.putc(r1); | 
| pravinautosys | 8:ecdfc4582186 | 482 | lcd.locate(2,3);lcd.putc(r2); | 
| pravinautosys | 8:ecdfc4582186 | 483 | lcd.locate(3,3);lcd.putc(r3); | 
| pravinautosys | 8:ecdfc4582186 | 484 | lcd.locate(4,3);lcd.putc(r4); | 
| pravinautosys | 8:ecdfc4582186 | 485 | lcd.locate(5,3);lcd.putc(r5); | 
| pravinautosys | 8:ecdfc4582186 | 486 | lcd.locate(6,3);lcd.putc(r6); | 
| pravinautosys | 8:ecdfc4582186 | 487 | lcd.locate(7,3);lcd.putc(r7); | 
| pravinautosys | 8:ecdfc4582186 | 488 | } | 
| pravinautosys | 8:ecdfc4582186 | 489 | void SetSerialDAC(){ | 
| pravinautosys | 8:ecdfc4582186 | 490 | uint8_t ch; | 
| pravinautosys | 8:ecdfc4582186 | 491 | uint16_t val; | 
| pravinautosys | 8:ecdfc4582186 | 492 | ch = r2 - '0'; | 
| pravinautosys | 8:ecdfc4582186 | 493 | val = (r3 - '0')*1000; | 
| pravinautosys | 8:ecdfc4582186 | 494 | val += (r4 - '0')*100; | 
| pravinautosys | 8:ecdfc4582186 | 495 | val += (r5 - '0')*10; | 
| pravinautosys | 8:ecdfc4582186 | 496 | val += (r6 - '0')*1; | 
| pravinautosys | 8:ecdfc4582186 | 497 | if(val > 4095) val = 4095; | 
| pravinautosys | 8:ecdfc4582186 | 498 | if(val < 0) val = 0; | 
| pravinautosys | 8:ecdfc4582186 | 499 | if((ch >= 0) && (ch < 4)) SetDAC(ch,val); | 
| pravinautosys | 8:ecdfc4582186 | 500 | else return; | 
| pravinautosys | 8:ecdfc4582186 | 501 | } | 
| pravinautosys | 8:ecdfc4582186 | 502 | |
| pravinautosys | 8:ecdfc4582186 | 503 | |
| pravinautosys | 8:ecdfc4582186 | 504 | void ParseCom(){ | 
| pravinautosys | 8:ecdfc4582186 | 505 | if(SerialAvailable){ | 
| pravinautosys | 8:ecdfc4582186 | 506 | PrintRs232(); | 
| pravinautosys | 8:ecdfc4582186 | 507 | switch(r1){ | 
| pravinautosys | 8:ecdfc4582186 | 508 | case '3'://DAC Command Set Value; | 
| pravinautosys | 8:ecdfc4582186 | 509 | SetSerialDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 510 | break; | 
| pravinautosys | 8:ecdfc4582186 | 511 | case '4'://DAC Command Set Zero; | 
| pravinautosys | 8:ecdfc4582186 | 512 | ResetDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 513 | break; | 
| pravinautosys | 8:ecdfc4582186 | 514 | case '5'://DAC Command Set Full; | 
| pravinautosys | 8:ecdfc4582186 | 515 | FullDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 516 | break; | 
| pravinautosys | 8:ecdfc4582186 | 517 | default:break; | 
| pravinautosys | 8:ecdfc4582186 | 518 | } | 
| pravinautosys | 8:ecdfc4582186 | 519 | } | 
| pravinautosys | 8:ecdfc4582186 | 520 | SerialAvailable = 0; | 
| pravinautosys | 8:ecdfc4582186 | 521 | } | 
| screamer | 0:005629fe3609 | 522 | int main() { | 
| pravinautosys | 8:ecdfc4582186 | 523 | uint16_t Counter=0; | 
| pravinautosys | 8:ecdfc4582186 | 524 | // EncoderButton.fall(&EncoderButtonPressed); | 
| pravinautosys | 8:ecdfc4582186 | 525 | // EncoderButton.enable_irq (); | 
| pravinautosys | 8:ecdfc4582186 | 526 | |
| pravinautosys | 8:ecdfc4582186 | 527 | |
| pravinautosys | 8:ecdfc4582186 | 528 | Rs232.attach(&Rx_interrupt, Serial::RxIrq); | 
| pravinautosys | 8:ecdfc4582186 | 529 | Rs232.attach(&Tx_interrupt, Serial::TxIrq); | 
| pravinautosys | 8:ecdfc4582186 | 530 | |
| pravinautosys | 8:ecdfc4582186 | 531 | OneSecTicker.attach(&SerialDataSend,1.0); | 
| pravinautosys | 8:ecdfc4582186 | 532 | |
| pravinautosys | 8:ecdfc4582186 | 533 | lcd.cls(); | 
| pravinautosys | 8:ecdfc4582186 | 534 | MCP4728Ldac = 0; | 
| pravinautosys | 8:ecdfc4582186 | 535 | ResetDAC(); | 
| pravinautosys | 8:ecdfc4582186 | 536 | //ForHighVoltageModule | 
| pravinautosys | 8:ecdfc4582186 | 537 | ADCData.CalibData[0] = 10.08; | 
| pravinautosys | 8:ecdfc4582186 | 538 | ADCData.CalibData[1] = 10.079; | 
| pravinautosys | 8:ecdfc4582186 | 539 | ADCData.CalibData[2] = 10.096; | 
| pravinautosys | 8:ecdfc4582186 | 540 | ADCData.CalibData[3] = 10.095; | 
| pravinautosys | 8:ecdfc4582186 | 541 | |
| pravinautosys | 8:ecdfc4582186 | 542 | DACData.Ch0 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 543 | DACData.Ch1 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 544 | DACData.Ch2 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 545 | DACData.Ch3 = 0; | 
| pravinautosys | 8:ecdfc4582186 | 546 | |
| pravinautosys | 8:ecdfc4582186 | 547 | lcd.locate(0,0); | 
| pravinautosys | 8:ecdfc4582186 | 548 | // lcd.printf("Test Jig Module "); | 
| pravinautosys | 8:ecdfc4582186 | 549 | lcd.printf("4 Ch HV Module "); | 
| pravinautosys | 8:ecdfc4582186 | 550 | wait(2); | 
| pravinautosys | 8:ecdfc4582186 | 551 | |
| pravinautosys | 8:ecdfc4582186 | 552 | while(1){ | 
| pravinautosys | 8:ecdfc4582186 | 553 | ReadADCConverted(); | 
| pravinautosys | 8:ecdfc4582186 | 554 | LCDPrintDataADC(); | 
| pravinautosys | 8:ecdfc4582186 | 555 | ParseCom(); | 
| pravinautosys | 8:ecdfc4582186 | 556 | if(EncoderButton == 0){ | 
| pravinautosys | 8:ecdfc4582186 | 557 | SetDac(); | 
| pravinautosys | 8:ecdfc4582186 | 558 | } | 
| pravinautosys | 8:ecdfc4582186 | 559 | wait(1); | 
| pravinautosys | 8:ecdfc4582186 | 560 | myled = !myled; | 
| screamer | 0:005629fe3609 | 561 | } | 
| pravinautosys | 8:ecdfc4582186 | 562 | |
| screamer | 0:005629fe3609 | 563 | } | 
| pravinautosys | 8:ecdfc4582186 | 564 | |
| pravinautosys | 8:ecdfc4582186 | 565 | |
| pravinautosys | 8:ecdfc4582186 | 566 | |
| pravinautosys | 8:ecdfc4582186 | 567 | |
| pravinautosys | 8:ecdfc4582186 | 568 | |
| pravinautosys | 8:ecdfc4582186 | 569 | |
| pravinautosys | 8:ecdfc4582186 | 570 | 
