Hello,
I have used a PIC 16F1788 to make driver for a VFD display. If I use
the internal clock (=4MHZ) and the default ADC reference voltage (=Vdd),
everthing works fine.I want to switch these to an external clock input and an external Vref
for accuracy and stability reasons.I have tried many combinations of commands to switch the
clock and change the bits in the ADCON registers. Nothing I do has any effect. The chip always
runs using the default conditions. Any ideas? Has anyone done this before? If so,how? Thank you.
( I am using a PICKit 3 to program the chip).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What have you tried? can you post some example of what has not worked?
Are you using GCGB or the IDE?
What version of the GCB compiler do you have ? This is important. GreatCowBasic\GCBASIC.exe /version will give you the version.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
External oscillator is handled in the config(uration) registers. Perhaps the easiest way to detect the options is looking at the chipdata file in GreatCowBasic folder of your installation. If it is an external crystal/resonator than there is the LP, XT, or HS designators. So for say a 20 Mhz crystal than the config would look like:
#config OSC=HS
For setting the a-d reference voltage than that would be the ADCON1 register, specifically the ADPREF0 and ADPREF1 bits. Setting the adc positive reference voltage to the Vref+ pin during initialization would be:
ADPREF1 = 0
ADPREF0 = 1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The PIC16F1788 defaults to differential ADC inputs so to get it working with an external VREF+ and the Negative VREF- set to Vss (GND) some bits need to be set.
First the ADPREF and ADNREF bits need to be configured as follows
SET ADPREF1 OFF 'Default
SET ADPREF0 ON
SET ADNREF OFF ' Default
Then the CHSN Bits need to be set as follows.
SET CHSN3 ON
SET CHSN2 ON
SET CHSN1 ON
SET CHSN0 ON
Below is working Code using a PIC16F1788 on a breadboard where a 10K POT connected to AN2 (PIN 4) for adjusting the ADC value and another 10K POT is connected to RA3 (Pin 5) to act as an adjustable VREF+. This works perfectly.
In your application you will need to physically Connect the external positive reference source to AN3 (Pin5)
I am using an external clock source ( 12 MHz Crystal)
Here is the Complete Working Code:
;---16F1788ADCTEST----;ByWilliamRoth;12-18-2015;*************************#chip 16F1788, 12#config OSC=HS#config MCLRE = OFF;SetupLCDParameters#define LCD_IO 4#define LCD_NO_RW#define LCD_Speed fast;-----DefineHardwaresettings#define LCD_RS PORTB.1#define LCD_Enable PORTB.0#define LCD_DB4 PORTC.4#define LCD_DB5 PORTC.5#define LCD_DB6 PORTC.6#define LCD_DB7 PORTC.7CLS'Set Vref+ to External Pin RA3/Pin5SETADPREF1OFFSETADPREF0ONSETADNREFOFF' defaults to off (redundant)'Set VREF- to VssSETCHSN3ONSETCHSN2ONSETCHSN1ONSETCHSN0ONLightLevel=ReadAD(AN2)'Pin4;MainloopDoForever'Take a measurement and store in the LightLevel variableLightLevel=ReadAD(AN2)'PinA.2'Display measurementLocate0,0Print"Light Level: "PrintLightLevelWait500msLocate0,12'clear value on screen"Print" "Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have used a PIC 16F1788 to make driver for a VFD display. If I use
the internal clock (=4MHZ) and the default ADC reference voltage (=Vdd),
everthing works fine.I want to switch these to an external clock input and an external Vref
for accuracy and stability reasons.I have tried many combinations of commands to switch the
clock and change the bits in the ADCON registers. Nothing I do has any effect. The chip always
runs using the default conditions. Any ideas? Has anyone done this before? If so,how? Thank you.
( I am using a PICKit 3 to program the chip).
What have you tried? can you post some example of what has not worked?
Are you using GCGB or the IDE?
What version of the GCB compiler do you have ? This is important. GreatCowBasic\GCBASIC.exe /version will give you the version.
External oscillator is handled in the config(uration) registers. Perhaps the easiest way to detect the options is looking at the chipdata file in GreatCowBasic folder of your installation. If it is an external crystal/resonator than there is the LP, XT, or HS designators. So for say a 20 Mhz crystal than the config would look like:
For setting the a-d reference voltage than that would be the ADCON1 register, specifically the ADPREF0 and ADPREF1 bits. Setting the adc positive reference voltage to the Vref+ pin during initialization would be:
Hi Louis,
Do you mean setting an external clock source for the PIC or setting the clock source for the ADC in the ADCON1 Register (ADCS Bits)?
Please take the time to post your (non-working) GCB code so that we can have a look. I have a PIC16F1788 on a breadboard that I can test/debug.
William
The PIC16F1788 defaults to differential ADC inputs so to get it working with an external VREF+ and the Negative VREF- set to Vss (GND) some bits need to be set.
First the ADPREF and ADNREF bits need to be configured as follows
SET ADPREF1 OFF 'Default
SET ADPREF0 ON
SET ADNREF OFF ' Default
Then the CHSN Bits need to be set as follows.
SET CHSN3 ON
SET CHSN2 ON
SET CHSN1 ON
SET CHSN0 ON
Below is working Code using a PIC16F1788 on a breadboard where a 10K POT connected to AN2 (PIN 4) for adjusting the ADC value and another 10K POT is connected to RA3 (Pin 5) to act as an adjustable VREF+. This works perfectly.
In your application you will need to physically Connect the external positive reference source to AN3 (Pin5)
I am using an external clock source ( 12 MHz Crystal)
Here is the Complete Working Code: