Phatline Posted February 2, 2021 Report Share Posted February 2, 2021 (edited) hei, for my CV1 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: 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 Edited February 2, 2021 by Phatline Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.