PDA

View Full Version : Question What signal does Rx send to servo?


abenn
Oct 10, 2007, 03:13 AM
I've constructed a simple circuit using a PICAXE microprocessor to flash strobe lights and to switch landing lights on/off. During each strobe flash cycle the on/off part of the circuit checks if the servo pulses from the Rx are above or below 150uS, and acts accordingly :cool:

But if the transmitter is not switched on my circuit behaves very erratically, so I guess that it's not receiving pulses from the Rx (otherwise it would measure them and act depending on their length) and is hanging at the "pulsin" check looking for pulses.

So, in a no-signal situation, what does the Rx send to the servos, please? Is it simply an absence of any signal?

slipstick
Oct 10, 2007, 03:57 AM
Receivers don't generally construct a signal they just decode what the Tx sends. No Tx signal = no output pulses.

One way to cater for this is a maximum wait time for a pulse to be found, around 25ms should do it. I don't know how easy that is to do with a PICAXE, never used one.

Steve

Peter Seddon
Oct 10, 2007, 04:34 AM
The standard pulse train from a receiver servo channel is a 1.5mS pulse every 20mS. Variation of the stick position will vary the pulse over the range 0.5 to 2mS.

No transmitter signal will give a very erratic output triggered by noise, unless you are using PCM or have a receiver with failsafe or DSP in which case you should still get a good pulse output.

regards Peter

mem
Oct 10, 2007, 05:17 AM
The delay between successive pulses from a particular channel varies with different transmitters and can also be dependent on the state of the other channels. The differences may not really matter much in your application, but have you considered using a timing delay in your code. A simple loop in your code should be more consistent with other radio systems you may use in the future.

The easiest implementation is to just ignore everything while in the delay loop, the pulses you will miss won’t matter in your application.

I did a similar project with a PIC and found a strobe pattern of 400ms on, 200ms off, 400ms on, 1000 ms off looked good. I used a 200ms timer and my program incremented a counter and serviced the lights based on the count modulo 20 and the camera based on the monitored channel. The 200ms latency was unnoticed.

I hope you have as much fun with your project as I did with mine.

Michael

abenn
Oct 10, 2007, 06:53 AM
Receivers don't generally construct a signal they just decode what the Tx sends. No Tx signal = no output pulses.

One way to cater for this is a maximum wait time for a pulse to be found, around 25ms should do it. I don't know how easy that is to do with a PICAXE, never used one.

Steve
Thanks. I'm a newbie to PICAXE, so I'll have to re-read the manual to figure out how to configure the wait time or, alternatively, add a routine to test for no output :)

The delay between successive pulses from a particular channel varies with different transmitters and can also be dependent on the state of the other channels. The differences may not really matter much in your application, but have you considered using a timing delay in your code. A simple loop in your code should be more consistent with other radio systems you may use in the future.

The easiest implementation is to just ignore everything while in the delay loop, the pulses you will miss won’t matter in your application.

I did a similar project with a PIC and found a strobe pattern of 400ms on, 200ms off, 400ms on, 1000 ms off looked good. I used a 200ms timer and my program incremented a counter and serviced the lights based on the count modulo 20 and the camera based on the monitored channel. The 200ms latency was unnoticed.

I hope you have as much fun with your project as I did with mine.

Michael
I'm running a loop, which increments a couple of variables (one for each strobe led) and switches the leds on and off when the variables reach certain values, and the variables themselves then revert to 0 when they reach another value, which is slightly different for each of the leds so that they gradually go out of synch :cool: The time the chip takes to complete a loop is dependent on the number of lines of code, so getting a good-looking strobe flash is a matter of changing the variables by trial-and-error -- I don't know what the timings are in ms :(

Within the loop is the check for an input to switch the landing lights on/off. This works fine while the receiver is receiving a signal from my transmitter, but the whole loop just hangs (so no strobes) if there's no signal. Not a big deal, I suppose, because it works when there is a signal, but I'd just like the strobes to flash properly as soon as I power up the module irrespective of whether it's getting a signal for the landing lights.

The standard pulse train from a receiver servo channel is a 1.5mS pulse every 20mS. Variation of the stick position will vary the pulse over the range 0.5 to 2mS.

No transmitter signal will give a very erratic output triggered by noise, unless you are using PCM or have a receiver with failsafe or DSP in which case you should still get a good pulse output.

regards Peter
The PICAXE command I'm using (pulsin), if I understand the manual correctly, counts how many pulses in a 10ms interval. By setting the trigger value to 150 it's switching my lights on and off at about half-throttle value, as I expect -- I was testing it on the throttle channel, rather than an auxiliary on/off channel, so I could see at which point it triggered :)

