All About Circuits Forum  

Go Back   All About Circuits Forum > Electronics Forums > The Projects Forum

Notices

The Projects Forum Working on an electronics project and would like some suggestions, help or critiques? If you would like to comment or assist others with their projects, this is the place to do it.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 09-21-2011, 10:13 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default Controlling Two LEDs with Center Tapped Pot

Hey all,

A while back I posted about some center tapped potentiometers I came across, and I'm finally getting around to using them. I'm trying to use the configuration shown to control the brightness of two LED's with PWM. The two LED's are each on a different output (RC2 and RD5 on a PIC18F45K20) with the switching being done by high-side MOSFETs...but that's not important right now

My main issue is coming up with a way for the microcontroller to be able to tell the difference between turning the potentiometer CW and CCW. Details: when the potentiometer is at center, the voltage at the wiper is zero. When the shaft is rotated CW, the voltage increases from 0 to 3.3V. The same thing occurs when the shaft is rotated CCW. This analog voltage is being read through the A/D of the PIC, which controls the duty cycle of the output PWM.

So, the problem is that the PIC doesn't know whether to output to RC2 or RD5 because the input voltage at the A/D varies from 0-3.3V no matter which direction the pot is turned. Does anyone have any ideas on how to make the PIC differentiate the two?

It may seem like a trivial task, but it's a task nonetheless . I think I'm having one of these moments

Reply With Quote
  #2  
Old 09-21-2011, 10:27 PM
SgtWookie's Avatar
SgtWookie SgtWookie is offline
Expert Member
 
Join Date: Jul 2007
Location: In the vast midwest of the USA; CST
Posts: 22,038
Default

Connect one end of the pot to an I/O pin that you can set to either 0v or 3.3v.
Toggle the I/O pin for the uC to tell which end the wiper is on.
__________________
General info:
If you have a question, please start a thread/topic. I do not provide gratis assistance via PM nor E-mail, as that would violate the intent of this Board, which is sharing knowledge ... and deprives you of other knowledgeable input.
Reply With Quote
  #3  
Old 09-21-2011, 10:54 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default

Thanks Sarge,

Just to make sure I'm understanding so far, I would take one end of the potentiometer that is currently always at a logic HI and connect it to an I/O pin instead? I'm still a little unsure how toggling the pin would show which direction the potentiometer was turned.
Reply With Quote
  #4  
Old 09-21-2011, 11:02 PM
SgtWookie's Avatar
SgtWookie SgtWookie is offline
Expert Member
 
Join Date: Jul 2007
Location: In the vast midwest of the USA; CST
Posts: 22,038
Default

1) Have the I/O pin high.
2) Take a reading from the ADC. If it's zero, you're done.
3) Lower the I/O pin to 0v.
4) Take another reading.
5) If the reading changed from the prior one, you're on the side of the pot attached to the I/O pin; otherwise not.
__________________
General info:
If you have a question, please start a thread/topic. I do not provide gratis assistance via PM nor E-mail, as that would violate the intent of this Board, which is sharing knowledge ... and deprives you of other knowledgeable input.
Reply With Quote
  #5  
Old 09-22-2011, 03:41 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default

Thanks Sarge, I think that should work. I wasn't sure what you were saying before, but now I get it. With only one side of the pot at 3.3V, you will only get voltage at the wiper if the potentiometer is rotated in that direction. Simple, yet should be effective. Thanks again.
Reply With Quote
  #6  
Old 09-22-2011, 04:10 PM
BMorse's Avatar
BMorse BMorse is offline
Senior Member
 
Join Date: Sep 2009
Location: Vermontville, Michigan (GMT -5)
Posts: 2,662
Blog Entries: 15
Default

or, connect center tap to IO pin, connect one leg of pot to +, and the other to -, when wiper is in center position, you should have 1/2 the 3.3V, from there you should be able to tell when it is turned in either direction from the input level..... the way it is wired now seems that if pot is turned to one extreme or another, it would just short out Vcc to Gnd
__________________
There is no spoon -Neo-
Disclaimer: The example programs,circuits, projects and information I provide or post on this web site are for educational purposes only. By copying anything from this site posted by me, you agree to the "as is" nature of the programs, circuits, information and to the statements listed in this disclaimer.No warranty or liability is expressed or implied. Working with AC /DC voltages can be dangerous and even deadly. Proceed at your own risk!
Reply With Quote
  #7  
Old 09-22-2011, 04:25 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default

