일종의 유추 신호를 pic18f14k50 컨트롤러로 읽으려고합니다. 여기 간단한 회로 : http://dl.dropbox.com/u/14663091/schematiconew.pdf. AN9 회로 포트에서 아날로그 신호를 읽어야합니다. 주요 기능은 포트로부터 판독하고, 임계 값에 도달하면 30 시간 점멸 :PIC A/D 변환 관련 문제
void main(void) {
InitializeSystem();
#if defined(USB_INTERRUPT)
USBDeviceAttach();
#endif
while(1) {
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) continue;
if(!HIDTxHandleBusy(lastTransmission))
{
int readed = myReadADC2(); //Here i tried both myReadADC2() or myReadADC1()
if(readed>40) { //If read threshold > 40, blink led 30 times
int i;
for(i=0; i<30; i++) {
Delay1KTCYx(0);
mLED_1_On();
Delay1KTCYx(0);
mLED_1_Off();
}
}
lastTransmission = HIDTxPacket(HID_EP, (BYTE*)hid_report_in, 0x03);
}//end while
}//end main
I는 AN9 포트로부터 판독하기 위해 두 방법을 이용을,() API 메소드 OpenADC 사용 myReadADC()
int myReadADC(void) {
#define ADC_REF_VDD_VDD_X 0b11110011
OpenADC(ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH9 & ADC_INT_OFF, ADC_REF_VDD_VDD_X & ADC_REF_VDD_VSS, 0b00000010); // channel 9
SetChanADC(ADC_CH9);
ConvertADC(); // Start conversion
while(BusyADC()); // Wait for completion
return ReadADC(); // Read result
}
및 myReadADC2()는 포트에서 수동 읽기를 구현합니다.
int myReadADC2() {
int iRet;
OSCCON=0x70; // Select 16 MHz internal clock
ANSEL = 0b00000010; // Set PORT AN9 to analog input
ANSELH = 0; // Set other PORTS as Digital I/O
/* Init ADC */
ADCON0=0b00100101; // ADC port channel 9 (AN9), Enable ADC
ADCON1=0b00000000; // Use Internal Voltage Reference (Vdd and Vss)
ADCON2=0b10101011; // Right justify result, 12 TAD, Select the FRC for 16 MHz
iRet=100;
ADCON0bits.GO=1;
while (ADCON0bits.GO); // Wait conversion done
iRet=ADRESL; // Get the 8 bit LSB result
iRet += (ADRESH << 8); // Get the 2 bit MSB result
return iDelay;
}
두 경우 모두이 작품은, 내가 포트 AN9 (아날로직 신호를 전송)을 만지지하지만 높은 임계 값을 설정하면 (~ 50) 낮은 임계 값,하지 깜박을 주도 (~ 0)이 immidiatly를 할 때 깜박하지 않습니다 나는 PIC에 전원을 공급한다. 어쩌면 잘못된 포트를 사용하고 있을까요? 실제로 AN9를 읽는 포트로 전달하고 있습니까? 아니면 임계 값이 잘못되었을 수 있습니까? 어떻게 올바른 가치를 발견 할 수 있습니까? 감사합니다
여기서 MPLAB C18 Apis http://dl.dropbox.com/u/14663091/API%20microchip%20C18.pdf입니다.
이 질문은 http://electronics.stackexchange.com/에 속하지 않으십니까? – YudhiWidyatama
아마도 어쩌면 예. 나는 그것을 옮겨야 만 하는가 아니면 관리 작업인가? – Emilio
죄송합니다. 자동으로 사용자를 이동할 수 없습니다. PIC는 프로그래밍이 가능하기 때문에 여기 또는 Electronics SE (또는 둘 다)에서 PIC 질문을 할 수 있다고 생각합니다. –