Hi Hans, Step 2 and step 3 should change:
-- Step 2: Set VDD as Vref ADCON1_ADPREF = 0b00 -- Step 3: Use Frc as ADC clock ADCON1_ADCS = 0b011 I hope this works. Kind regards, Rob ________________________________ Van: [email protected] <[email protected]> namens hans <[email protected]> Verzonden: dinsdag 17 januari 2023 17:28 Aan: jallib <[email protected]> Onderwerp: [jallib] 12F1840 sample ADC and usart Hello , Does anyone have an example for this pic, I want an2 in adc and A0 as Tx and A1 as Rx. I've tried to derive some from other programs but I keep stumbling on the datasheet. Hans -- chip setup include 12f1840 -- Internal oscillator at 8 MHz with PLL enabled -> 32 MHz pragma target clock 32_000_000 -- oscillator frequency pragma target OSC INTOSC_NOCLKOUT -- internal oscillator pragma target WDT DISABLED -- watchdog off pragma target PWRTE ENABLED -- power up delay pragma target MCLR EXTERNAL -- reset externally pragma target BROWNOUT DISABLED -- no brownout pragma target CLKOUTEN DISABLED -- no clock out pragma target IESO DISABLED -- no osc switchover pragma target FCMEN DISABLED -- no clock monitoring pragma target PLLEN ENABLED -- PLL enabled pragma target LVP DISABLED -- allow LVP OSCCON_IRCF = 0b1110 -- 8 MHz (+ PLL -> 32 MHz) OSCCON_SCS = 0b00 -- Clock determined by fuses -- OSCCON_PLLEN = TRUE -- PLL fixed enabled by configuration bits enable_digital_io() -- all pins digital const byte ADC_CHANNEL = 2 -- potmeter connected to pin_AN3 ADCON0_CHS2 = TRUE -- port 3 is analog input (default) pin_AN2_direction = input -- Step 2: Set VDD and VSS as Vref FVRCON_FVREN = true -- Step 3: Use Frc as ADC clock ANSEL_ADCS = 0b011 const ADC_RSOURCE = 4_700 -- Input resistance: 4.7K potmeter -- Now we can include the library include adc -- And initialize the whole with our parameters adc_init() var byte DIR forever loop DIR = adc_read_low_res(ADC_CHANNEL) end loop -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/17f8ecc8-484d-4763-aa30-fa7b15395f64n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/17f8ecc8-484d-4763-aa30-fa7b15395f64n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB1637830EB78526ED57F9D78CE6C69%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM.