True, and I did try that

The only problem with that is doing the math in the microcontroller to set the duty cycle. The CCPR1L register is the main one controlling duty cycle, and re-scaling the A/D values to correspond to CCPR1L register values results in a significant loss of resolution. For example, when I did it that way the duty cycle would jump from 0% to 5%, then 5% to 8%, then 8% to 15%, etc. Here's why I think it happened:

When the pot is at center, the A/D value is approximately 500. When turned one direction, this increases to 1023. When turned the other direction, this decreases to 0. I basically tried to scale these numbers to something that would fit nicely in CCPR1L. so like this:

500 -> 1023 becomes 0 -> 1023
500 -> 0 becomes 0 -> 1023

The formula required to do this results in a pretty big loss of resolution. There's probably a better way of doing it, but I haven't figured one out yet. Thanks for the suggestion though
Reply With Quote
  #8  
Old 09-22-2011, 04:59 PM
djsfantasi's Avatar
djsfantasi djsfantasi is offline
Senior Member
 
Join Date: Apr 2010
Location: Northeast US
Posts: 1,029
Blog Entries: 1
Default

I suspect that the loss of accuracy that you are seeing has more to do with the accuracy or resolution of the potentiometer than with the scaling formula for the ADC values. You have approximately 500 units on either side of center, which mathematically implies .2% resolution (1/500). Ideally, you should be able to convert up to 1% resolution to reduce jitter.

I wouldn't scale from 500-1023 to 0-1023, but convert 500-0 and 500-1023 to 0-500 and use this value (a range of 500 units) instead. That is what I meant by you should be able to calculate with .2% resolution.

I would test your potentiometer by placing one end at 0v and the other at 3.3v and capturing the results as you slowly rotate the knob from one end to the other. In a perfect world, you should see the values smoothly increase/decrease to/from 0 and 1023. In the practical world, there will be jumps and not distributed evenly.

In my case, I performed statistical analysis of the ADC results to determine the minimum resolution. For my application, much less resolution was required (20% was acceptable ) But I felt your pain while developing my application... http://forum.allaboutcircuits.com/sh...ad.php?t=44738
__________________
- Δj' fαπταi
Reply With Quote
  #9  
Old 09-22-2011, 05:49 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default

That makes sense, I'll check that out. The only thing that confuses me is I've used potentiometers in a similar manner to this where the duty cycle doesn't jump like it does here. The biggest change is the math I'm making the uC do. I'm still working on SgtWookie's suggestion as it turned out to be a little more modification to my original code than I thought would be the case. I'm debugging right now to figure out where my problems are, but I'll update when I get it working.
Reply With Quote
  #10  
Old 09-22-2011, 09:35 PM
jwilk13's Avatar
jwilk13 jwilk13 is offline
Senior Member
 
Join Date: Jun 2011
Location: California
Posts: 228
Default

Thanks to everyone for the input; I'm almost there. It took me a bit to figure out that I wasn't using the pulse steering correctly on my PIC, but once I took care of that, the output switching works perfectly using (roughly) the logic that SgtWookie provided.

As it turns out, I had to do some scaling anyways because of the value in PR2. The good thing is I only had to scale in the positive direction, which made it relatively simple. A few more kinks to work out and it should be good to go
Reply With Quote
Reply   Post New Thread

Tags
, , , ,


Related Site Pages
Section Title
Worksheet Flip-flop circuits
Worksheet Servo motor systems
Worksheet Thyristor application circuits
Worksheet Power conversion circuits
Textbook Stepper motors : Ac Motors
Worksheet Performance-based assessments for DC circuit competencies
Textbook AC instrumentation transducers : Ac Metering Circuits
Textbook Rectifier circuits : Diodes And Rectifiers
Textbook Potentiometer as a voltage divider : Dc Circuits
Textbook Voltage divider circuits : Divider Circuits And Kirchhoff's Laws


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implement max current pot LaserAdct The Projects Forum 5 01-30-2011 03:12 AM
120V Variable Resistor/Digital Pot needed cshoulder General Electronics Chat 11 11-17-2010 07:53 PM
rocker up and down pedal matching pot values relicmarks General Electronics Chat 9 10-24-2009 07:39 AM
Digital Pot max amp question Tobias General Electronics Chat 15 10-19-2009 11:34 AM
Center Tapped Pots? sausages Electronics Resources 6 03-16-2009 10:14 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:51 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.