RC Receiver with PIC16F628A Very Glitchy


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62

    Question RC Receiver with PIC16F628A Very Glitchy

    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.

    Code:
    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
    There are 10 kinds of people. Those that know binary and those that do not.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    Any chance your steering servo is spiking your PIC ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    I would disconnect any motors for the testing, as David suggested.

    Ioannis

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    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
    Last edited by Acetronics2; - 15th October 2013 at 10:49.

  5. #5
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    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:
    Code:
            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.
    There are 10 kinds of people. Those that know binary and those that do not.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    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

    Code:
            IF (pulse >= 1850 µs) AND (pulse <= 1950 µs ) Then
    might be written

    Code:
            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 ...
    Code:
            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.

  7. #7
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62


    Did you find this post helpful? Yes | No

    Lightbulb Re: RC Receiver with PIC16F628A Very Glitchy

    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:

    Code:
    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

    Look for the on pulse > turn the light on

    Look for the off pulse > Turn the light off

    Here is my final code:

    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.
    There are 10 kinds of people. Those that know binary and those that do not.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    Why not put it in one check and save a cycle?

    Like this (untested):

    Code:
    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

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: RC Receiver with PIC16F628A Very Glitchy

    Quote Originally Posted by Ioannis View Post
    Why not put it in one check and save a cycle?

    Like this (untested):
    Ioannis
    or simpler to write ( may be same execution time ... )

    Code:
    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

  10. #10
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62


    Did you find this post helpful? Yes | No

    Wink Re: RC Receiver with PIC16F628A Very Glitchy

    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. Instead of receiving IR signals Its connected to the RC Receiver.

    Code:
    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
    Last edited by RFEFX; - 19th October 2013 at 21:51.
    There are 10 kinds of people. Those that know binary and those that do not.

Similar Threads

  1. pic16f628a issue
    By Bigandrewgold in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 2nd May 2012, 01:38
  2. PIC16F628A programming help
    By bentech4u in forum mel PIC BASIC
    Replies: 17
    Last Post: - 29th October 2008, 18:03
  3. Exploring Pic16F628a...
    By mbox in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 19th October 2008, 00:01
  4. Help Pic16f628a
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th August 2008, 00:22
  5. PIC16F628A defines
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd May 2007, 09:00

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts