Cerb40: How to initialize Analog input

Hello

How to initialize analog input on Cerb40 ?
I do not found the correct syntax.
There is no socket.

It is OK for Input, Output, InputInterrupt with this syntax:


using GHI.OSHW.Hardware;

OutputPort out1 = new OutputPort(FEZCerberus.Pin.PC7, false);

InputPort in1 = new InputPort(FEZCerberus.Pin.PC8, true, Port.ResistorMode.Disabled);

InterruptPort   Interrupt = new InterruptPort(FEZCerberus.Pin.PC9, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

But how define an AnalogChannel?
I do not found Ferberus.AnalogChannel.

I try this syntax without success:

const Cpu.AnalogChannel PC0 = (Cpu.AnalogChannel)0x20;  // PC0
AnalogInput analog = new AnalogInput(PC0, 8);    =>     'System.ArgumentException' in Microsoft.SPOT.Hardware.dll

Thanks
Christian

@ ChristianJack - Have alook in GHI.OSHW.Hardware and you should see…

FEZCerbuino.Pin.AnalogIn.A0 - FEZCerbuino.Pin.AnalogIn.A5

i.e. AnalogInput pin = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A0);

@ ChristianJack - oops i see your Cerb40 not Cerbuino… strike that

@ ChristianJack - does this work (i dont have a Cer40 to hand)

AnalogInput pin = new AnalogInput((Cpu.AnalogChannel)FEZCerberus.Pin.PC2);

@ Justin

I have already try your syntax but I have also an ‘System.ArgumentException’ in Microsoft.SPOT.Hardware.dll

@ ChristianJack - Have you updated the the latest firmware?

@ Justin : Yes

@ ChristianJack - Can you post your full code

@ Justin
I have try your first code
AnalogInput pin = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A0); but with A3 because A0 do not exists on Cerb40. It is OK.

@ ChristianJack - I think if it’s Cerb40 you should use

AnalogInput pin = new AnalogInput((Cpu.AnalogChannel)FEZCerberus.Pin.PC2);

But if it works, take the money and run :slight_smile:

@ ChristianJack

The AnalogInput syntax will be the same as the other systems: AnalogInput pin = new AnalogInput((Cpu.AnalogChannel)X); where X is the actual channel. You cannot typecast the FEZ pins to AnalogChannels because the channel system is sequential to the driver design.

These are the current pin to channel assignments:


// Pin Configuration
 #define STM32F4_ADC 1     // A6,A2,A3,C0,C1,A4,C2,C3,A5,B0,B1
 #define STM32F4_AD_CHANNELS { 6, 2, 3,10,11, 4,12,13, 5, 8, 9}

Where Channel 0 is pin A6 and B1 is Channel 10.

To verify if you have these channels look at the pin out on the board or on the wiki here: http://wiki.tinyclr.com/index.php?title=FEZ_Cerb40_Developer

@ Justin
First syntax is good and run, second syntax generate Exception.

  1. AnalogInput pin = new AnalogInput(FEZCerbuino.Pin.AnalogIn.A3);
  2. AnalogInput pin = new AnalogInput((Cpu.AnalogChannel)FEZCerberus.Pin.PC3);

Thanks. It is Ok for me.

@ ChristianJack - Have a read of Aron’s explanation - he knows what he’s talking about :wink:

Number 2 gives the exception because when you are typecasting the FEZCerberus.Pin.PC3 to the CPU.AnalogChannel you are just taking PC3, which is the number 35, and trying to assign the AnalogInput object the channel 35. The Cerb family only has 11 channels available for Analog input.