ankit-max
Junior Member level 1
- Joined
- Dec 20, 2012
- Messages
- 17
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,402
Device 16F72
Xtal 4
'Settings for ADC
Declare Adin_Res 8
Declare Adin_Tad 32_FOSC
Declare Adin_Stime 50
Output PORTB.7 'Led connected
Low PORTB.7
Dim x As Byte 'to store digital value
GoTo start
analog:
x=ADIn 0
DelayMS 10
Return
start:
x=0
lp:
GoSub analog
If x > 180 Then
High PORTB.7
ElseIf x < 180 Then
Low PORTB.7
EndIf
GoTo lp
Device 16F72
Xtal 4
Declare Adin_Res 8
Declare Adin_Tad 32_FOSC
Declare Adin_Stime 50
ADCON1 = %00000010
TRISA = %00000111
TRISB = %00000000
'Output PORTB.7
Low PORTB.7
Dim x As Byte
GoTo start
analog:
x=ADIn 0
DelayMS 10
Return
start:
x=0
High PORTB.7
DelayMS 1000
Low PORTB.7
DelayMS 1000
High PORTB.7
DelayMS 1000
Low PORTB.7
lp:
GoSub analog
If x > 204 Then
Low PORTB.7
ElseIf x < 204 Then
High PORTB.7
EndIf
GoTo lp
What Basic Compiler are you using?
Ok. I got it. It's Proton Development Suite. I will try and let you know.
It is working fine. Yo adc is 8 bit. So, for 204 raw adc value input volts will be 4. See the simulation LED will be ON till vin is 4V (204) and it will be OFF if > 4 V (>204). You have to use Fosc/8.
Edit: Even if your pot position is in the center you get 20V. I think your adc is already damaged by giving high voltage.
Ex: Say I power up PIC with a 9v Battery and I use 7805 regulator IC to give VDD(5V) to pic as a supply - ground being same. Now, I take a pot. I connect one send of pot to the +9V and the other end to the GND. And I give middle terminal of pot to the PortA.0 (Keeping 9v = 5v using divider), and vary the 9v voltage so I would get variation on PortA.0. So, would it give the correct result as ADC is using VDD as reference voltage which is supply of the PIC?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?