EmbeddedRelated.com
Forums

Interfacing a PIC with Digital Potentiometer?

Started by smitty505000 October 9, 2005
Hi Neil, Chris,

What Chris says is correct; you can generate a R/C servo control signal in
the PIC. They've been well documented. They use a varying pulse width.

Read through Chuck's site:

http://www.mcmanis.com/chuck/robotics/

Alan KM6VV > Chris
> Sent: Monday, October 10, 2005 5:45 AM
> To: piclist@picl...
> Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
>
> wrote:
> >
> > Norm,
> On my Head Mounted Display will be two
> > heading lock gyro's that will read up/down and left/right. They will
> > send data to the pic that will convert those and then send out to
> > the digi pots. These two pots output to my radio and will then
> > control camera pan and tilt on my plane. What do you think? Crazy
> > huh?
> >
> > Neil Smith
>
> Sounds great, you might even be able to save using the pots at all if
> you can find out the method of signal modulation following the a/d
> conversion from the existing pot, and how it's fed to the rf modulator
> side of things. You're using a pic already so it might be fun to try
> and elliminate the need for digital pots completely !


To elaborate on Alan's posting, by sending a pulse that is between 1ms
and 2ms long every 20ms any servo can go from full throw in either
direction. Centre stick is represented by a 1.5ms pulse.

Malcolm

Alan Marconett wrote:

> Hi Neil, Chris,
>
> What Chris says is correct; you can generate a R/C servo control signal in
> the PIC. They've been well documented. They use a varying pulse width.
>
> Read through Chuck's site:
>
> http://www.mcmanis.com/chuck/robotics/
>
> Alan KM6VV > > Chris
> > Sent: Monday, October 10, 2005 5:45 AM
> > To: piclist@picl...
> > Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
> >
> > wrote:
> > >
> > > Norm,
> > On my Head Mounted Display will be two
> > > heading lock gyro's that will read up/down and left/right. They will
> > > send data to the pic that will convert those and then send out to
> > > the digi pots. These two pots output to my radio and will then
> > > control camera pan and tilt on my plane. What do you think? Crazy
> > > huh?
> > >
> > > Neil Smith
> >
> > Sounds great, you might even be able to save using the pots at all if
> > you can find out the method of signal modulation following the a/d
> > conversion from the existing pot, and how it's fed to the rf modulator
> > side of things. You're using a pic already so it might be fun to try
> > and elliminate the need for digital pots completely ! >
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions >
> >. >
>



I recently create a PIC program for driving 8 servos using timer
interrupts. It has 12.8 uS resolution although this could probably be
improved. You can find it here in the Files section as
ArrayOfInterruptDrivenServos.zip

Richard

-- In piclist@picl..., Malcolm <malcolm.crabbe@n...> wrote:
>
> To elaborate on Alan's posting, by sending a pulse that is between 1ms
> and 2ms long every 20ms any servo can go from full throw in either
> direction. Centre stick is represented by a 1.5ms pulse.
>
> Malcolm
>
> Alan Marconett wrote:
>
> > Hi Neil, Chris,
> >
> > What Chris says is correct; you can generate a R/C servo control
signal in
> > the PIC. They've been well documented. They use a varying pulse
width.
> >
> > Read through Chuck's site:
> >
> > http://www.mcmanis.com/chuck/robotics/
> >
> > Alan KM6VV
> >
> >
> > > Chris
> > > Sent: Monday, October 10, 2005 5:45 AM
> > > To: piclist@picl...
> > > Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
> > >
> > > wrote:
> > > >
> > > > Norm,
> > > On my Head Mounted Display will be two
> > > > heading lock gyro's that will read up/down and left/right.
They will
> > > > send data to the pic that will convert those and then send out to
> > > > the digi pots. These two pots output to my radio and will then
> > > > control camera pan and tilt on my plane. What do you think? Crazy
> > > > huh?
> > > >
> > > > Neil Smith
> > >
> > > Sounds great, you might even be able to save using the pots at
all if
> > > you can find out the method of signal modulation following the a/d
> > > conversion from the existing pot, and how it's fed to the rf
modulator
> > > side of things. You're using a pic already so it might be fun to try
> > > and elliminate the need for digital pots completely !
> >
> >
> >
> >
> > to unsubscribe, go to http://www.yahoogroups.com and follow the
> > instructions
> >
> >
> >