mem
Oct 10, 2007, 08:38 AM
Within the loop is the check for an input to switch the landing lights on/off. This works fine while the receiver is receiving a signal from my transmitter, but the whole loop just hangs (so no strobes) if there's no signal. Not a big deal, I suppose, because it works when there is a signal, but I'd just like the strobes to flash properly as soon as I power up the module irrespective of whether it's getting a signal for the landing lights.Can you use an interrupt to detect transitions in the channel you want to monitor. If there is a timer you can start and stop when the channels goes high and low , the timer count can be polled at the end of each delay loop to see if you need to turn on or off the lights.

If you don't want to use interrupts, you could just continuously poll the channel state for a little over 20 ms and if you don’t get a transition within this time then assume the tx is off but carry on with your routine. If it bothers you that this will throw the timing off a little when you do get a signal, you could have a flag so you only poll for channel transition every so many loops, say a few times a second.

Gary Warner
Oct 10, 2007, 11:08 AM
...Variation of the stick position will vary the pulse over the range 0.5 to 2mS.

That's 1ms to 2ms stick range.

heli_madken
Oct 10, 2007, 11:40 AM
I had a similar problem, I just added a goto to stop running the main body of code at zero stick something like -

pulsin 3,1,b0 (Where '3' = the port number you are reading)

do_loop
if b0 < 120 then goto zerostick

'your code here'

goto do_loop

zerostick:

'insert new code here to flash lights without reading any input values'

That way no pulses are sent to output ports until you raise throttle, the 120 value I found by experimentation, in the mean time you can use random values to flash the lights

Hope this helps, Ken

shanghai_fool
Oct 10, 2007, 12:26 PM
You need to put the pulsin inside the do loop or it will never exit.

heli_madken
Oct 10, 2007, 12:55 PM
Yep sorry you are right copied it wrong from my code -

do_loop

pulsin 3,1,b0 (Where '3' = the port number you are reading)

if b0 < 120 then goto zerostick

'your code here'

goto do_loop

zerostick

maxvtol
Oct 10, 2007, 02:32 PM
Abenn

The pulsin command does hang if there is no pulse (as metioned earlier, there should be no pulse), but it does timeout after .65 seconds if you are using the 4mhz resonator. It returns 0 if it times out, so maybe you could check for pulsin = 0 in your code to leave all the lights off.

abenn
Oct 10, 2007, 03:04 PM
Abenn

The pulsin command does hang if there is no pulse (as metioned earlier, there should be no pulse), but it does timeout after .65 seconds if you are using the 4mhz resonator. It returns 0 if it times out, so maybe you could check for pulsin = 0 in your code to leave all the lights off.
I tried with my trigger value at 0, instead of 150, but it still just seems to hang :( That should have left the landing lights off, but the strobes still double-flashing at about once per second. But if the receiver isn't receiving a signal from my transmitter, or if the lights circuit is disconnected from the receiver (and powered independently), the strobes slow down to about one long glow (not a flash) every half minute or so because their timing is in the same loop as the pulsin check.

heli_madken: That's basically the same code as I'm using, except I used >150 instead of <120. As mentioned above, I tried a test with >0, but the PICAXE pulsin command doesn't seem to treat no-signal the same as zero pulse :(

maxvtol
Oct 10, 2007, 03:30 PM
I'm no expert with the PICAXE, perhaps there's something strange going on if you're using a byte variable and it can't handle beyond 255, try a variable that can handle 16 or 32 bit.

If the code isn't too long, try posting that here.

If we can't figure it out, I hear the PICAXE forums are pretty good.

abenn
Oct 10, 2007, 03:50 PM
I'm no expert with the PICAXE, perhaps there's something strange going on if you're using a byte variable and it can't handle beyond 255, try a variable that can handle 16 or 32 bit.

If the code isn't too long, try posting that here.

If we can't figure it out, I hear the PICAXE forums are pretty good.
Thanks, I'm trying to sign-up to the official PICAXE forum, but it's been two days now and they still haven't authorised my account :(

The code was generated automatically from a flowchart, and it's quite simple.

main:
let b2= 0
let b0= 0
label_01: if b2= 0 or b2= 4 then label_09
label_02: if b0= 0 or b0= 4 then label_11
label_03: if b2= 1 or b2= 5 then label_10
label_04: if b0= 1 or b0= 5 then label_12

label_05: let b2=b2+ 1
let b0=b0+ 1
if b0> 40 then label_13
label_06: if b2> 41 then label_08
label_07: pause 0
goto label_14

label_08: let b2= 0
goto label_07

label_09: high 2
goto label_02

label_10: low 2
goto label_04

label_11: high 0
goto label_03

label_12: low 0
goto label_05

label_13: let b0= 0
goto label_06

label_14: pulsin 3,1,b1
if b1> 150 then label_15
low 4
goto label_01

label_15: high 4
goto label_01

From label_01 to label_07 is the part of the loop that increments the variables to create the double-flashes of the strobes. Label_14 and label_15 check for a pulse input to switch the landing lights (channel 4) before returning to the beginning of the loop. The interval between the strobe flashes is determined by the values I've specified for b0 and b2, and by the time the chip takes to complete one cycle of the loop :(

maxvtol
Oct 10, 2007, 04:27 PM
Try using w1 for your pulse variable instead of b1. I suspect after the byte variables get to 255, it overflows and just returns 255.

w1 will let the numbers get up to 65335 which is where it times out. Then it should return 0.

abenn
Oct 11, 2007, 03:19 AM
OK, I've just tried using w1 and the result seems the same. I hadn't realised the significance of what name you give to the variable. At first it seemed to work, though the complete cycle took 28 seconds (which is about right if it takes 0.65 seconds before it time-outs at the pulsin step, and has to loop 41 times before the next strobe flash). But after two cycles one of the strobe lights stayed on permanently :eek:

As I said earlier, it works fine when the transmitter is switched on, so maybe I'll have to leave it like this. After all, my Tx should be on all the time the Rx is :)

Thanks for all the input.

maxvtol
Oct 11, 2007, 06:47 AM
After all, my Tx should be on all the time the Rx is :)


That's definitely a practice you want to remember. Ask me how I know. :o

abenn
Oct 11, 2007, 08:42 AM
That's definitely a practice you want to remember. Ask me how I know. :o
I agree, and that's what I normally do. It just bugs me that the circuit should be able to be made to continue looping (and, thus, giving strobe flashes) even when there's no signal going to pin 3.

However, during my swim this morning ( :D ) I decided to take the simple way out: I'll use two PICAXE chips -- one for the strobe circuit and another for the landing light switch :)

abenn
Oct 14, 2007, 07:07 AM
I've been on the official PICAXE forum a couple of days now, and the answer seems to be that there's a bug in the pulsin command that causes it to either timeout and/or hang in the absence of a signal from the Rx -- it doesn't interpret no-signal the same as a signal with a zero pulse-count :(

Malc C
Oct 14, 2007, 06:00 PM
No expert with PICAXE, but have dabbled a bit with microchip's PIC micros. The problem you have is that you need to scan the input for a pulse, time the pulse, and in between pulse one or more pins to give the strobe effect. Now using higher level languages such as basic etc it's sometimes harder to acheive than using pure assembly.

