• AVR Freaks

Hot!Guidance : R/C Pulse Width Measurement : PIC12F675 or 683

Author
daba
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2012/10/15 13:24:07
  • Location: UK
  • Status: offline
2020/10/18 01:27:43 (permalink)
0

Guidance : R/C Pulse Width Measurement : PIC12F675 or 683

MPLAB IDE 8.92
MPASMWIN.exe v5.51
mplink.exe v4.49
mplib.exe v4.49
 
Hi guys, looking for project guidance ; I have a need to measure the pulse widths of two potentially adjacent R/C servo signals from the receiver.
 
Background : I had a solution for the 675, which used a 200uS interrupt to count how many times each channel was "high", and used the respective counts to determine the positions of the control inputs. It suffered "jitter", so was only suited for "ON/OFF" R/C channels, such as GEAR and FLAPS, i.e. the channel was either hard ON or hard OFF.

Now I need better measurement, to determine three positions : minimum, mid-position, and maximum. R/C servo systems are not universal. Some texts say the timing of each channel is 0.5 to 2.5 mS, others say 1.0 to 2.0 mS, so I'm thinking that deviation from the mid-point (always 1.5 mS, give or take a bit) is the best way to go.

Moving On : I won't be able to use the CCP module on the 683, because I will eventually be using GPIO2 in PWM mode.  I think the best way forward is to use GPIO interrupt on the two inputs. I am thinking of < 1.2mS = minimum, 1.3 to 1.7mS = mid-point, and > 1.8 mS = maximum and at that point, give up, and deem it to be at maximum, releasing the interrupt for the next channel's transition from low to high. EDIT : I realise now that I will have to alternate the input pins if I do this, as the interrupt will be generated by that, now ignored, pin going low.  That will give me latching "hysteresis".  The two input pins do not have to be both "in use", so both are "pulled-up".  Response speed will not be an issue, the application is R/C model lighting.
 
Has anyone done anything similar ? 
Is there a better way ?
Has anyone got any comments on my idea before I get coding ?
Recommendation of which Timer module would be best for the idea above ?
post edited by daba - 2020/10/18 01:51:43
#1

16 Replies Related Threads

    Mysil
    Super Member
    • Total Posts : 3785
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/18 03:37:40 (permalink)
    0
    Hi,
    I think PIC12F675 and PIC12F683 are both quite antique devce types,
    and awkward for experimentation and development.
    They cannot be debugged in hardware (without a debug adapter), and have small program and data memory.
     
    There have been a lot of development in the meantime.
    Newer device types can be debugged in hardware, even som of the small PIC12F in 8 pin package.
    PIC12F1822 or PIC12F1840 can be programmed and debugged in MPLAB 8.92,
    but will need PICkit 3 programmer tool for this.
     
    For learning and development, I would suggest PIC16F1824, PIC16F1825 or PIC16F1826 in 14 pin package,
    or PIC16F1828 or PIC16F1829 in 20 pin package.
    These microcontrollers have internal oscillator with PLL, and are able to run with clock frequency up to 32 MHz.
    When you understand what you do, and have code that work, condense it into a 8-pin device.
     
    All these devices are pin compatible, 8 pins at end of the package, with PIC12F683.
     
    Jitter may be reduced by averaging or hysteresis in software.
     
    The latest development in this line is PIC16F18323,
    but then you will get PPS pin remapping, which may make code setup a little more complicated,
    and will have to learn to use MPLAB X for development.
     
        Mysil
    #2
    Mysil
    Super Member
    • Total Posts : 3785
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/18 04:06:25 (permalink)
    0
    Hi,
    if you are using CCP module for PWM  light output intensity, then Timer2 will be used for PWM period.
    You may then use Timer1 for pulse lenght measurement.
    You may even use Timer1 in Gated Timer mode for pulse length measurement,
    but only for one servo signal on pin T1G.
     
        Mysil
     
    #3
    daba
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2012/10/15 13:24:07
    • Location: UK
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/18 04:38:20 (permalink)
    0
    Thanks for the replies guys - I've been reading the datasheet on the PIC16F18313/18323 and it says it has 2 CCP modules, and 2 PWM modules, but then gets confusing because the "P" in CCP stands for PWM, so a little unsure what it has.

    I think I've got the concept of PPS remapping, and hoping that chip will ....
    a. allow 2 CC(P?) inputs to be measured
    b. also allow 1 PWM output
    c. is supported by MPLAB IDE 8.92 (doesn't look like it is)
    d. can be programmed with PICKit 2 (doesn't look like it is)
     
    If I can't use the PIC16F18313/18323 - is there a pin compatible chip that will do the job I want ?
    #4
    Mysil
    Super Member
    • Total Posts : 3785
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/18 05:37:33 (permalink)
    0
    Hi,
    a.  Yes 2 CCP modules allow 2 inputs to be measured.
    b.  Yes, PIC16F313/323 have 2 additional PWM modules that may be used separately from CCP.
         There is also a CWG module that may make square wave signals.
    c.  You are right, Not supported by MPLAB 8.92
    d.  Forum member Anobium and associates have updated PICkit 2 standalone Programmer Application
         to PICkitPlus   for use with PICkit2 and also PICkit3 hardware.
         So are able to Program nearly any PIC device.
         Also they have done a lot of updates to PICkit2 device files, that may be used with ordinary PICkit2 software.
         See:     http://www.pickitplus.co.uk/
     
        Mysil
    #5
    NorthGuy
    Super Member
    • Total Posts : 6345
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/18 07:01:12 (permalink)
    0
    There might be some PICs which have multiple CCP/PWM, but still supported by old MPLAB 8. For example, PIC16F1614 (I'm not sure it is supported). If you don't find anything in 14-/20-pin PICs, there must be such parts among 28-pin PIC16F1xxx - these tend to have more periphery.
    #6
    daba
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2012/10/15 13:24:07
    • Location: UK
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 15:15:17 (permalink)
    0
    NorthGuy
    There might be some PICs which have multiple CCP/PWM, but still supported by old MPLAB 8. For example, PIC16F1614 (I'm not sure it is supported). If you don't find anything in 14-/20-pin PICs, there must be such parts among 28-pin PIC16F1xxx - these tend to have more periphery.


    I'm stuck with 8-pin, PCBs are manufactured, so for now the PIC1618313 (8-pin) seems to be a reasonable choice, with its ability to divert, or map, peripheral inputs and outputs to specific physical pins.
     
    I have installed MPLAB X IDE, to provide support for the later chips.  Sort of drops me back on the flat part of the learning curve, but hey ho, challenge accepted ....
     
    I might need some help along the way, I'm OK with understanding the instruction set (I code in ASM), my biggest problem is getting the CCP/Timer/Counter modules configured the way I can use them, but currently in quicksand on the __CONFIG directives. Any tutorials out there ?
     
    #7
    ric
    Super Member
    • Total Posts : 28634
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 16:08:04 (permalink)
    0
    daba
    but currently in quicksand on the __CONFIG directives. Any tutorials out there ?

    The easy way to set CONFIG bits in your source using MPLABX

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    ric
    Super Member
    • Total Posts : 28634
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 16:12:24 (permalink)
    0
    Which version of MPLABX did you download?
    v5.40 is the first to drop support for MPASM, it forcres you to use PIC-AS, which has a number of teething problems.
    You can download older versions at Download previous versions of MPLAB X and MPLAB 8
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    dan1138
    Super Member
    • Total Posts : 3914
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 16:41:03 (permalink)
    0
    daba
    ...  but currently in quicksand on the __CONFIG directives. Any tutorials out there ?



    I do not know of any tutorials for using MPLABX v5.40 and the pic-as(v2.xx) tools chain.
     
    To practice I have been making some example projects.
     
    I did one just for your PIC16F18313 and put it in my git repository here.
     
    I do not have a real part so it's only been validated with the simulator. Your Mileage May Vary.
    post edited by dan1138 - 2020/10/19 16:43:36
    #10
    daba
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2012/10/15 13:24:07
    • Location: UK
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 18:01:16 (permalink)
    0
    ric
    daba
    but currently in quicksand on the __CONFIG directives. Any tutorials out there ?

    The easy way to set CONFIG bits in your source using MPLABX


    Every single "option" drop-down does not work...

    Attached Image(s)

    #11
    ric
    Super Member
    • Total Posts : 28634
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 18:03:51 (permalink)
    0
    Which version MPLABX are you using?
     Have you created an ASM project for your PIC?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    daba
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2012/10/15 13:24:07
    • Location: UK
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 18:08:27 (permalink)
    0
    ric
    Which version MPLABX are you using?
     Have you created an ASM project for your PIC?
     


     
    Product Version: MPLAB X IDE v5.40
    Java: 1.8.0_202; OpenJDK 64-Bit Server VM 25.202-b05
    Runtime: OpenJDK Runtime Environment 1.8.0_202-b05
    System: Windows 7 version 6.1 running on amd64; Cp1252; en_GB (mplab)
    User directory: C:\Users\Dave\AppData\Roaming\mplab_ide\dev\v5.40
    Cache directory: C:\Users\Dave\AppData\Local\mplab_ide\Cache\dev\v5.40\var
     
     
    post edited by daba - 2020/10/19 18:10:06

    Attached Image(s)

    #13
    ric
    Super Member
    • Total Posts : 28634
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 18:19:53 (permalink)
    0
    That looks like another "teething problem" with pic-as,
    I did specifically warn against using v5.40 and pic-as.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    daba
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2012/10/15 13:24:07
    • Location: UK
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 18:45:23 (permalink)
    0
    ric
    That looks like another "teething problem" with pic-as,
    I did specifically warn against using v5.40 and pic-as.
     


    I've shied away from using C or C+ or C++ (is there a C+++ ?).
    I do use it for Arduino programming, because I'm not going down the route of learning the instruction set of those MCUs !

    So do I need to drop back a version or two of MPLAB X ?
    #15
    ric
    Super Member
    • Total Posts : 28634
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 19:01:14 (permalink)
    0
    daba
    So do I need to drop back a version or two of MPLAB X ?

    Yes.
    Anything older than 5.40 supports MPASM.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    dan1138
    Super Member
    • Total Posts : 3914
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Guidance : R/C Pulse Width Measurement : PIC12F675 or 683 2020/10/19 19:11:36 (permalink)
    0
    @daba,
     
    Microchip has done an awful and stupid integration of the pic-as(v2.xx) tool chain into MPLABX v5.40 as you are presently being treated to.
     
    This is the path that Microchip has decided to go for support of future 8-bit PIC architecture controllers.
     
    If the controller you want to use is supported by MPLABX v5.35 then MPASM can be used to build assembly language source code projects for that controller.
     
    However Apple has decided that support for 32-bit applications will not be part of MacOS.
     
    That means that as of a few months ago MPASM would not run on MacOS.
     
    So what I see is if you are going to use Microchip controllers on into the future you will be unable to use controllers supported only by the "new" MPLABX releases. If you think you want to use "new" controllers you would be better off learning to cope with pic-as(v2.xx) now.
    #17
    Jump to:
    © 2020 APG vNext Commercial Version 4.5