PDA

View Full Version : RC Receiver with PIC16F628A Very Glitchy



RFEFX
- 14th October 2013, 22:47
I read this post http://www.picbasic.co.uk/forum/showthread.php?t=12007 and though the code did help somewhat I am having a lot of glitches when steering the car. All I am doing is turning on lights with the 3rd channel of my RC system.


Here is my setup.

Airtronics MX-3S PLL synthesized 3 channel 75Mhz.
PIC16F628A running at 20mhz.

Here is the code I am running.



Define OSC 20
CMCON = 7

'-------------------------------------------------------------------------------

signal VAR PortA.0
pulse VAR BYTE

'-------------------------------------------------------------------------------

main:
PulsIn signal, 1, pulse ' reads signal from receiver

IF (pulse >= 150) AND (pulse <= 200) Then
High PortA.1 ' turns LED off
Else
Low PortA.1 ' turns LED on
EndIF

GoTo main

Archangel
- 15th October 2013, 01:42
Any chance your steering servo is spiking your PIC ?

Ioannis
- 15th October 2013, 08:55
I would disconnect any motors for the testing, as David suggested.

Ioannis

Acetronics2
- 15th October 2013, 09:44
The truth is in your electrical scheme ...

especially around the use of the " magic " .1 or .22µF ceramic capacitor to be located just between the Vdd and Vss pins ( yes, SMD 1206 size is THE thing ! )

also place a medium value resistor ( 1k to 10k ) in series with your signal input ...
a 100k resistor between A.0 and Vss is also to consider ...

last things ... is your LED connected to the Rx supply ??? ...
and also how much does it draw ???
and overall ... what kind of supply do you use ?

Alain

RFEFX
- 15th October 2013, 17:17
I willl Try your suggestions with the Cap and Resistors.

Ultimately I think the Pulsin timing is wrong and still trying to figure what the correct values should be, or to use pulsin at all.

Using my Saleag logic analyzer I captured a 50M sample and toggled channel 3 to capture the pulse width.

With the switch High the width was 1900µs in the off state it was 1500µs. i can upload the captures later if need be.

So i then looked at 5 different High widths and they ranged from 1895µs to 1910µs.

The confusing part for me is with a 20Mhz clock this gives me 2µs resolution. What does that mean?

I then plugged in the values without the steering servo plugged in:


IF (pulse >= 185) AND (pulse <= 195) Then


I get no response.

Alain,

The board I designed uses the 5v from the ESC.

I am not driving an LED directly, I am driving a ULN2003 Darlington array which closes the ground for the LEDs but powered from the receiver as well. ULN2003 is rated at 500mA.

The receiver is powered from the ESC and thus plugged into the 7.2V Battery pack for the car.

Should i have separate power supplies?

Thanks,
Gary D.

Acetronics2
- 15th October 2013, 19:13
my fault - I didn't pay attention to that, only glitches problem - ... it's obvious you do not get any response.

your pulse is > 1890µs ...

@ 20 Mhz: 2µs per count



IF (pulse >= 1850 µs) AND (pulse <= 1950 µs ) Then


might be written



IF (pulse >= 1850 /2) AND (pulse <= 1950 /2) Then


where 2 is your resolution in µS ( or also 40 / Osc freq. )

second point ... do not set the limits too close to your nominal values ... ( always a +/- 1 count jitter for " pulsin " !!! ) and also think to temp and voltage effects on Tx pulse length ...

so ...


IF (pulse >= 925) AND (pulse <= 975 ) Then ...


will give you fine practical results for nominal values from 1855 to 1945µs.

one more thing to do is to set the PWRTE fuse in the config : the processor will reset if your supply goes too low due to the ESC and the motor ( surprises should arise ! even with a " BEC " circuit ... )

also use a nice Electrolytic ( say 100+ µF low ESR ) or tantalum capacitor at the input on your board.

RFEFX
- 16th October 2013, 18:00
Ok, I got the code working the way i wanted but had to make some alterations.

First of all - I'm definitely going to have to have a separate power supply for my board as it keeps resetting at full throttle. Even with PWRTE set.

I had to change:


Width var byte

to

Width var word

Since the 2µs resolution puts it well beyond 255.

And after a few minutes of just looking at hundreds if not thousands of pulses on my Logic analyzer it hit me :eek:

Look for the on pulse > turn the light on

Look for the off pulse > Turn the light off

Here is my final code:



define osc 20 '20Mhz oscillator

CMCON = 7 'Turn off Comparators

Width var word '@ 20Mhz channel 3 is 1900µs in the on state. with 2µs resolution thats a value of 950. byte only holds a value of 255.

Main:
Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width."
if (Width >= 925 ) and ( Width <= 975) then '1900µs is on state. 1900µs /2 = 950
high porta.1
else
goto Check_pulse
endif
goto Check_pulse

Check_pulse:
Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width."
if (Width >= 475 ) and ( Width <= 525) then '1000µs is off state. 1000µs /2 = 500
low porta.1 'If channel 3 is indeed in the off state turn the LED off.
else
goto Main
endif
goto Main



Thanks for all of the help.

Ioannis
- 16th October 2013, 19:38
Why not put it in one check and save a cycle?

Like this (untested):



Main:
Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width."
if (Width >= 925 ) and ( Width <= 975) then '1900µs is on state. 1900µs /2 = 950
high porta.1
else
if (Width >= 475 ) and ( Width <= 525) then '1000µs is off state. 1000µs /2 = 500
low porta.1 'If channel 3 is indeed in the off state turn the LED off.
endif
endif
goto Main


Ioannis

Acetronics2
- 16th October 2013, 19:55
Why not put it in one check and save a cycle?

Like this (untested):
Ioannis

or simpler to write ( may be same execution time ... )




Main:
While 1
Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width."
if (Width >= 925 ) and ( Width <= 975) then high porta.1 '1900µs is on state. 1900µs /2 = 950

if (Width >= 475 ) and ( Width <= 525) then low porta.1 '1000µs is off state. 1000µs /2 = 500
'If channel 3 is indeed in the off state turn the LED off.

Wend

Alain

RFEFX
- 19th October 2013, 20:47
Im sorry guys this final code is the deal breaker. Even simpler than I previously thought it was going to be.

Turns lights on and off with a quickness. Ill post my RC Car here when i get it finished. Thanks again.

I am using the same board I designed for this post: Home Theater IR remote light switch. (http://www.picbasic.co.uk/forum/showthread.php?t=15712&highlight=home+theater) Instead of receiving IR signals Its connected to the RC Receiver.



define osc 20

CMCON = 7

Width var word


Main:
while 1
Pulsin Porta.0, 1, Width 'Wait for a high pulse store the pulse width in the variable "Width."
if (Width > 900) then high porta.1 '1900µs is on state. 1900µs /2 = 950

if (Width < 550) then low porta.1 '1000µs is off state. 1000µs /2 = 500

wend