Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.electronics.design > #478932
| From | Jan Panteltje <pNa0nStpealmtje@yahoo.com> |
|---|---|
| Newsgroups | sci.electronics.design |
| Subject | Re: How does a PLL work? |
| Date | 2017-09-26 08:02 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oqd1j1$v7p$1@gioia.aioe.org> (permalink) |
| References | (1 earlier) <Xbydneiym9W1m1TEnZ2dnUU7-a_NnZ2d@supernews.com> <47aisc1ndkeku35dlqm58t4v107lmrqh2e@4ax.com> <4qqdnRAvlJyJslTEnZ2dnUU7-WnNnZ2d@supernews.com> <fgayB.107942$fF2.47818@fx17.iad> <uKCdnQX2iviG71TEnZ2dnUU7-IGdnZ2d@supernews.com> |
On a sunny day (Mon, 25 Sep 2017 17:16:11 -0400) it happened Phil Hobbs
<pcdhSpamMeSenseless@electrooptical.net> wrote in
<uKCdnQX2iviG71TEnZ2dnUU7-IGdnZ2d@supernews.com>:
>Things sure are strange in the digital Cretaceous today!
>
>Cheers
>
>Phil Hobbs
I dunno how many of those PLL or control loops I designed an build over the years.
Many projects had one or more.
The OP was talking about software..
last one I did was a control system for altitude for my drone,
it drives a 32 position DAC that can be tri-stated to control the 'up / down' throttle.
It is just a few lines of asm, and I wrote it first time right.
In PIC 18 asm:
; if abs(requested_altitude_decimeters_h:requested_altitude_decimeters_l to current_altitude_decimeters_h:current_altitude_decimeters_l ) then goto main_read_sector
clrf REGA3
clrf REGA2
movff requested_altitude_decimeters_h, REGA1
movff requested_altitude_decimeters_l, REGA0
; REGA3:REGA0 = requested_altitude_decimeters_h:requested_altitude_decimeters_l
clrf REGB3
clrf REGB2
; signal to interrupt routine not to change these bytes one at the time
bsf WAIT_UPDATING_ALTITUDE_FLAG
movff current_altitude_decimeters_h, REGB1
movff current_altitude_decimeters_l, REGB0
bcf WAIT_UPDATING_ALTITUDE_FLAG
; REGB3:REGB0 = current_altitude_decimeters_h:current_altitude_decimeters_l
call subtract ; 32 bit subtract REGA - REGB -> REGA, return carry set if overflow, test bit 7 REGA3 for sign flag
; REGA3:REGA0 = requested_altitude_decimeters_h:requested_altitude_decimeters_l - current_altitude_decimeters_h:current_altitude_decimeters_l = correction factor
; this is positive if too low, then go up
; this is negative if too high, then go down
; remember sign bit in UP_FLAG
main_positive_alitude:
bsf UP_FLAG
btfsc REGA3, 7
bcf UP_FLAG
; if negative altitude things reverse, yes GPS gives negative altitude sometimes
btfss NEGATIVE_ALTITUDE_FLAG
bra main_positive_altitude
; how to handle GPS negative altitude, well what do you say, we go into hold tristate DAC out pin 19. and hold position sector
movlw D'16'
movwf VREFCON2
; DAC out pin 19 tristate, HOLD
bcf VREFCON1, DAC1OE
bra main_loop
main_positive_altitude:
; get ABS difference in REGA3:REGA0
call absa ; checks sign of REGA and convert negative to positive
; REGA3:REGA0 = abs(requested_altitude_decimeters_h:requested_altitude_decimeters_l - current_altitude_decimeters_h:current_altitude_decimeters_l)
movff REGA0, pa_error
; check if altitude error < 1.5 m
clrf REGB3
clrf REGB2
clrf REGB1
movlw D'15' ; 15 dm, 1.5 m
movwf REGB0
; REGB3:REGB0 = 15
call subtract ; 32 bit subtract REGA - REGB -> REGA, return carry set if overflow, test bit 7 REGA3 for sign flag
; REGA3:REGA0 = abs(requested_altitude_decimeters_h:requested_altitude_decimeters_l - current_altitude_decimeters_h:current_altitude_decimeters_l) - 15
; REGA is SIGNED!
; test if in proportional range
; this is negative for abs altitude error < 15
btfss REGA3, 7
bra altitude_error_out_of_proportional_range
; WAS TEST
; movff pa_error, ttemp
; call tx_crlf
; movfw ttemp
; call print_w_ascii_dec
; movlw ' '
; call tx_w
; movlw '1'
; btfss UP_FLAG
; movlw '0'
; call tx_w
; call tx_crlf
; movff ttemp, REGA0
; To create a proportional band
; if the error is smaller than 15
; if going up
; add the difference to the DAC + 16 (makes range 16 to 31)
; else
; sutract the difference from the DAC + 16 (makes range 16 to 1)
; else
; if going up
; set DAC to maximum (<= 31)
; else
; set DAC to minimum (>= 0)
; note now always DAC out pin 19 enabled!!, throttle on remote control can still override due to series resistors.
; test if up or down required
btfss UP_FLAG
bra proportional_down
; proportional up
; add REGA0 (for sure < 16) to DAC 16
movlw D'16'
addwf pa_error
movff pa_error, VREFCON2
; DAC to pin 19
bsf VREFCON1, DAC1OE
; do not wait till altitude reached, close enough, 1.6 meter either way, correct while moving to next sector / point
bra main_test_end_of_data
; bra main_loop
proportional_down:
; subract REGA0 (for sure < 16) from DAC 16
movff pa_error, WREG
sublw D'16'
movwf VREFCON2
; DAC to pin 19
bsf VREFCON1, DAC1OE
; do not wait till altitude reached, close enough, 1.6 meter either way, correct while moving to next sector / point
bra main_test_end_of_data
; bra main_loop
altitude_error_out_of_proportional_range:
; test if need to go up or down
; flashing red and green indicates trying to get to specified altitude
btg GREEN_LED
btfss UP_FLAG
bra max_down
; max up
; set DAC to DAC_MAX_RANGE
movlw DAC_MAX_RANGE
movwf VREFCON2
; DAC to pin 19
bsf VREFCON1, DAC1OE
; wait till altitude reached
bra main_loop
max_down:
; set DAC to DAC_MIN_RANGE
movlw DAC_MIN_RANGE
movwf VREFCON2
; DAC to pin 19
bsf VREFCON1, DAC1OE
; wait till altitude reached
bra main_loop
***********************************
You can see it flying an altitude controlled pattern here:
https://www.youtube.com/watch?v=bI_0mjwlvNw
The smaller you make the proportional band the higher the gain in fact.
The 'phase' is the altitude,
How many times per second the code is executed is also important.
It is a bit 'fingerspitzengefuhl'.
It is not hard,
I think Tim had a nice writeup here a while back about contol loops.
Now do not tell me it does not work ;-)
Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 10:07 +0200
Re: How does a PLL work? bill.sloman@ieee.org - 2017-09-25 01:25 -0700
Re: How does a PLL work? Rob <nomail@example.com> - 2017-09-25 08:27 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 12:38 +0200
Re: How does a PLL work? Rob <nomail@example.com> - 2017-09-25 11:31 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 13:53 +0200
Re: How does a PLL work? Steve Wilson <no@spam.com> - 2017-09-25 08:46 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 12:50 +0200
Re: How does a PLL work? Steve Wilson <no@spam.com> - 2017-09-25 12:28 +0000
Re: How does a PLL work? Jan Panteltje <pNa0nStpealmtje@yahoo.com> - 2017-09-25 15:43 +0000
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 09:35 -0400
Re: How does a PLL work? Steve Wilson <no@spam.com> - 2017-09-25 13:56 +0000
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 11:45 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 15:59 +0200
Re: How does a PLL work? Steve Wilson <no@spam.com> - 2017-09-25 14:15 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-25 16:38 +0200
Re: How does a PLL work? Steve Wilson <no@spam.com> - 2017-09-25 14:53 +0000
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 12:24 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 00:14 +0200
Re: How does a PLL work? pcdhobbs@gmail.com - 2017-09-25 16:16 -0700
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 09:44 +0200
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-26 13:55 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 23:13 +0200
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-28 00:28 +0200
Re: How does a PLL work? George Herold <gherold@teachspin.com> - 2017-09-27 17:39 -0700
Re: How does a PLL work? Jan Panteltje <pNaonStpealmtje@yahoo.com> - 2017-09-28 07:42 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-28 10:17 +0200
Re: How does a PLL work? Jan Panteltje <pNaonStpealmtje@yahoo.com> - 2017-09-28 12:52 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-28 16:21 +0200
Re: How does a PLL work? Jan Panteltje <pNaonStpealmtje@yahoo.com> - 2017-09-28 15:22 +0000
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-28 12:29 -0700
Re: How does a PLL work? whit3rd <whit3rd@gmail.com> - 2017-09-28 13:27 -0700
Re: How does a PLL work? kevin93 <kevin@whitedigs.com> - 2017-09-25 16:43 -0700
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 10:10 +0200
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 10:25 -0400
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 10:29 -0400
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 12:09 -0400
Re: How does a PLL work? John Larkin <jjlarkin@highlandtechnology.com> - 2017-09-25 09:12 -0700
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 12:30 -0400
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 12:36 -0400
Re: How does a PLL work? Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2017-09-25 21:18 +0300
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 15:14 -0400
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-25 12:39 -0700
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 16:07 -0400
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 17:28 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 00:34 +0200
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 19:52 -0400
Re: How does a PLL work? pcdhobbs@gmail.com - 2017-09-25 17:39 -0700
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 17:16 -0400
Re: How does a PLL work? Jan Panteltje <pNa0nStpealmtje@yahoo.com> - 2017-09-26 08:02 +0000
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 01:01 +0200
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 19:54 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 11:52 +0200
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 12:30 -0400
Re: How does a PLL work? Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-25 12:32 -0400
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 13:48 -0400
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 13:55 -0400
Re: How does a PLL work? John Larkin <jjlarkin@highland_snip_technology.com> - 2017-09-25 11:39 -0700
Re: How does a PLL work? John Larkin <jjlarkin@highland_snip_technology.com> - 2017-09-25 11:37 -0700
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 10:06 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-26 00:04 +0200
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-26 12:30 -0400
Re: How does a PLL work? Piotr Wyderski <peter.pan@neverland.mil> - 2017-09-27 00:01 +0200
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-25 12:00 -0700
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-25 15:39 -0400
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-25 12:45 -0700
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-26 11:19 -0700
Re: How does a PLL work? bitrex <bitrex@de.lete.earthlink.net> - 2017-09-26 15:09 -0400
Re: How does a PLL work? Jim Thompson <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> - 2017-09-26 12:48 -0700
Re: How does a PLL work? George Herold <gherold@teachspin.com> - 2017-09-26 12:54 -0700
csiph-web