Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mita ADC command does not properly setup channels #268

Open
XDK-Support opened this issue Dec 13, 2018 · 4 comments
Open

Mita ADC command does not properly setup channels #268

XDK-Support opened this issue Dec 13, 2018 · 4 comments

Comments

@XDK-Support
Copy link

XDK-Support commented Dec 13, 2018

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
Copy link
Contributor

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

  • use the noise_sensor.noise to read noise
  • do this initialization by hand (see native functions)
  • propose/implement a separate setup for the microphone somewhat like
setup mic: Microphone {
  var mic = connect(samplecount=5000, samplerate=44100); // : array<int8>(length=5000)
}

I hope this helps!

@wegendt-bosch
Copy link
Contributor

wegendt-bosch commented Jan 24, 2019

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

@XDK-Support
Copy link
Author

XDK-Support commented Jan 25, 2019

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 wegendt-bosch reopened this Feb 4, 2019
@wegendt-bosch
Copy link
Contributor

Ok, thanks for the additional feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants