CV Sampling (J5 Pin 0/1)

hei,

for my 

i want to sample/record the ControlVoltage which is connected to J5 Pin0 and Pin1.

Mostly for Envelopes (which i get from an envelope follower), which i read out in Milliseconds…thats enough since its for VCA and not a VCO…

I can not directly scan it via Board_J5_Pin Get— because this routine is only for Digital Signals:

< base_url >/topic/21290-mios32_board_jx_pinget-x-returns-0-when-set-2-analog/?do=embed&comment=186125&embedComment=186125&embedDo=findComment

so i have to use the AIN-Driver… or is there any other way? Has anybody programmed already some kind of BIT-Crusher? (AIN to AOUT), or some stripped down code - that is more easy to understand, to get get access directly to the GPIO?

I miss some basic knowledge to abserve some basic GPIO-Readout… in the AIN-Driver i identificate my 2 pins:
  { ADC_Channel_11, GPIOC, GPIO_Pin_1 }, // J5A.A0
  { ADC_Channel_12, GPIOC, GPIO_Pin_2 }, // J5A.A1

 

but maybe its better to copy the whole AIN-Driver to the project-directory, and strip it down until i get a glue… renamed it to sampler and include it… i see that coming…

 

 

when stripping it down to scan only one channel, without DMA, oversampling, deadband and all that stuff:

#include \<mios32.h\> static u16 ain\_pin\_values; // this table maps ADC channels to J5.Ax pins typedef struct { u8 chn; GPIO\_TypeDef \*port; u16 pin\_mask; } adc\_chn\_map\_t; static const adc\_chn\_map\_t adc\_chn\_map = { ADC\_Channel\_11, GPIOC, GPIO\_Pin\_1 }; ///////////////////////////////////////////////////////////////////////////// //! Initializes AIN driver ///////////////////////////////////////////////////////////////////////////// s32 AIN\_Init(u32 mode) { // clear variables ain\_pin\_values = 0; // set analog pins GPIO\_InitTypeDef GPIO\_InitStructure; GPIO\_StructInit(&GPIO\_InitStructure); GPIO\_InitStructure.GPIO\_Mode = GPIO\_Mode\_AN; GPIO\_InitStructure.GPIO\_PuPd = GPIO\_PuPd\_NOPULL; GPIO\_InitStructure.GPIO\_Pin = adc\_chn\_map.pin\_mask; GPIO\_Init(adc\_chn\_map.port, &GPIO\_InitStructure); // enable ADC1/2 clock RCC\_APB2PeriphClockCmd(RCC\_APB2Periph\_ADC1 | RCC\_APB2Periph\_ADC2, ENABLE); // configure ADCs ADC\_CommonInitTypeDef ADC\_CommonInitStructure; ADC\_CommonStructInit(&ADC\_CommonInitStructure); ADC\_CommonInitStructure.ADC\_Mode = ADC\_DualMode\_RegSimult; ADC\_CommonInitStructure.ADC\_Prescaler = ADC\_Prescaler\_Div2; ADC\_CommonInitStructure.ADC\_DMAAccessMode = ADC\_DMAAccessMode\_2; ADC\_CommonInitStructure.ADC\_TwoSamplingDelay = ADC\_TwoSamplingDelay\_5Cycles; ADC\_CommonInit(&ADC\_CommonInitStructure); ADC\_InitTypeDef ADC\_InitStructure; ADC\_StructInit(&ADC\_InitStructure); ADC\_InitStructure.ADC\_ScanConvMode = ENABLE; ADC\_InitStructure.ADC\_ContinuousConvMode = DISABLE; ADC\_InitStructure.ADC\_ExternalTrigConvEdge = ADC\_ExternalTrigConvEdge\_None; //ADC\_InitStructure.ADC\_ExternalTrigConv = ADC\_ExternalTrigConv\_None; ADC\_InitStructure.ADC\_DataAlign = ADC\_DataAlign\_Right; ADC\_InitStructure.ADC\_NbrOfConversion = 1; ADC\_Init(ADC1, &ADC\_InitStructure); ADC\_Init(ADC2, &ADC\_InitStructure); // enable ADCs ADC\_Cmd(ADC1, ENABLE); return 0; } ///////////////////////////////////////////////////////////////////////////// //! Returns value of an AIN Pin ///////////////////////////////////////////////////////////////////////////// s32 AIN\_PinGet(u32 pin){ return ain\_pin\_values; } ///////////////////////////////////////////////////////////////////////////// //! Checks for pin changes ///////////////////////////////////////////////////////////////////////////// s32 AIN\_Handler(void \*\_callback) { MIOS32\_IRQ\_Disable(); u32 pin\_value = ain\_pin\_values; MIOS32\_IRQ\_Enable(); return 0; // no error }

at least the Initalize is done there (hopefully)

but which part of the code really reads out the Pin-Value isnt clear for me