VF50: Read ADC does not work


I have to use the ADC of the VF50 and get always an error when reading from it. The return value of VybAdc_Read is always zero and when I execute GetLastError() I get ERROR_INVALID_HANDLE.
Finally when I close and uninitialize the ADC I succeed again.

But the returned handle of the init function is always valid. My test routine looks like that:

HANDLE adcHandle;
adcHandle = VybAdc_Init(L"ADC3"); 
if (adcHandle == NULL)
	RETAILMSG(1, (L"Error in Adc_Init()\r\n"));
RETAILMSG(1, (TEXT("VybAdc_Init with HANDLE: %u\r\n"), adcHandle));

BOOL bSuccess = FALSE;
bSuccess = VybAdc_SetConfigInt(adcHandle, L"BitResolution", 12, StoreVolatile);
RETAILMSG(1, (TEXT("VybAdc_SetConfigInt: %d\r\n"), bSuccess));
bSuccess = VybAdc_SetConfigInt(adcHandle, L"AvgSamples", 8, StoreVolatile);
RETAILMSG(1, (TEXT("VybAdc_SetConfigInt: %d\r\n"), bSuccess));

bSuccess = VybAdc_Open(adcHandle);
RETAILMSG(1, (TEXT("VybAdc_Open: %d\r\n"), bSuccess));

DWORD vtg = 0;
bSuccess = (VybAdc_Read(adcHandle, &vtg, 4) != 0);
RETAILMSG(1, (TEXT("VybAdc_Read: %d, HANDLE: %u, voltage: %u\r\n"), bSuccess, adcHandle, vtg));

bSuccess = VybAdc_Close(adcHandle);
RETAILMSG(1, (TEXT("VybAdc_Close: %d\r\n"), bSuccess));

bSuccess = VybAdc_Deinit(adcHandle);
RETAILMSG(1, (TEXT("VybAdc_Deinit: %d\r\n"), bSuccess));

The resulting log output is like that:

VybAdc_Init with HANDLE: 3396195504
VybAdc_SetConfigInt: 1
VybAdc_SetConfigInt: 1
VybAdc_Open: 1
VybAdc_Read: 0, HANDLE: 3396195504, voltage: 0
VybAdc_Close: 1
VybAdc_Deinit: 1

I don’t see what might be wrong. Do you have any idea?
The difference to the demo programs on your homepage (which are working) is that I’m using it not in a application, but directly in our custom BSP.



I just did a test with out latest library and your code and it was working ok for me.
Does it work if you try our default BSP?

What did you change compared to our bsp?


It seems to not work when the opening of the ADC port VybAdc_Open takes place already in the init of a subproject of the BSP. When opening it just before the measurement which is triggered from an application it works.

Probably when the opening of the ADC port takes place too early not all needed resources might be available (e.g. clock source of ADC block).

Yes, this sub project is a driver. But isn’t the ADC block started by executing VybAdc_Open?

No, if you look at debug output ADC driver is loaded. VybAdc_open only uses ADC driver. You can change order property of ADC driver and your driver so you make sure they are loaded one after another.

Ok, yes I can see that

Loading ADC1...
Done ADC1...
Loading ADC2...
Done ADC2...

are loaded only after my driver. So then I have to change that of course.

Thanks for your support.

Is this sub project a driver? If its loaded earlier in boot process then ADC driver this may happen.

You could change order of ADC driver to make it load earlier.