PDA

View Full Version : Another question about 12F675



fratello
- 24th August 2010, 12:28
Hi everybody !
I intend to use ADC(AN3) of 12F675 and using VRef . My question is : pin 6-GP1 must be connected to VDD ?
I post my code. Thanks in advance !

@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, bod_off

DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

CMCON = 7
OPTION_REG = %10000110
TRISIO = %00011110 'if 1 then GPIO=input ; if 0 then GPIO=output
ANSEL = %00011000
ADCON0 = %10001101

..............
adcin 3, read_volt
read_volt=read_voltage * 5000
read_volt=div32 1023

sayzer
- 24th August 2010, 13:49
Datasheet:

bit 6 VCFG: Voltage Reference bit
1 = VREF pin
0 = VDD


So you have to change your


ADCON0 = %10001101


to


ADCON0 = %11001101


AND connect Vref pin to your separate voltage source (since you want to use Vref pin, you should have a voltage source other than Vdd).

fratello
- 24th August 2010, 14:38
Thank You for such fast reply!
So :
If I connect pin 6 to VDD - it's correct ADCON0= %10001101.
In this case, this code

adcin 3, read_volt
read_volt=read_voltage * 5000
read_volt=div32 1023
it's correct ? It's possible to read so at AN3 the voltage between 0 and 5 volts(VDD)?
I need to read maximum 1 volt...
Some explanations: I intend to use ADC of 12F675 like "over-current detector" for one electrical motor. The montage is used in autovehicle,where, I think, it's spikes of voltage and I search the way to avoid PIC dammge.

sayzer
- 24th August 2010, 15:29
Thingie %1:
If you need to measure max. 1Volt, then you may want to have a 1V voltage source connected to Vref Pin. Something like " LM185-1.2/LM285-1.2/LM385-1.2
Micropower Voltage Reference Diode" or" LM4121 1.25V Precision Micropower Low Dropout Voltage Reference". Not 1V though.
But, if you set ADC module with Vref pin and connect Vref pin to Vdd, you simply waste a pin. You do not have to use Vref in such case;
bit 6 VCFG: Voltage Reference bit
1 = VREF pin
0 = VDD

If you set it as "0 = VDD" then you do not need to connect Vref pin to Vdd. You can use GP1 for other purposes.

Thingie %10:
May I recommend that you use comparator module of this PIC for "over load" dedection & protecton?
It will be much quicker.
You can set your comparator module to a level where you want the protection take action.

fratello
- 24th August 2010, 16:01
Thanks, again !
On first "boot" (when I power up for the first time the montage) I read the over-load current ( about 300 mV) and I store the value into eeprom. Next time, I read the current and if this is > value memorised, then I stop the motor. This works fine , but, time to time, the PIC is dammaged. I use for power LM 2931AZ5, with 100uF and 100nF .I really don't understand why this...so I think maybe it's something wrong with this pin (6). Thank You for support !