pin sharing between ADC and IO output

cancel
Showing results for 
Search instead for 
Did you mean: 

pin sharing between ADC and IO output

707 Views
duonghiep_set
Contributor II

Hi all,

I have a question about pin sharing between ADC and IO

My circuit use PTB3 for both ADC and IO output. In start, circuit will check a jumper to choice config PTB3 is ADC input or output.

I setup ADC and IO in figure below:

pastedImage_1.png

pastedImage_2.png

In main(), I Check jumper and set direction of PTB3 is output  "CDS_SetOutput()" and blinking it, but It isn't work. The output don't change when I mount a LED in.

How can I do that??

Edit:

MCU : MKE02Z16VLC4

CW 10.7

Thanks,

Plus.

Labels (1)
4 Replies

508 Views
andy1
Contributor II

You will have to write code that changes the use of the pin depending on your jumper. My suggestion is to make two configurations (builds) of your project. Each copy will be configured for one of the two specific uses alone. That way you can test that they both work independently. AND even more importantly, you can compare the PE generated code for each build and find see how the PE tool configures the pin and peripherals for each output. (use a freeware tool like Diffmerge to compare the code files in each project directory)

Once you do that, you can make a single project that can run the appropriate configuration code depending on which use you want for PTB3.

In general, you need to do two different things to switch from ADC input to GPIO output. I am using MCUExpresso and the latest Kinteis SDKs, not Processor Expert. So this is purely example code, but I expect that the solution for your situation will be similar. (BTW, Why are you using old tools like PE? I suggest updating to the current toolchain if you want to get the best help on here.)

1: Initialize the pin as an output, with an initial state of 0:

gpio_pin_config_t gpiob_pin38_config = {
.pinDirection = kGPIO_DigitalOutput,
.outputLogic = 0U
};
GPIO_PinInit(GPIOB, 3U, &gpiob_pin38_config);

2: Switch the pin MUX to GPIO, this disconnects the port from the ADC and connects it to the GPIO module:
PORT_SetPinMux(PORTB, 3U, kPORT_MuxAsGpio);

If you wanted to switch back to ADC, you would need to do a similar thing, except set the pin mux to ADC instead of GPIO:

(PORT_SetPinMux(PORTB, 3U, kPORT_PinDisabledOrAnalog);

508 Views
duonghiep_set
Contributor II

Thank Andrew,

Your suggestion is very helpful. I'm using PE because of many reasons like my company system, team activities..etc.

This project was be pending so my circuit is be in bottom of the cabinet. :smileygrin: 

When have time, I will coding in MCUExpresso and try your code.

Regard,

Plus.

0 Kudos

508 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi,

Processor Expert can't understand your requirement. You setting is conflict to each other. You have to manually add you code. You must take care that each time you generate Processor Expert code, it may cover your own code.

Regards,

Jing

508 Views
duonghiep_set
Contributor II

Hi Jing,

Many thank for your suggestion.

I'm newbie and I am in embarrass that how to setup GPIO and ADC without PE.

I will search and try on my circuit.

Regards,

Plus.

0 Kudos