sample servo signal

A catchall for PSoC3 discussions not captured by the other forums.

Moderator: ericb

sample servo signal

Postby navyman » Wed Oct 17, 2012 1:31 pm

Hi
I'm new with psoc and need help on my project.
I can do it with psoc 3 or 1.
I have a cy8ckit-001 for my development.
I would like to sample a servo signal (pulse width rise to fall) and measure it.
I need to give a value of 8 bit for the each measuring.
the period can be between 1ms to 2ms so 1ms will be 0 degree and 2ms will be 180 degree (1.5ms will be 90degree) - it is linear.
can you recommend me how to do it? or do you have a sample project?
By the way the 8 bit value will be transmitted on RS232 line using the UART.
navyman
Newbie
Newbie
 
Posts: 3
Joined: Wed Oct 17, 2012 1:18 pm

Re: sample servo signal

Postby bobmarlowe » Thu Oct 18, 2012 12:26 am

I'd suggest you to do it with a PSoC3 because the debugging facilities for your program are much better than for a PSoC1 (except when you have access to an ICE-Cube).

Use a 16-bit counter-component and feed it with a fixed (precise) frequency so that 4ms will let it overflow.
Use your servo-signal as enable-signal
Use the negated servo-signal (with a NOT-gate) as input to an ISR-component (edge) to trigger when a measure is ready.
On interrupt read the state of the counter to clear interrupt and read the counter-value. Reset the counter to zero
Calculate (from input frequency and counter value the time.

For interrupts: Have a look at Help->Documentation->System Reference at CY_ISR and CY_ISR_PROTO and use ISR_StartEx().

UART is easy, have a look at the datasheet.

Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: sample servo signal

Postby navyman » Thu Oct 18, 2012 12:44 am

thanks Bob,

why do i NEED 16Bit counter with 4 ms overflow?
isnt it easier to use 1ms over flow (or alittle bit more) and use 8 bit counter? this way any result I will get will be the one that I send (8bit word) through the UART and no need for extra calculation. am I right or I missing somthing?

thanks
Guy
navyman
Newbie
Newbie
 
Posts: 3
Joined: Wed Oct 17, 2012 1:18 pm

Re: sample servo signal

Postby danadak » Thu Oct 18, 2012 2:50 am

The counter width and its clock rate control time measurement resolution. Counter
depth controls total measurement range, for a given clock rate.

You can use an 8 b bit counter.

Sending 1 or 2 bytes thru UART really not a heavy lift, either easy to do. And decode.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: sample servo signal

Postby bobmarlowe » Thu Oct 18, 2012 3:41 am

To retrieve the full possible range of the servo (and so I understood the exercise)
0 = 1ms to 255 = 2ms an 8-bit counter will not be sufficient to measure the high-time of the signal, this I recommended using a 16-bit counter and do some scaling-calculations at the end (before sending to UART)

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: sample servo signal

Postby danadak » Thu Oct 18, 2012 4:04 am

The servo range is 1 mS ( 1 mS to 2 mS). If clock to servo is set to
1 mS / 256 =~ 3.9 uS = ~ 256 Khz then your measurement resolution
is 3.9 uS , ~ 4 uS.

So if you feed the servo pulse to the counter enable, and clock is running
at 256 Khz, then the counter will handle the measurement with a resolution
of ~ 4 uS. Simply put you are making a period measurement, attached some
docs on that.

You might want to set clock up for a FS of 4 mS ( 1 mS to 4 mS) to prevent overflow,
as Bob mentioned previously. Then period width to measure = 3 mS, clock = 11.7 uS,
85.3 Khz. Then resolution = 11.7 uS =~ 12 uS.

Setup counter as up counter, UDB, 8 bit, falling edge capture, hardware enable,
rload on reset, interrupt on capture, run mode one shot. That should do it.
When capture ISR fires, read capture reg, and issue a reset. Tie enable and capture
to Servo pulse in.

Regards, Dana.

PS : Docs too big, I can send them to your email address if you desire.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: sample servo signal

Postby danadak » Fri Oct 19, 2012 11:51 am

Here is a project you can run on 030 DVK. Creater 2.1

Take a look at notes page tab next to top schematic page tab for explanation.

Regards, Dana.
Attachments
Design11.cywrk.Archive01.zip
(1.65 MiB) Downloaded 89 times
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: sample servo signal

Postby navyman » Fri Oct 19, 2012 2:19 pm

thanks Dana
you help alot.
just one question:
if I need up to 16 like this working in parallel do you think it is possible?

if not what will be the maximum number of Servo inputes that I can do in parallel in one Psoc?

thanks again,
Guy
navyman
Newbie
Newbie
 
Posts: 3
Joined: Wed Oct 17, 2012 1:18 pm

Re: sample servo signal

Postby bobmarlowe » Sat Oct 20, 2012 12:44 am

A PSoC 3 or 5 has got 24 UDBs When you look at the generated -map-file in Creator "Results"-tab you'll find within a listing that shows the resource usage.
Since you'll need as I understood
1 input pin
1 UDB for 8-bit PWM
1 UART (2 pins)

You'll have the chance to integrate about 20 channels into one PSoC.

The interrupt rate will go up to about (Channels * 50Hz) which can be handled if you do not have much calculations in your ISRs.


Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: sample servo signal

Postby danadak » Sat Oct 20, 2012 3:26 am

if I need up to 16 like this working in parallel do you think it is possible?


Are they all being driven by same signal, eg all positioned same, or are they independent ?

As far as interrupt capacity there is one interrupt in it that performs

Code: Select all
   pcntrisrflg = 1;      // Indicate new period measurment val ready
   PerdCntr_ReadStatusRegister( );


You might want to move the status reg read into main(), that way ISR only sets the flag
and returns. Otherwise its another stack push to do f() call and that creates ISR latency.

As far as how many servos can be handled, two issues, HW resources, Routing, and available
MIPS for all the ISR activity and what ever else you have to do in code. For case where all
servos independent. So I do not have a simple answer. Start by setting up 4, toggle an activity
pin somewhere in code to get a handle on how much code MIPS is being consumed.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: sample servo signal

Postby jomalogil » Sun Oct 28, 2012 12:42 pm

FYI. My hexapod has:
- 18 servos (18 PWM 8 bit)
- 1 full duplex uart
- 2 PWM 8 bit (extra)
- 2 Timer 8bit
- 1 SPI 10 bit
All servos work at same time. It's possible to control via UART (232 or 485) and PS2 keyboard
mapping result:

Resource Type : Used : Free : Max : % Used
============================================================
Digital domain clock dividers : 4 : 4 : 8 : 50.00%
Analog domain clock dividers : 0 : 4 : 4 : 0.00%
Pins : 35 : 37 : 72 : 48.61%
Macrocells : 68 : 124 : 192 : 35.42%
Unique Pterms : 114 : 270 : 384 : 29.69%
Total Pterms : 126 : : :
Datapath Cells : 16 : 8 : 24 : 66.67%
Status Cells : 5 : 19 : 24 : 20.83%
Control/Count7 Cells : 13 : 11 : 24 : 54.17%
Sync Cells : 8 : 68 : 76 : 10.53%
Drqs : 0 : 24 : 24 : 0.00%
Interrupts : 5 : 27 : 32 : 15.63%
DSM Fixed Blocks : 0 : 1 : 1 : 0.00%
VIDAC Fixed Blocks : 0 : 4 : 4 : 0.00%
SC Fixed Blocks : 0 : 4 : 4 : 0.00%
Comparator Fixed Blocks : 0 : 4 : 4 : 0.00%
Opamp Fixed Blocks : 0 : 4 : 4 : 0.00%
CapSense Buffers : 0 : 2 : 2 : 0.00%
CAN Fixed Blocks : 0 : 1 : 1 : 0.00%
Decimator Fixed Blocks : 0 : 1 : 1 : 0.00%
I2C Fixed Blocks : 0 : 1 : 1 : 0.00%
Timer Fixed Blocks : 2 : 2 : 4 : 50.00%
DFB Fixed Blocks : 0 : 1 : 1 : 0.00%
USB Fixed Blocks : 0 : 1 : 1 : 0.00%
LCD Fixed Blocks : 0 : 1 : 1 : 0.00%
EMIF Fixed Blocks : 0 : 1 : 1 : 0.00%
LPF Fixed Blocks : 0 : 2 : 2 : 0.00%
Gil
Saludos-Best regards
jomalogil
Cheese Wheel
Cheese Wheel
 
Posts: 140
Joined: Thu Nov 24, 2005 6:36 am
Location: Madrid - Spain


Return to “%s” PSoC3 General

Who is online

Users browsing this forum: No registered users and 1 guest

cron