FORUM TOPIC · READ ONLY

ADC inputs yet again

ADC inputs yet again

Forum : dsPIC Peripherals

3 message(s) · archive en lecture seule

Bernard Leak
It has been some months since I last picked up a new copy of the block-set, and the latest

version seems to have broken something which once worked.



The default behaviour seems to be to leave all analogue input pins configured for

analogue input. Explicitly putting a digital I/O block in a model would set bits in the

AD[12]PCFG[HL] registers to disable them as analogue inputs. In the past, I have

used digital input blocks driving terminator blocks. to ensure that I could use the

associated pin as a digital I/O pin (in code not visible in the Simulink model diagram).

This no longer works.



The analogue pins I am using are all in AN16-31 (so they are configured

in AD1PCFGH). The list is [ 16 17 18 19 20 22 23 24 25 26 ].

I am using AN27-AN31 as digital inputs. Whereas AD1PCFGH used

to be set (correctly) to 0xF800, it is now left as 0 (the default state

at start-up).



There has been some change in this area: in fact, I used to see compiler

warnings about 16-bit shifts on 16-bit quantities.
Bernard Leak

Re: ADC inputs yet again

Here's a tiny illustrative model. This one shows the problem even though

there is no ADC input at all!



On this CPU (dsPIC33FJ256GP710) the digital I/O pins given are

also analogue inputs (numbered as labelled). At power-on, all the

analogue input pins are configured as ADC inputs by default,

represented by 0 bits in the ADxPCFGL and AD1PCFGH registers.

The generated dummy.c file has all the appropriate details.

TRISE is (correctly) left with all bits set, so all the pins are inputs.

However, AD1PCFGH is left with all bits clear, so AN16-AN31

are configured as analogue inputs only; port read input is disabled,

so the actual state of the pin isn't read.



AD1PCFGL and AD2PCFGL are explicitly (and redundantly)

set to their default value of 0. This guarantees that the

same problem will also affect AN0-AN15 (it so happens that

I wasn't using any of these as inputs).

Pièce jointe : dummy.mdl

Pièce jointe : dummy.c

LubinKerhuel

Re: ADC inputs yet again

Thanks again for this clear bug description with simulin example.It really helped to track it !



the bug is corrected and the corrected blockset version will be available in the next blockset version (following version 0.99c)



Lubin