Author Topic: CH32V003A4 - A3 and A4 adc pins remap  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

Offline HeindalTopic starter

  • Contributor
  • Posts: 16
  • Country: us
CH32V003A4 - A3 and A4 adc pins remap
« on: November 18, 2024, 02:04:50 pm »
Making a board variant for the 16-pin CH32V003A4 which is a variant of the 20-pin CH32V003F4. The problem is that most of the pins need to remapped  and some pins dont exist on 16 pin version. for the ADC i have gotten A0,A1,A2,A5,A6 an A7 remapped properly but A3 and A4 do not work even If I map  PD1 and PD7 to them. PD1 and PD7 are analog compatible pins according to the datasheet.

I figured that maybe they only work with the Opamp and comparator. And Is it best just to not use A3 and A4 and leave this variant with only 6 working Adc pins.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14101
  • Country: gb
    • Mike's Electric Stuff
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #1 on: November 18, 2024, 02:41:14 pm »
Not sure if its the case with the 16 pin, but on the 8 pin, some pins are bonded to multiple pads on the chip, so they all need to be configured in a compatible way
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1600
  • Country: gb
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #2 on: November 18, 2024, 05:05:20 pm »
I think there's some confusion here.

For a start, ADC input channels cannot be remapped on CH32V003. You either use the channels through their related pins or you don't. Like, for example, A0 is fixed on PA2 and you can't change that. The only thing remappable concerning the ADC are external trigger inputs - see ADC_ETRG* bits in AFIO_PCFR1. Note the lack of any other ADC things in AFIO.

Also, A3 and A4 are not associated with pins PD1 and PD7 on any chip package of the CH32V003. In fact those pins do not have any ADC channel associated with them. I don't know where you will have got that idea from or what you're doing to "map" them. A3 and A4 are associated with PD2 and PD3 respectively (see Table 2-2 in datasheet), which - indeed as OP correctly says - are not exposed on SOP16 package.

Heindal, I think you are out of luck, and A3 & A4 are just not usable on the SOP16 package. :--

Not sure if its the case with the 16 pin, but on the 8 pin, some pins are bonded to multiple pads on the chip, so they all need to be configured in a compatible way

According to the pin-out table in the datasheet, the SOP16 package does not do any pin sharing like SOP8.
 

Offline HeindalTopic starter

  • Contributor
  • Posts: 16
  • Country: us
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #3 on: November 18, 2024, 05:49:34 pm »
I meant remap it for chip since some of the pins are not the same. I will leave the same config for a3 and a4 . PD1 and PDA7 are analog pins according to the datasheet. I know its not mapped to A3 or A4. If you try to read a3 & a4 it works but the pin is just not connected to any external pin.

Heres the remapped ADC pin code for ch32v003A4

Code: [Select]
//*** ADC ***
#ifdef ADC_MODULE_ENABLED
WEAK const PinMap PinMap_ADC[] = {
 
  // PD2 and PD3 dont exist for CH32V003A4
  {PA_2,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 0)}, // ADC1_IN0 (A0) (works)
  {PA_1,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 1)}, // ADC1_IN1 (A1) (works)
  {PC_4,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 2)}, // ADC1_IN2 (A2) (works)
  {PD_2,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 3)}, // ADC1_IN3 (A3)
  {PD_3,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 4)}, // ADC1_IN4 (A4)
  {PD_5,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 5)}, // ADC1_IN5 (A5) (Works)
  {PD_6,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 6)}, // ADC1_IN6 (A6) (Works)
  {PD_4,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 7)}, // ADC1_IN7 (A7) (works)
  {NC,        NP,   0}

};
#endif

For comparison Here is also the default code for CH32V003F4. When used with CH32V003A4, only A0(PA2), A1(PA1), A2(PC4) kind of works.

