• AVR Freaks

Hot!Harmony v2 and ADC channels

Author
dobrosoft
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2019/05/20 04:44:55
  • Location: 0
  • Status: offline
2020/02/05 03:41:50 (permalink)
0

Harmony v2 and ADC channels

I need small help with ADC setting in harmony v2.
 
I need use AN1, AN2, AN3 and AN4 as multiplex in channel 0.  Is it possible to set it in Harmony configurator?
 
When I set Channel instance 0 - and there Channel selection 1 , there is only ADCHS_DEFAULT_CLASS1_AN1.
 
In program I use in initialisation:
  DRV_ADC_Initialize();
  DRV_ADC0_Open();
 
And in service task:
 
DRV_ADC_Start;
if (DRV_ADC_SamplesAvailable(1))
{!(
   current1 = DRV_ADC_SamplesRead(1);
}
DRV_ADC_Stop;
 
It works. But how to configure and use analog input pins AN2, AN3, AN4 as. Is it possible to set it in harmony
 
current2 =  DRV_ADC_SamplesRead(2);
current3 =  DRV_ADC_SamplesRead(3);
current4 =  DRV_ADC_SamplesRead(4);
 
Idea is to have two analog channels: channel1 (Pins AN1,AN2, AN3, AN4) and channel2 (Pins AN0, AN7, AN19) and get independent array of inputs in independent time for each channel. Is it possible?
#1

7 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 604
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/05 07:44:23 (permalink)
    0
    What PIC are you using? (i.e. ADC handling in PIC32MX very different from PIC32MZ)
     
    You can set it in Harmony, but be careful - depending on the Harmony/MHC version there are some bugs that may cause MHC to loose settings, so set the ADC file to read-only to prevent future MHC generate from overwriting good ADC file.
     
    Please have a look at my previous posts over last couple years you'll see several about ADCs for different types of PICs (MX, MZ), including warnings and code patches for different Harmony versions (Hv204 vs Hv206, etc.). If you have specific question after then please post here.
     
    (Click on my name to see my account and post history)
     
    Paul
     
    #2
    nigelwright7557
    Super Member
    • Total Posts : 422
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/05 11:09:05 (permalink)
    0
    I just wrote my own code for using multiple ADC inputs.
     
    #3
    dobrosoft
    Starting Member
    • Total Posts : 76
    • Reward points : 0
    • Joined: 2019/05/20 04:44:55
    • Location: 0
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/06 01:38:43 (permalink)
    0
    I'm using PIC32 MZ.
     
     
    #4
    dobrosoft
    Starting Member
    • Total Posts : 76
    • Reward points : 0
    • Joined: 2019/05/20 04:44:55
    • Location: 0
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/06 05:41:04 (permalink)
    0
    I have set harmony now:
     
    Channel instance 0:
    ADSCHS_CHANNEL_0 pin AN0
     
    Channel instance 1:
    ADSCHS_CHANNEL_1 pin AN1
     
    Channel instance 2:
    ADSCHS_CHANNEL_2 pin AN2
     
    Channel instance 3:
    ADSCHS_CHANNEL_3 pin AN3
     
    Channel instance 4:
    ADSCHS_CHANNEL_4 pin AN4
     
    Channel instance 5:
    ADSCHS_CHANNEL_7
     
    Enable Analog input scanning - yes
    Scan instances - 5
    Scan instance 0 - AN19
    Scan instance 1..4 AN9..12
     
    In program:
     
    if (DRV_ADC_SamplesAvailable(i)){
    adcBuffer = DRV_ADC_SamplesRead(i);
    }
     
    adcBuffer[0..4] get right numbers, but adcBuffer[9..12] and adcBuffer[19] are empty. It's looking like CHANNEL 7 not run input scanning. What's wrong?
    #5
    Paul PortSol
    Super Member
    • Total Posts : 604
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/06 06:18:16 (permalink)
    0
    1. MHC in Hv206 will corrupt ADC settings, so each time you open MHC check all the ADC settings. When you generate a working adc file then set it read only so not overwritten when do an MHC generate for something else.
    Especially Class 2 settings, but other items lost as well.
     
    2. Check that other ADC channels (MHC missed some code).
    DRV_ADC0_Open();//Enable ADC Driver *Channels* as Setup in Harmony
    DRV_ADC1_Open();
    DRV_ADC2_Open();
    DRV_ADC3_Open();
    DRV_ADC4_Open();
    DRV_ADC5_Open();
    // In MHCv2052 after ADC Diagram ensure Manually set Class2 channels if 6 or 7 used, else AN10/AN11 may be set wrong
     
    3. Patch for MHCv2060: Disable this block of generated Code in drv_adc_static.c at about lines 293-306:
    ////// PLIB_ADCHS_ChannelSetup(
    ////// DRV_ADC_ID_1,
    ////// ADCHS_CHANNEL_7,
    ////// ADCHS_DATA_RESOLUTION_12BIT,
    ////// 4,
    ////// 29,
    ////// ADCHS_EARLY_INTERRUPT_PRIOR_CLOCK_4
    ////// );
    //////
    ///////* Since configuration of analog inputs (dedicated and alternate) for dedicated ADC channel */
    ///////* is done via selection of dedicated channel only, here, the analog input for a dedicated */
    ///////* ADC channel number is fixed */ 
    ////// if (DEVADC7 != 0xFFFFFFFF)
    ////// PLIB_ADCHS_ChannelConfigurationSet(DRV_ADC_ID_1, ADCHS_CHANNEL_7, DEVADC7);
     
    4. Attached is my adc_static.c with patches (for reference)
     
    5. Attached my ADC settings (Sorry but had to drop resolution crazy to fit in ancient forum limit).
     
    Paul

    Attached Image(s)

    #6
    dobrosoft
    Starting Member
    • Total Posts : 76
    • Reward points : 0
    • Joined: 2019/05/20 04:44:55
    • Location: 0
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/06 07:38:54 (permalink)
    0
    Thank you Paul. I'm starting to understand the principle fo ADC Configuring with Harmony. I'm going throught generated code of dev_adc_static.c, and change it manually. I read more manuals, but there are examples with one - two adc inputs. It works well with harmony but I need using all channels, 16 analog inputs, and to do it with Harmony is horrible. I hope that your example will help me.
    #7
    Paul PortSol
    Super Member
    • Total Posts : 604
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony v2 and ADC channels 2020/02/06 08:14:25 (permalink)
    0
    This project enables all 37 ADCs on PIC32MZ
    I used dropsend since zip too big for this forum (I've been using dropsend > 10years).
    http://myaccount.dropsend.com/file/62a33cd29021efee
    Paul
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5