Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
analog.c MICRO maskings that work for me
19-05-2012, 11:58 PM, (This post was last modified: 20-05-2012, 01:36 PM by KiloOne.)
#1
analog.c MICRO maskings that work for me
The analogmask and bufmask for the MICRO in analog.c do not work for me.

The existing masks in r433 are:
Code:
#if defined(PIC32_PINGUINO_MICRO)

u16 __analogmask[] = { _1,  _2,  _3,  _4, nil, nil, nil,  _8,   //  0- 7
                       _9, _10, _11, _12, nil, _14, nil, nil,   //  8-15  nil is a unavailable pin
                       _0, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                      nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

u16 __bufmask[]    = {  4,   8,  12,  16,  32,  36,  40,  44,   //  0- 7
                       48,  56, nil, nil, nil, nil, nil, nil,   //  8-15
                        0, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                      nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31
#endif

Here is what I have found to work (for me) on all MICRO AN# pins (0-4,8-12 and 14):
Code:
#if defined(PIC32_PINGUINO_MICRO)

u16 __analogmask[] = {nil,  _1,  _2,  _3,  _4, nil, nil,  _8,   //  0- 7
                       _9, _10, _11, _12, nil, _14, nil, nil,   //  8-15  nil is a unavailable pin
                       _0, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                      nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

u16 __bufmask[]    = {nil,   4,   8,  12,  16, nil, nil,  32,   //  0- 7    
                       36,  40,  44,  48,  nil, 56, nil, nil,   //  8-15
                        0, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                      nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

Also I have come across something funny about reading AN0. It appears that a correct analog value can be read on AN0 pin using many pin numbers in an analogRead statement. I don't have time to work on this further but it may deserve some attention too.

Hope this helps others.

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
20-05-2012, 10:43 AM, (This post was last modified: 20-05-2012, 01:54 PM by mf01.)
#2
RE: analog.c errors in MICRO maskings
Hi Dale,

I am not saying you are wrong, but the changes you are suggesting are not necessarily consistent with how the analog inputs are defined for other boards. Pinguino IDE A0 does not necessarily = AN0. For the PIC32 Pignuino OTG board A0 = AN1 and AN0 is not used for any of the the defined analogue inputs (A0 - A7). I suspect that this is to allow AN0 to be used with a reference voltage - the PIC32 Pinguino Micro schematic includes a similar jumper to that included on the PIC32 Pinguino OTG board.

That having been said, I do not fully understand the relationship between the Pinguino IDE Analog inputs and the entries in _analogmask[] and _buffmask[].

For the PIC32 Pinguino OTG the values for the Pinguino IDE analogue pins, the IC analog register, the corresponding other register and the corresponding entry in _analogmask are:-

A0 = AN1 = RB1 = 0x0002
A1 = AN2 = RB2 = 0x0004
A2 = AN3 = RB3 = 0x0008
A3 = AN4 = RB4 = 0x0010
A4 = AN8 = RB8 = 0x0100 (also linked to RD9)
A5 = AN9 = RB9 = 0x0200 (also linked to RD8)
A6 = AN11 = RB11 = 0x0800
A7 = AN10 = RB10 = 0x0400

The same physical inputs are also accessible as A14 - A21 (corresponding to D14 - D21).

Further details are in the table I published on the wiki (PIC32 Pinguino OTG Xref Table)).

What I am not sure about is why the tables for the Micro have "gaps" or nulls in them. This would suggest that only some of the A# numbers are valid and the sequence of A# numbers is not continuous as it is for the OTG.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
20-05-2012, 11:56 AM, (This post was last modified: 20-05-2012, 05:17 PM by jpmandon.)
#3
RE: analog.c errors in MICRO maskings
According to this pinout:
http://wiki.pinguino.cc/images/9/9d/Pic3...ctions.JPG

I think the analog_mask should be:

u16 __analogmask[] = { _1, _2, _3, _4, _8, _9, _10, _11, // pin 0- 7
_12, _14, nil, nil, nil, nil, nil, nil, // 8-15 nil is a unavailable pin
_0, nil, nil, nil, nil, nil, nil, nil, // 16-23
nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

nil value are not used but will be later used to return an error if a non analogic pin is passed as a parameter. ( if == nil return nil ). This is on the TODO list
A0 to A7 need to be adapted with a #if board directive. Their value should be adapted to each board and their particular pin out.

To be clear ( I hope !!):
On PIC32MX3XXX/4XXX, analog mask is the ANX number corresponding to the pin.
if AN3 is connected to pin 16 ( and pin A2 ) -> analog_mask[2] should be _3 and analog_mask[16] should be _3 ( because both A2 or 16 can be used in the analogRead instruction )
this example is made with PIC32-PINGUINO-OTG schematic
buf_mask is the value used to select the channel in the AD1CHS register during the conversion.
for PIC32MX3XXX/4XXX, buf_mask should be equal to analog_mask*4

On PIC32MX1XXX/2XXX, an array is added.
port_mask is the corresponding port for a particular pin
on PINGUINO32-DIY:
AN2 is connected to pin 12 and AN2 is RB0, port_mask[12]=pB
analog_mask is the offset of the pin number
for the example above, analog_mask[12]=_2 ( because AN2 )
buf_mask is the value used to select the channel in the AD1CHS register during the conversion.

GENERIC32MX250F128 and GENERIC32MX220F032 board are an exception because all the Analogic input are on PORTB. So no need to define a port_mask array.

I'm not sure to be as clear as possible, if you need more info, just ask.....

JP

(20-05-2012, 10:43 AM)mf01 Wrote: Hi Dale,

I am not saying you are wrong, but the changes you are suggesting are not necessarily consistent with how the analog inputs are defined for other boards. Pinguino IDE A0 does not necessarily = AN0. For the PIC32 Pignuino OTG board A0 = AN1 and AN0 is not used for any of the the defined analogue inputs (A0 - A7). I suspect that this is to allow AN0 to be used with a reference voltage - the PIC32 Pinguino Micro schematic includes a similar jumper to that included on the PIC32 Pinguino OTG board.

That having been said, I do not fully understand the relationship between the Pinguino IDE Analog inputs and the entries in _analogmack[] and _buffmask[].

For the PIC32 Pinguino OTG the values for the Pinguino IDE analogue pins, the IC analog register, the corresponding other register and the corresponding entry in _analogmask are:-

A0 = AN1 = RB1 = 0x0002
A1 = AN2 = RB2 = 0x0004
A2 = AN3 = RB3 = 0x0008
A3 = AN4 = RB4 = 0x0010
A4 = AN8 = RB8 = 0x0100 (also linked to RD9)
A5 = AN9 = RB9 = 0x0200 (also linked to RD8)
A6 = AN11 = RB11 = 0x0800
A7 = AN10 = RB10 = 0x0400

The same physical inputs are also accessible as A14 - A21 (corresponding to D14 - D21).

Further details are in the table I published on the wiki (PIC32 Pinguino OTG Xref Table)).

What I am not sure about is why the tables for the Micro have "gaps" or nulls in them. This would suggest that only some of the A# numbers are valid and the sequence of A# numbers is not continuous as it is for the OTG.

Regards
Reply
20-05-2012, 01:57 PM, (This post was last modified: 20-05-2012, 02:21 PM by KiloOne.)
#4
RE: analog.c MICRO maskings that work for me
Sorry guys but after having spent most of a day trying to be able to read a voltage on the MICRO's PIC32MX440F256H physical pins associated with AN0, AN1,AN2,AN3,AN4,AN8,AN9,AN10,AN11,AN12,AN14 using an analogmask and bufmask that worked for all of them, I posted my successful result. These pins are all accessible on the MICRO header pins directly.

I tried to edit the existing arrays as little as possible and as I said AN0 seems to have different values that do work.

Creating an A0-A7 would not be enough for the MICRO as I count at least 11 accessible analog pins on CON1 and CON2.

Dale

jp,

On a end-user level, where a person just has to put in a correct pin for their analogRead(pin), wouldn't this be less confusing and should also work?
Code:
#if defined(PIC32_PINGUINO_MICRO)

u16 __analogmask[] = { _0,  _1,  _2,  _3,  _4, nil, nil, nil,   //  0- 7
                        _8,  _9, _10, _11, _12, nil, _14, nil,   //  8-15  nil is a unavailable pin
                       nil, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                       nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

u16 __bufmask[]    = {  0,   4,   8,  12,  16, nil, nil, nil,   //  0- 7    
                        32,  36,  40,  44,  48, nil,  56, nil,   //  8-15
                       nil, nil, nil, nil, nil, nil, nil, nil,   // 16-23
                       nil, nil, nil, nil, nil, nil, nil, nil }; // 24-31

That way at least the pin # matches the AN# (even though that is not really necessary).

Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
20-05-2012, 03:01 PM,
#5
RE: analog.c MICRO maskings that work for me
Hi Dale,

sorry if I caused any confusion but my post was only meant to point out the inconsistency in how the Micro _analogmask[] array had been set, and not meant to suggest that only 8 analog inputs should be mapped for the Micro. JP's suggestion for __analogmask does make all the analog inputs available, all be it in a different order. I think that part of the reason for JP's suggestion is so that there is a simple correspondence between the Pinguino Analog inputs (A#) and the digital pins (P#), so that if A0 is used then P0 will not in general be available for use as a digital input/output although this simple correspondence does not appear to be there for all boards.

Also I noticed that the current __bufmask[] array is also consistent with what JP has proposed for __analogmask[], so JP's proposal is probably the minimum change as only __analogmask[] is changed.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
25-02-2013, 11:37 PM,
#6
RE: analog.c MICRO maskings that work for me
I am trying the analogRead on a Pinguino-Micro and nether maps seem to work for me. I can use AN1 and AN2 but as for the rest... blank.

quick example:
Code:
int value[3];
void setup() {

    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A2, INPUT);
    pinMode(A3, INPUT);
}

loop() {
    while (digitalRead(USERBUTTON)) {
    
        value[0]= analogRead(A0);
        value[1]= analogRead(A1);
        value[2]= analogRead(A2);
        value[3]= analogRead(A3);
        CDC.println("%d %d %d %d ", value[0], value[1], value[2], value[3]);
        delay(50);
     }
}

the results :
-1610580164 xxx yyy -1610580164

where xxx and yyy is ok, e.g. 0 if pulled to gnd and 1023 if pulled to +3.3

also anything above A7 is not allowed when compiled.

I a running Pinguino x.3 rev unknown !

Any help much appreciated....Thanks in advance.
Reply
26-02-2013, 11:37 PM,
#7
RE: analog.c MICRO maskings that work for me
I retied this again today, removed the mask from KiloOne so analog.c was back to standard and the I re-pasted KiloOne mask back in (after working out the logic), and it works !!Undecided - clearly I must have made a typo or som'it (not sure how I could mess up copy and paste but....)

However, if you want to use A8-A12 and A14 then you need to use the numbers only or define them, as somewhere defines only to A7. I tried adding the following in analog.c

Code:
#if defined(PIC32_PINGUINO_MICRO)
    #define A0 0
    #define A1 1
    #define A2 2
    #define A3 3
    #define A4 4
    #define A8 8
    #define A9 9
    #define A10 10
    #define A11 11
    #define A12 12
    #define A14 14
#else
    #define A0 0
    #define A1 1
    #define A2 2
    #define A3 3
    #define A4 4
    #define A5 5
    #define A6 6
    #define A7 7
#endif

but that did not work.

answers on a postcard (or on this forum Smile )
Reply
27-02-2013, 09:42 PM,
#8
RE: analog.c MICRO maskings that work for me
Try in const.h instead of analog.c

(26-02-2013, 11:37 PM)Telboy Wrote: I retied this again today, removed the mask from KiloOne so analog.c was back to standard and the I re-pasted KiloOne mask back in (after working out the logic), and it works !!Undecided - clearly I must have made a typo or som'it (not sure how I could mess up copy and paste but....)

However, if you want to use A8-A12 and A14 then you need to use the numbers only or define them, as somewhere defines only to A7. I tried adding the following in analog.c

Code:
#if defined(PIC32_PINGUINO_MICRO)
    #define A0 0
    #define A1 1
    #define A2 2
    #define A3 3
    #define A4 4
    #define A8 8
    #define A9 9
    #define A10 10
    #define A11 11
    #define A12 12
    #define A14 14
#else
    #define A0 0
    #define A1 1
    #define A2 2
    #define A3 3
    #define A4 4
    #define A5 5
    #define A6 6
    #define A7 7
#endif

but that did not work.

answers on a postcard (or on this forum Smile )
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)