Page 2 of 2

Re: Any thoughts on q41 parts?

Posted: Mon Dec 20, 2021 10:54 am
by Jerry Messina
Glad you got it all working!
I seem to remember something like this before and having to put a particular module first but obviously I'm not using much code in this.
I usually add this as the very first two includes in the main program:

Code: Select all

include "intosc.bas"
#option DIGITALIO_INIT = true
include "setdigitalio.bas"
The intosc module will add code to the startup routines to set the osc freq from the 'clock=xxx' setting.
Some devices power up with a slow clock, so you probably want that included first.

Setting '#option DIGITALIO_INIT = true' will automatically add a call to SetAllDigital() at startup
so you don't have to worry about calling it... it'll do that for you. Depending on what other peripherals
you use, that might be important to have happen early on too.
better try the adc next !
Let us know how that goes... the ADC.bas module hasn't been updated in quite a while, so you'll
probably have to change that setup for sure. I keep meaning to look at that one, but there are so many different
ADC peripherals in the devices (and no way to tell which one's which) that trying to have a module
that works with them all is hopeless. I think at last count there were 15 different setups!

Re: Any thoughts on q41 parts?

Posted: Mon Dec 20, 2021 10:59 am
by richardb
I hate to ask again but is there anything obvious i need to do to get the adc working in the 06q41 part, i see the adc is very different and have tried setting some of the registers manually but i just read zeros, and there are 45 pages to do with the adc!!!


Re: Any thoughts on q41 parts?

Posted: Mon Dec 20, 2021 11:51 am
by Jerry Messina
I dug up this code from my notes (so no promises!)

Code: Select all

// This code block configures the ADC for polling, Vdd and Vss references, ADCRC oscillator
ADCON1 = 0
ADCON2 = 0      // Legacy mode, no filtering, ADRES->ADPREV
ADCON3 = 0      // no math functions
ADREF = 0       // Vref = Vdd & Vss
ADCAP = 0       // default S&H capacitance
ADRPT = 0       // no repeat measurements
ADACT = 0       // auto-conversion disabled
ADACQH = 0      // set acquisition time (high byte)-software controlled acquisition time
ADACQL = 0      // set acquisition time (low byte)
ADCON0 = $94    // ADC On, right-justified, ADCRC clock

// to convert:
// set adc channel select register
ADPCH = $00     // select RA0/AN0
// delay for acq time after changing the channel
// start a conversion
ADCON0.bits(0) = 1      // set GO
// wait for conversion to complete
while (ADCON0.bits(0) = 1)
end while
// result is in ADRESH:ADRESL
Make sure you have the ADC pin that you want to convert set as an analog input (TRISx=1, ANSELx=1)
If you've used SetAllDigital, then you'll have to set the pin back to analog mode.

SetDigitalIO.bas has a function you can use to control the mode setting of a single pin:
SetAnalogPort(AN0, ANA)

Re: Any thoughts on q41 parts?

Posted: Mon Dec 20, 2021 9:27 pm
by richardb
Great that worked.

and even managed to get the internal ref to work.

BTW the noise on the ADC seems low at 1or2 counts and no big offset like the k80 pics

This is starting to look like a very flexible small part.

Thanks again Jerry