void AGC_Task(void) { u16 RFVol;//基准的RF电压值 u16 RF=0; if (Config.AGC == flg_AGC) //agc { RF = ADC_RUN(ADC_OP);//ADC_Data[0]; if (RF < 0X05) { Att= ATT_AGC_old;//没有信号,开机没信号则=30, //中途没信号则=ATTAGCold } else { if (Dataflash.AGC > 86 ) { Dataflash.AGC = 86; } else if (Dataflash.AGC <= 0 ) { Dataflash.AGC = 0; } RFVol = AGC_RFVol[Dataflash.AGC]; if ( AGColdflg == flg_MGC) //上次是MGC状态,不比较直接进入AGC状态 { Att = ATT_AGC_old; } else //last time AGC { if ( RF < (RFVol-4) ) //实际值RF值 小于基准值 //if (RFVol - adcRF > RF_OFFSET) { if ( ATT_AGC_old > 0) //那么减小衰减值 { Att = ATT_AGC_old - 1; } else { Att = 0; } } else if ( RF > (RFVol+4) ) //实际RF 大于 基准值 加大衰减量 { if ( ATT_AGC_old < 63 ) { Att = ATT_AGC_old + 1; } else { Att = 63; } } else //等于基准 { Att=ATT_AGC_old ; } } } ATT_AGC_old = Att ; AGColdflg = flg_AGC; } else //MGC { Att = Dataflash.MGC; AGColdflg = flg_MGC; } if (Att != ATT_old) { ATTControl(Att); // LED(CLOSE); Delayms(20); // LED(OPEN); // Delayms(100); } ATT_old = Att; //RFF[5]= Att; //SendFrame(RFF,6); }
void ADCtask(void) { unsigned char alarmtemp = 0; u8 f = 0; static unsigned count[4]={0,0,0,0}; if ( Config.laserSWflag == OPEN) { if (ADC_RUN(ADC_OP) < LASER_OP_LOW) //OP { if (count[0] > 2) { alarmtemp |= (0x01 << 0); count[0] = 3; f = 1; } else count[0]++; } else { count[0]=0; alarmtemp &= 0xFE; } if ((ADC_RUN(ADC_IB) < LASER_IA_LOW) || (ADC_RUN(ADC_IB) > LASER_IA_HIGH))//IB { if (count[1] > 2) { alarmtemp |= (0x01 << 1); count[1] = 3; f = 1; } else count[1]++; } else { count[1]=0; alarmtemp &= 0xFD; } if ((ADC_RUN(ADC_TEM) < LASER_TEMP_LOW)||(ADC_RUN(ADC_TEM) > LASER_TEMP_HIGH))//TEMP { if (count[2] > 2) { alarmtemp |= (0x01 <<2); count[2] = 3; f=1; } else count[2]++; } else { count[2]=0; alarmtemp &= 0xFB; } } else { count[0]=0; count[1]=0; count[2]=0; } if((ADC_RUN(ADC_RF)< LASER_RF_LOW) || (ADC_RUN(ADC_RF) > LASER_RF_HIGH)) { if(count[3]>2) { alarmtemp |= (0x01 << 3); count[3] = 3; f = 1; } else count[3]++; } else { count[3] = 0; alarmtemp &= 0xF7; } if(f==1) //有告警 { //alarmtemp |= 0x01; LED(OPEN); //open red led } else //无告警 { // alarmtemp &= 0xFE; LED(CLOSE); } Dataflash.Err = alarmtemp; }
void UART0_IRQHandler(void) { static char *line = &cmdbuf[0]; static uint16_t frequency=1; float results[2]; uint32_t temp; uint32_t U0IIR = 0; uint32_t baudrate; uint32_t result[2]; extern uint8_t CorrectIndexesOverride; extern uint8_t CorrectIndexesBrute; extern uint8_t EqualIndexes; extern uint16_t FirstOverrideIndex; extern uint16_t SecondOverrideIndex; char *EndFromStrtoul; U0IIR=UART_GetIntId(LPC_UART0); if ((U0IIR & 0xE) == 0x4) { c = UART_ReceiveByte(LPC_UART0); if (c == CR) c = LF; /* read character */ if (c != LF) { if (c == BACKSPACE || c == DEL) { /* process backspace */ if (uart_rcv_len_cnt != 0) { uart_rcv_len_cnt--; /* decrement count */ line--; /* and line pointer */ putchar (BACKSPACE); /* echo backspace */ putchar (' '); putchar (BACKSPACE); } } else if (c != CNTLQ && c != CNTLS) { /* ignore Control S/Q */ putchar (*line = c); /* echo and store character */ line++; /* increment line pointer */ uart_rcv_len_cnt++; /* and count */ } if (uart_rcv_len_cnt == sizeof(cmdbuf)) { printf("\nError."); printf("\nBuffer full."); } } else { line = &cmdbuf[0]; UART_pressed_enter = 1; if (command == none) { if ( (strcmp(cmdbuf, "cal") == 0) && uart_rcv_len_cnt == 3) { command = Calibrate; printf("\n Entered into calibrating state. Type calibrating command.\n>"); UART_pressed_enter = 0; } else if ( (strcmp(cmdbuf, "m") == 0) && uart_rcv_len_cnt == 1) { wait(1); Measure(results, frequency); printf("\n Magnitude of impedance is: "); printf("%.1f Ohm.", results[0]); printf("\n Phase of impedance is: "); printf("%.2f graduses.", results[1]*57.295779513); printf("\nType next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "f ", 2) == 0) { frequency = atoi(&(cmdbuf[2])); AD9833_SetFreq(frequency*1000); AD9833_Start(); printf("\n New DDS frequency is %u kHz. ", frequency); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "fmin ", 5) == 0) { f_min = atoi(&(cmdbuf[5])); printf("\n f_min are %u kHz.", f_min); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "fmax ", 5) == 0) { f_max = atoi(&(cmdbuf[5])); printf("\n f_max are %u kHz.", f_max); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "nf ", 3) == 0) { n_F = atoi(&(cmdbuf[3])); printf("\n n_F are %u.", n_F); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if ((strncmp(cmdbuf, "bg", 2) == 0) && uart_rcv_len_cnt == 2) { bg_flag = 1; UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "r ", 2) == 0) { temp = atoi(&(cmdbuf[2])); AD7793_SetRate(temp); printf("\n AD7793 rate field = are %u.", temp); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if ( uart_rcv_len_cnt == 0) { StartADC=1; UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "g", 1) == 0) { ADC_RUN(result); printf("\n Magnitude are %u.", result[0]); printf("\n Phase are %u.", result[1]); printf("\n Type next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "d ", 2) == 0) { debug_mode = atoi(&(cmdbuf[2])); if (debug_mode == 0) { printf("\n Debug mode disabled."); } else { printf("\n Debug mode enabled."); } printf("\nType next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "raw ", 4) == 0) { raw_data_mode = atoi(&(cmdbuf[4])); if (raw_data_mode == 0) { printf("\n Raw data mode disabled."); } else { printf("\n Raw data mode enabled."); } printf("\nType next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "UartFifo ", 9) == 0) { UartWithFifo = atoi(&(cmdbuf[9])); if (UartWithFifo == 0) { printf("\n Software UART FIFO disabled."); } else { printf("\n Software UART FIFO enabled."); } printf("\nType next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "UART ", 5) == 0) { baudrate = atoi(&(cmdbuf[5])); SER_Init(baudrate); printf("\n UART baudrate are %u bps.", baudrate); printf("\nType next command.\n>"); UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "CIO ", 4) == 0) { CorrectIndexesOverride = atoi(&(cmdbuf[4])); if (CorrectIndexesOverride == 1) { printf("\nEnter correct override indexes:\n>"); command = CorrectIndexesPutting; } else { printf("\n Index overriding disabled."); printf("\nType next command.\n>"); } UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "CIB ", 4) == 0) { CorrectIndexesBrute = atoi(&(cmdbuf[4])); if (CorrectIndexesBrute == 1) { printf("\n Correct calibrating curves brute forcing enabled."); printf("\nType next command.\n>"); } else { printf("\n Correct calibrating curves brute force disabled."); printf("\nType next command.\n>"); } UART_pressed_enter = 0; } else if (strncmp(cmdbuf, "EI ", 3) == 0) { EqualIndexes = atoi(&(cmdbuf[3])); if (EqualIndexes == 1) { printf("\n Equal calibrating indexes for mag and phase enabled."); printf("\nType next command.\n>"); } else { printf("\n Equal calibrating indexes for mag and phase disabled."); printf("\nType next command.\n>"); } UART_pressed_enter = 0; } else { printf("\nWrong command. Please type right command.\n"); UART_pressed_enter = 0; } memset(cmdbuf,0,15); uart_rcv_len_cnt=0; } else if (command == CorrectIndexesPutting) { FirstOverrideIndex = strtoul(cmdbuf, &EndFromStrtoul, 10); SecondOverrideIndex = atoi(EndFromStrtoul); printf("\n FirstCorrectIndex = %u", FirstOverrideIndex); printf("\n SecondCorrectIndex = %u", SecondOverrideIndex); printf("\nType next command.\n>"); UART_pressed_enter = 0; command = none; memset(cmdbuf,0,15); uart_rcv_len_cnt=0; } } } else if ((U0IIR & 0xE) == 0x2) { if (SW_UART_FIFO_STRUCT.count!=0) { LPC_UART0->THR = SW_UART_pop(); } else UART_IntConfig(LPC_UART0,UART_INTCFG_THRE,DISABLE); //Disable UART0 THRE Interrupt } }