> > >.
> >
> >
> >

> >
>




HI Richard,

Thanks for the contribution! I take it this code is for R/C type servos.

Now all it needs is an RS-232 interface (USB?), and a simple command
language.

Alan KM6VV > -----Original Message-----
> From: piclist@picl... [mailto:piclist@picl...] On Behalf
> Of rtstofer
> Sent: Monday, October 10, 2005 12:49 PM
> To: piclist@picl...
> Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
>
> I recently create a PIC program for driving 8 servos using timer
> interrupts. It has 12.8 uS resolution although this could probably be
> improved. You can find it here in the Files section as
> ArrayOfInterruptDrivenServos.zip
>
> Richard
>
> -- In piclist@picl..., Malcolm <malcolm.crabbe@n...> wrote:
> >
> > To elaborate on Alan's posting, by sending a pulse that is between 1ms
> > and 2ms long every 20ms any servo can go from full throw in either
> > direction. Centre stick is represented by a 1.5ms pulse.
> >
> > Malcolm
> >
> > Alan Marconett wrote:
> >
> > > Hi Neil, Chris,
> > >
> > > What Chris says is correct; you can generate a R/C servo control
> signal in
> > > the PIC. They've been well documented. They use a varying pulse
> width.
> > >
> > > Read through Chuck's site:
> > >
> > > http://www.mcmanis.com/chuck/robotics/
> > >
> > > Alan KM6VV
> > >
> > >
> > > > Chris
> > > > Sent: Monday, October 10, 2005 5:45 AM
> > > > To: piclist@picl...
> > > > Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
> > > >
> > > > wrote:
> > > > >
> > > > > Norm,
> > > > On my Head Mounted Display will be two
> > > > > heading lock gyro's that will read up/down and left/right.
> They will
> > > > > send data to the pic that will convert those and then send out to
> > > > > the digi pots. These two pots output to my radio and will then
> > > > > control camera pan and tilt on my plane. What do you think? Crazy
> > > > > huh?
> > > > >
> > > > > Neil Smith
> > > >
> > > > Sounds great, you might even be able to save using the pots at
> all if
> > > > you can find out the method of signal modulation following the a/d
> > > > conversion from the existing pot, and how it's fed to the rf
> modulator
> > > > side of things. You're using a pic already so it might be fun to try
> > > > and elliminate the need for digital pots completely !
> > >
> > >
> > >
> > >
> > > to unsubscribe, go to http://www.yahoogroups.com and follow the
> > > instructions
> > >
> > >
> > >
>
> > > >.
> > >
> > >
> > >
>
> > >
> >
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
> Yahoo! Groups Links


--- In piclist@picl..., "Alan Marconett" <KM6VV@a...> wrote:
>
> HI Richard,
>
> Thanks for the contribution! I take it this code is for R/C type
servos.
>
> Now all it needs is an RS-232 interface (USB?), and a simple
command
> language.
>
> Alan KM6VV

Yes, R/C servos. However, it isn't very granular and there are only
about 100 steps between 0 and 180 degrees - see the code listing.

What probably needs to happen is to move the pulse on time to Timer
1 because it is 16 bits. Then Timer 0 could generate the 20 mS
timing interval. That isn't easy because Timer 0 is only 8 bits.

If you use a PIC with 2 16 bit counters life is good!

Nevertheless, it will get you started.

Richard


HI Richard,

Yes, I see that now. Timer 0 could still run at a faster rate, say 1 mS,
and then only "act" every 20 mS. I'll have to give all that a try.

Alan KM6VV

> -----Original Message-----
> From: piclist@picl... [mailto:piclist@picl...] On Behalf
> Of rtstofer
> Sent: Monday, October 10, 2005 3:53 PM
> To: piclist@picl...
> Subject: [piclist] Re: Interfacing a PIC with Digital Potentiometer?
>
> --- In piclist@picl..., "Alan Marconett" <KM6VV@a...> wrote:
> >
> > HI Richard,
> >
> > Thanks for the contribution! I take it this code is for R/C type
> servos.
> >
> > Now all it needs is an RS-232 interface (USB?), and a simple
> command
> > language.
> >
> > Alan KM6VV
>
> Yes, R/C servos. However, it isn't very granular and there are only
> about 100 steps between 0 and 180 degrees - see the code listing.
>
> What probably needs to happen is to move the pulse on time to Timer
> 1 because it is 16 bits. Then Timer 0 could generate the 20 mS
> timing interval. That isn't easy because Timer 0 is only 8 bits.
>
> If you use a PIC with 2 16 bit counters life is good!
>
> Nevertheless, it will get you started.
>
> Richard
>


--- In piclist@picl..., "Alan Marconett" <KM6VV@a...> wrote:
>
> HI Richard,
>
> Yes, I see that now. Timer 0 could still run at a faster rate,
say 1 mS,
> and then only "act" every 20 mS. I'll have to give all that a
try.

These's always a yes but.... If you are using a 20 MHz crystal then
you start with 5 MHz and divide that by 256 (prescaler) and you are
clocking at 19.531 KHz. The timer will overflow in 13 mS. So, you
have to let it overflow twice and keep track to get to 20 mS.

Should work. Maybe I'll give it a try.

Richard

>
> Alan KM6VV
>
> > -----Original Message-----
> > From: piclist@picl... [mailto:piclist@picl...]
On Behalf
> > Of rtstofer
> > Sent: Monday, October 10, 2005 3:53 PM
> > To: piclist@picl...
> > Subject: [piclist] Re: Interfacing a PIC with Digital
Potentiometer?
> >
> > --- In piclist@picl..., "Alan Marconett" <KM6VV@a...>
wrote:
> > >
> > > HI Richard,
> > >
> > > Thanks for the contribution! I take it this code is for R/C
type
> > servos.
> > >
> > > Now all it needs is an RS-232 interface (USB?), and a simple
> > command
> > > language.
> > >
> > > Alan KM6VV
> >
> > Yes, R/C servos. However, it isn't very granular and there are
only
> > about 100 steps between 0 and 180 degrees - see the code listing.
> >
> > What probably needs to happen is to move the pulse on time to
Timer
> > 1 because it is 16 bits. Then Timer 0 could generate the 20 mS
> > timing interval. That isn't easy because Timer 0 is only 8 bits.
> >
> > If you use a PIC with 2 16 bit counters life is good!
> >
> > Nevertheless, it will get you started.
> >
> > Richard
> >
>




Hi Richard,

I'm using '877 PICs, with either a 4 Mhz resonator, or a 10 Mhz Xtal.

With a 10 Mhz Xtal I prescale 16, and use a counter reload value of -37 (that's
what the PIC .AS file says, I let the compiler figure it out) or 219, I get a
nice 250 uS INT rate. This works fine for multiplexing 4 LED 7 segment
displays. I then count interrupts to generate a 1/10 sec. "systems tick". I
check for a key detected (keys muxed with LED segment drive lines), and set task
flags depending on what keys were detected. I also call other tasks at this
1/10 sec rate, if they are an active task. All this gives me a nice multi-task
base to work from.

What I'd like to do (on an 18F4620 PIC) is run up to 4 stepper motors. The PIC
would have to ramp up/down, and generate a pre-calculated number of steps in
each axis. I currently (on my PC) watch the time until it's time to generate a
step, and then calculate the next step time. This method doesn't fit in too
well with the above kernel! I could just throw out the above kernel, and
simulate the 8254 of the PC, and "build" my 40-bit clock, running at a similar 5
Mhz rate. I haven't decided yet.

Alan KM6VV
rtstofer wrote:
> --- In piclist@picl..., "Alan Marconett" <KM6VV@a...> wrote:
>
>>HI Richard,
>>
>>Yes, I see that now. Timer 0 could still run at a faster rate,
>
> say 1 mS,
>
>>and then only "act" every 20 mS. I'll have to give all that a
>
> try.
>
> These's always a yes but.... If you are using a 20 MHz crystal then
> you start with 5 MHz and divide that by 256 (prescaler) and you are
> clocking at 19.531 KHz. The timer will overflow in 13 mS. So, you
> have to let it overflow twice and keep track to get to 20 mS.
>
> Should work. Maybe I'll give it a try.
>
> Richard >>Alan KM6VV
>>
>>
>>>-----Original Message-----
>>>From: piclist@picl... [mailto:piclist@picl...]
>
> On Behalf
>
>>>Of rtstofer
>>>Sent: Monday, October 10, 2005 3:53 PM
>>>To: piclist@picl...
>>>Subject: [piclist] Re: Interfacing a PIC with Digital
>
> Potentiometer?
>
>>>--- In piclist@picl..., "Alan Marconett" <KM6VV@a...>
>
> wrote:
>
>>>>HI Richard,
>>>>
>>>>Thanks for the contribution! I take it this code is for R/C
>
> type
>
>>>servos.
>>>
>>>>Now all it needs is an RS-232 interface (USB?), and a simple
>>>
>>>command
>>>
>>>>language.
>>>>
>>>>Alan KM6VV
>>>
>>>Yes, R/C servos. However, it isn't very granular and there are
>
> only
>
>>>about 100 steps between 0 and 180 degrees - see the code listing.
>>>
>>>What probably needs to happen is to move the pulse on time to
>
> Timer
>
>>>1 because it is 16 bits. Then Timer 0 could generate the 20 mS
>>>timing interval. That isn't easy because Timer 0 is only 8 bits.
>>>
>>>If you use a PIC with 2 16 bit counters life is good!
>>>
>>>Nevertheless, it will get you started.
>>>
>>>Richard
>>>
> >
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
> Yahoo! Groups Links



I did a similar task switcher a while back - mostly because it
cleaned up the code. Tasks are just neater - simple, stand alone
functions with limited interaction.

My time base was 1 mS so I switched a lot and each task had to be
guaranteed to be complete in 1 mS because this was not a preemptive
scheduler. But, 1 mS is a long time when you grind out 5,000,000
instructions (albeit simple ones) per second. You can execute about
5000 instructions in a time slice and that is a lot.

It worked quite well but there was the drawback of the fixed time
slice. Even when a task completed early, another task was not
dispatched. That would be a simple upgrade...

Richard

--- In piclist@picl..., KM6VV <KM6VV@a...> wrote:
>
> Hi Richard,
>
> I'm using '877 PICs, with either a 4 Mhz resonator, or a 10 Mhz
Xtal.
>
> With a 10 Mhz Xtal I prescale 16, and use a counter reload value
of -37 (that's
> what the PIC .AS file says, I let the compiler figure it out) or
219, I get a
> nice 250 uS INT rate. This works fine for multiplexing 4 LED 7
segment
> displays. I then count interrupts to generate a 1/10
sec. "systems tick". I
> check for a key detected (keys muxed with LED segment drive
lines), and set task
> flags depending on what keys were detected. I also call other
tasks at this
> 1/10 sec rate, if they are an active task. All this gives me a
nice multi-task
> base to work from.
>
> What I'd like to do (on an 18F4620 PIC) is run up to 4 stepper
motors. The PIC
> would have to ramp up/down, and generate a pre-calculated number
of steps in
> each axis. I currently (on my PC) watch the time until it's time
to generate a
> step, and then calculate the next step time. This method doesn't
fit in too
> well with the above kernel! I could just throw out the above
kernel, and
> simulate the 8254 of the PC, and "build" my 40-bit clock, running
at a similar 5
> Mhz rate. I haven't decided yet.
>
> Alan KM6VV >
> rtstofer wrote:
> > --- In piclist@picl..., "Alan Marconett" <KM6VV@a...>
wrote:
> >
> >>HI Richard,
> >>
> >>Yes, I see that now. Timer 0 could still run at a faster rate,
> >
> > say 1 mS,
> >
> >>and then only "act" every 20 mS. I'll have to give all that a
> >
> > try.
> >
> > These's always a yes but.... If you are using a 20 MHz crystal
then
> > you start with 5 MHz and divide that by 256 (prescaler) and you
are
> > clocking at 19.531 KHz. The timer will overflow in 13 mS. So,
you
> > have to let it overflow twice and keep track to get to 20 mS.
> >
> > Should work. Maybe I'll give it a try.
> >
> > Richard
> >
> >
> >>Alan KM6VV
> >>
> >>
> >>>-----Original Message-----
> >>>From: piclist@picl... [mailto:piclist@picl...]
> >
> > On Behalf
> >
> >>>Of rtstofer
> >>>Sent: Monday, October 10, 2005 3:53 PM
> >>>To: piclist@picl...
> >>>Subject: [piclist] Re: Interfacing a PIC with Digital
> >
> > Potentiometer?
> >
> >>>--- In piclist@picl..., "Alan Marconett" <KM6VV@a...>
> >
> > wrote:
> >
> >>>>HI Richard,
> >>>>
> >>>>Thanks for the contribution! I take it this code is for R/C
> >
> > type
> >
> >>>servos.
> >>>
> >>>>Now all it needs is an RS-232 interface (USB?), and a simple
> >>>
> >>>command
> >>>
> >>>>language.
> >>>>
> >>>>Alan KM6VV
> >>>
> >>>Yes, R/C servos. However, it isn't very granular and there are
> >
> > only
> >
> >>>about 100 steps between 0 and 180 degrees - see the code
listing.
> >>>
> >>>What probably needs to happen is to move the pulse on time to
> >
> > Timer
> >
> >>>1 because it is 16 bits. Then Timer 0 could generate the 20 mS
> >>>timing interval. That isn't easy because Timer 0 is only 8
bits.
> >>>
> >>>If you use a PIC with 2 16 bit counters life is good!
> >>>
> >>>Nevertheless, it will get you started.
> >>>
> >>>Richard
> >>>
> >>
> >
> >
> >
> >
> >
> >
> >
> > to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>




Hi Richard,

I've been examining my companies' PIC products, and we use these task
switchers quite a bit. I can see the utility, one product has 50 "mini
tasks" that take turns running off the main system tick. A/D reads on
multiple channels, trigger input reads, start/stop/monitoring of several
small pumps, display update tasks, etc.

There are drawbacks, but it still makes a simpler system then a fully
pre-emptive one.

I'm not sure how my stepper drivers will fare under a task switcher, 'tho.

Alan KM6VV

> -----Original Message-----
> From: piclist@picl... [mailto:piclist@picl...] On Behalf
> Of rtstofer
> Sent: Monday, October 10, 2005 9:16 PM
> To: piclist@picl...
> Subject: [piclist] R/C servos on PIC. WAS Re: Interfacing a PIC with
> Digital Potentiometer? > I did a similar task switcher a while back - mostly because it
> cleaned up the code. Tasks are just neater - simple, stand alone
> functions with limited interaction.
>
> My time base was 1 mS so I switched a lot and each task had to be
> guaranteed to be complete in 1 mS because this was not a preemptive
> scheduler. But, 1 mS is a long time when you grind out 5,000,000
> instructions (albeit simple ones) per second. You can execute about
> 5000 instructions in a time slice and that is a lot.
>
> It worked quite well but there was the drawback of the fixed time
> slice. Even when a task completed early, another task was not
> dispatched. That would be a simple upgrade...
>
> Richard