Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
But waaaaaaait.... I was going to use ADC to detect the sine rise...
Does it makes sense to check TTL voltage levels while I want to use ADC?
Yes. Every input signal >2.0V means HIGH.My VDD is 5V so it's simply 2V?
No! You have to look for V_IL to know what the valid levels for LOW are.and 1.9V at pin means LOW?
If I dont have 4.7V Zener diode, can I use 3.3V one?
ADDED:
BTW. I don´t recommend using ADC. It is slow compared to logic levels or comparator input. But if this is no problem for your application then for sure you may use it.
Klaus
Precision...I need to detect the sine rise precisely
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #define ADC_TEST_VALUE 100 void main() { int ac, pot; OSCCON = 0b01110010; // Set internal clock on 8MHz TRISA = 0; // set direction to be output TRISB = 0; // set direction to be output ADCON1 = 0x00; //configure all pins as analog, pins are not disabled individually // UART1_Init(9600); // Initialize UART module at 9600 bps do { LATA = 0x00; // Turn OFF LEDs on PORTA LATB = 0x00; // Turn OFF LEDs on PORTB ac = ADC_Read(2); if(ac < ADC_TEST_VALUE) continue; LATA = 0xFF; // Turn ON LEDs on PORTA LATB = 0xFF; // Turn ON LEDs on PORTB // stay on until sine goes down while(1) { ac = ADC_Read(2); if(ac < ADC_TEST_VALUE) break; } // UART_Write_Text("Changed"); } while(1); // Endless loop }
Hi,
it seems you control the ADC just in the main loop without known/fixed timing.
I strongly recommend to use a fixed ADC sampling rate and an interrupt driven processing of the ADC values.
Klaus
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #define ADC_TEST_VALUE 100 void main() { int ac, pot; OSCCON = 0b01110010; // Set internal clock on 8MHz TRISA = 0; // set direction to be output TRISB = 0; // set direction to be output ADCON1 = 0x00; //configure all pins as analog, pins are not disabled individually // UART1_Init(9600); // Initialize UART module at 9600 bps do { LATA = 0x00; // Turn OFF LEDs on PORTA LATB = 0x00; // Turn OFF LEDs on PORTB ac = ADC_Read(2); if(ac < ADC_TEST_VALUE) continue; LATA = 0xFF; // Turn ON LEDs on PORTA LATB = 0xFF; // Turn ON LEDs on PORTB // stay on until sine goes down while(1) { ac = ADC_Read(2); if(ac < ADC_TEST_VALUE) break; } // UART_Write_Text("Changed"); } while(1); // Endless loop }
Code C - [expand] 1 ADC_Init();
Code C - [expand] 1 LATA = 0x00; // Turn OFF LEDs on PORTA
Code C - [expand] 1 LATA = 0xFF; // Turn ON LEDs on PORTA