My first bit of assemble was to get three leds to double flash in a sequence. This was a working execise and most of the code was demonstrated to me, and I confess that at the time I had no idea how it worked ! The next project the guy helped me with was a simple RC switch that would detect the pulse width and toggle an output. I then managed to understand enough of the code to work out how to incorporate the two so that I could switch on / off the flashing strobe lights. The code for this is shown below (for a 12F675 PIC)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
; 12F675 Navigation Lights ;
; ;
; Tripple flash, three sequential outputs ;
; Control from a spare switched channel on TX ;
; ;
; M. Crabbe ;
; April 8th 2006 ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;

list p=12F675
#include "p12f675.inc"

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

CURRENT equ 0x20
PREVIOUS equ 0x21
DIFF equ 0x22

del_lo equ 0x24
del_hi equ 0x25

org 0x00
nop
goto init

org 0x04
return

init
banksel 0x80 ;select upper register bank
clrf ANSEL ;make all I/O ports digital
movlw 0x0B
movwf TRISIO ;make GP2,GP4 and GP5 outputs
movlw 0xd3
movwf OPTION_REG
banksel 0x00 ;select lower register bank
clrf GPIO ;initialise all outputs
clrf CURRENT
clrf PREVIOUS
clrf DIFF
clrf del_lo ;initialise delay counter low byte
clrf del_hi ;initialise delay counter high byte


test
movf GPIO,w
movwf CURRENT
xorwf PREVIOUS,w
movwf DIFF
movf CURRENT,w
movwf PREVIOUS
btfss DIFF,3
goto test
btfss CURRENT,3
goto stop
start clrf TMR0
goto test
stop movf TMR0,w
sublw 59 ; detects the threshold between low 1ms and 2ms PW
btfss STATUS,C
goto lightson
lightsoff
bcf GPIO,4
bcf GPIO,2
bcf GPIO,5
goto test
lightson

bsf GPIO,0
bsf GPIO,1
bsf GPIO,2 ;set output GP2 high
movlw 0x45 ;value after the x sets the speed of the double pulse Lower = faster
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,2 ;set output GP2 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,2 ;set output GP2 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,2 ;set output GP2 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,2 ;set output GP2 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,2 ;set output GP2 low
movlw 0xff ;the value FF sets a longer OFF period before the delay call
movwf del_hi
call delay ;call the delay subroutine


bsf GPIO,4 ;set output GP4 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,4 ;set output GP4 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,4 ;set output GP4 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,4 ;set output GP4 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,4 ;set output GP4 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,4 ;set output GP4 low
movlw 0xff
movwf del_hi
call delay ;call the delay subroutine


bsf GPIO,5 ;set output GP5 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,5 ;set output GP5 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,5 ;set output GP5 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,5 ;set output GP5 low
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bsf GPIO,5 ;set output GP5 high
movlw 0x45
movwf del_hi
call delay ;call the delay subroutine

bcf GPIO,5 ;set output GP5 low
movlw 0xFF
movwf del_hi
call delay ;call the delay subroutine

goto test


delay
decfsz del_lo,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del_hi,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called
end


There is a pause sometimes between when you activate the switch and the leds stop flashing depending where in the flash sequence loop it is activated.

Hope this helps

abenn
Oct 15, 2007, 03:53 AM
Thanks Malc. Interesting, but no help in this situation because the PICAXE doesn't (so far as I know) accept assembler code. Also, the 08 chip I'm using only takes 128 bytes of code :)

Anyway, I've now got a Basic programme that does exactly what I want (3 strobes each flashing in a slightly different cycle-time so they look random, plus an on/off landing light) with about 7 bytes to spare.

The problem I was trying to solve, and have now accepted is insoluble within the constraints of the chip and the language, is that the command that measures the pules in the receiver signal (pulsin) causes a problem when there's no signal. This is not a problem so long as I have the trannie switched on while the receiver is on -- which is normal good practice anyway :cool: