eclipse / mita

mita
Eclipse Public License 2.0
56 stars 20 forks source link

Mita ADC command does not properly setup channels #268

Open XDK-Support opened 5 years ago

XDK-Support commented 5 years ago

When using the setup adc in Mita with the XDK workbench for the ADC channel the code generated does not correctly set up the pin configuration for the channels.

when using the following code:

package main;
import platforms.xdk110;

setup adc: ADC {
var microphone = channel(CH4);
}

It generates a config for the given channel in the file ConnectivityADCAdc.c and initializes the ADC with it.

AdcCentral_ConfigSingle_T microphone_config = {
   .AcqTime = ADC_ACQ_TIME_16,
   .Appcallback = adcCallback,
   .BufferPtr = &AdcResultBuffer,
   .Channel = ADC_ENABLE_CH4,
   .Reference = ADC_REF_2V5,
   .Resolution = ADC_RESOLUTION_12BIT
};

Retcode_T ConnectivityADCAdc_Setup(void)
{
   Retcode_T exception = RETCODE_OK;

   exception = AdcCentral_Init();
   if(exception != RETCODE_OK) return exception;

   AdcSampleSemaphore = xSemaphoreCreateBinary();
   if(AdcSampleSemaphore == NULL) {
       return RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_SEMAPHORE_ERROR);
   }

   return NO_EXCEPTION;
}

Retcode_T ConnectivityADCAdc_Enable(void)
{

   return NO_EXCEPTION;
}

But it is missing a pin configuration for the used pins. In case of the used microphone, there is also no voltage supply enabled for the microphone. For using the microphone, the function calls of BSP_Mic_AKU340_Connect() and BSP_Mic_AKU340_Enable() are needed in the function ConnectivityADCAdc_Setup() in the generated C code.

For the other ADC channels, the function calls to configure the pins as inputs and connecting to them are missing too and would need to be added in the same manner as for the microphone.

wegendt-bosch commented 5 years ago

If I understand the ADC correctly what you're describing is connecting the microphone to the ADC channel 4. This is not always what you want to do if you want to measure this channel though. Therefore I don't think that always connecting the microphone for CH4 is correct. Instead you could

setup mic: Microphone {
  var mic = connect(samplecount=5000, samplerate=44100); // : array<int8>(length=5000)
}

I hope this helps!

wegendt-bosch commented 5 years ago

Since I got no response I'll assume this issue is solved. Feel free to respond if you still have problems.

XDK-Support commented 5 years ago

Hello wegendtbosch,

Unfortunately, I have to ask you to take a second look, using the noise sensor as you described works but the pin configuration is missing for the other ADC channels, such as PD5 and PD6, as I described in the last sentence of my last post.

Aside from that, the noise sensor usage with ch4 was copied from the WB 3.5 release notes which should, in that case, be corrected there or in Mita.

The ADC is initialized and enabled but reading an invalid configured input pin regardless of what channel is to be read due to missing initialization of the pin, therefore it returns weird readouts.

If you also check the generated includes in the files, there is no mention of a module that could be used to initialize the GPIOs as well. Therefore the GPIOs are not defined as inputs.

To solve this, a call of the functions BSP_ExtensionPort_ConnectAdc() and BSP_ExtensionPort_EnableAdc() from the BSP_ExtensionPort.h interface with the corresponding pin would be required.

Kind Regards

wegendt-bosch commented 5 years ago

Ok, thanks for the additional feedback!