Code: [Select]
//*** ADC ***
#ifdef ADC_MODULE_ENABLED
WEAK const PinMap PinMap_ADC[] = {
  {PA_2,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 0)}, // ADC1_IN0
  {PA_1,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 1)}, // ADC1_IN1
  {PC_4,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 2)}, // ADC1_IN2
  {PD_2,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 3)}, // ADC1_IN3
  {PD_3,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 4)}, // ADC1_IN4
  {PD_5,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 5)}, // ADC1_IN5
  {PA_6,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 6)}, // ADC1_IN6
  {PA_4,      ADC1, CH_PIN_DATA_EXT(CH_MODE_INPUT, CH_CNF_INPUT_ANALOG, 0, AFIO_NONE, 7)}, // ADC1_IN7
  {NC,        NP,   0}
};
#endif



Also modified code for TIM2 & TIM1 for CH32V003A4

Code: [Select]
//*** TIM ***
#ifdef TIM_MODULE_ENABLED
WEAK const PinMap PinMap_TIM[] = {

  // TIM2 is Fully Remapped -> Complete mapping (CH1/ETR/PC1, CH2/PC7, CH3/PD6, CH4/PD5).
 
  {PC_1,       TIM2, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_FullRemap_TIM2_ENABLE, 1)}, // TIM2_CH1
  {PC_7,       TIM2, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_FullRemap_TIM2_ENABLE, 2)}, // TIM2_CH2
  {PD_6,       TIM2, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_FullRemap_TIM2_ENABLE, 3)}, // TIM2_CH3
  {PD_5,       TIM2, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_FullRemap_TIM2_ENABLE, 4)}, // TIM2_CH4

  //Pins PD2 & PD0 dont exist on Ch32v003A4. So the respected channels cannot work.

  {PD_2,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 1)}, // TIM1_CH1
  {PA_1,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 2)}, // TIM1_CH2
  {PC_3,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 3)}, // TIM1_CH3
  {PC_4,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 4)}, // TIM1_CH4
  {PD_0,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 1)}, // TIM1_CH1N
  {PA_2,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 2)}, // TIM1_CH2N
  {PD_1,       TIM1, CH_PIN_DATA_EXT(CH_MODE_OUTPUT_50MHz, CH_CNF_OUTPUT_AFPP, NOPULL, AFIO_Remap_TIM1_DISABLE, 3)}, // TIM1_CH3N
  {NC,         NP,   0}
};

 Also you can see in the table in the datasheet , PD1 and PDA7 are analog but it could be Analog only for Opamp/comparator.
« Last Edit: November 18, 2024, 05:57:08 pm by Heindal »
 

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1600
  • Country: gb
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #4 on: November 18, 2024, 06:19:12 pm »
Oh, I see, you're talking about some kind of software mapping for a driver or other abstraction layer. Yeah, sucks to not be able to have a 'complete' interface.

The "I/O/A" in the datasheet just means the pin has structure that includes input driver, output driver, and has a connection for analog input. Not that the analog input is necessarily connected to anything to do with the ADC. ;D



Yeah, PD7 will be using it for op-amp channel 1 positive input. No idea why PD1 has analog input, because as far as I understand, ADC AETR2 takes a digital signal. :-//
 

Offline HeindalTopic starter

  • Contributor
  • Posts: 16
  • Country: us
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #5 on: November 18, 2024, 07:13:13 pm »
This is kinda of a reminder but if anyone is using Serial.printf in platformio or arduino core....don't use it if you want more storage. printf is very costly in terms of flash. Replaced it with serial.print. At first , i was wondering how i was reaching 62% flash usage with barely any code but after i removed printf it went down from 62% to 33%. 
 

Offline rhodges

  • Frequent Contributor
  • **
  • Posts: 349
  • Country: us
  • Available for embedded projects.
    • My public libraries, code samples, and projects for STM8.
Re: CH32V003A4 - A3 and A4 adc pins remap
« Reply #6 on: November 18, 2024, 09:27:43 pm »
Would you be interested in binary/decimal functions? If so, I can share them here.
Currently developing embedded RISC-V. Recently STM32 and STM8. All are excellent choices. Past includes 6809, Z80, 8086, PIC, MIPS, PNX1302, and some 8748 and 6805. Check out my public code on github. https://github.com/unfrozen
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf