1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

18lf4431 for PWM

Discussion in 'Oshonsoft' started by camerart, Feb 16, 2018.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I have a thread: https://www.electro-tech-online.com/threads/radio-control-by-location.152926/
    And as I have some 18F2431 PICs, I'm using these before the 18LF4431 PICs

    Looking at the POWER CONTROL PWM MODULE, SECTION 18 of the D/S, it appears that it has special PWM circuitry.

    Has anyone used these PICs for PWM for driving servos and ESC motor control?

    EDIT: Just found CINFIG3L PWMPIN
    Camerart.
     
    Last edited: Feb 16, 2018
  2. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,593
    Likes:
    202
    Location:
    Lancashire UK
    I have used a PIC18F2431 PWM for a closed loop speed controller. The speed feedback is from an optical encoder on the motor and the PWM controls the power to the motor. The PWM part is easy to use and works well.

    Les.
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi L,
    I will not be need feedback, so only need to output servo or ESC motor control.
    Did you use the SECTION 18 of the D/S way of setting the PWM?
    C.
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,720
    Likes:
    422
    Location:
    Brisbane Australia
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi M,
    Thanks for searching for your example, I note it uses CCP as you say.
    I was hoping for an example without CCP. Does this thread answer my question?
    See #4
    http://www.picbasic.co.uk/forum/showthread.php?p=43820#post43820
    C.
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,720
    Likes:
    422
    Location:
    Brisbane Australia
    You can bitbang it but why would you want to? The CCP module is made for this very thing.

    Just reread the OP and I still think it asks for PWM code!

    Mike.
    Edit, with the special event trigger you can have up to 20 servo outputs using one PWM/CCP module.
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  9. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,805
    Likes:
    958
    Location:
    Rochdale UK
    Hi C.. The PWM is controlled via the CCP module... To use PWM without hardware means software alternative ( Mike calls it bit banging ) I have use software PWM on many pics using the timer interrupt..

    But!! The hardware one is piddle easy to use... Has Vladimir done the PWMout on this device... Do you need an example..
     
  10. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi M and I,
    Section 18, Power Control PWM, is not an easy read, but I sense that it specialises in 'bitbanging' (Thanks for the explanation, I)
    I have programs where CCP controls the PWM, by Eric Gibbs, but he had to make some special ASM code (Which I don't understand) to do it, because of Oshonsoft limitations.
    If bit banging is a way to get round this and use a PIC that specialises in PWM, then this may be the best for me.
    From what I gather, on this PIC, there is no need for timer control, as it is inbuilt, let me know if I'm wrong.
    EDIT: Again, correct me if I'm wrong, but I don't think it is necessary to 'do' bitbanging with this PIC?
    C.
     
    Last edited: Feb 17, 2018
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,354
    Likes:
    650
    Location:
    Ex Yorks' Hants UK
    Hi C,
    If you recall there is a bug on Oshonsoft PWM, it does not clear the CCPRxL reg correctly, it was reported to Vlad.
    You and I have used this ASM in dozens of programs already, I don't see a problem with using it again.??

    E

    hcw: ' clock wise
    Hserin dutyhcw 'duty 0 thru FFh
    ASM: bcf CCP1CON,DC1B0
    ASM: bcf ccp1con,dc1b1
    ASM: movlw 0x00
    ASM: movwf ccpr1l
    PWMduty 2, dutyhcw
    Goto main

    hacw: ' anti clock wise
    Hserin dutyhacw 'duty 0 thru FFh
    ASM: bcf CCP2CON,DC2B0
    ASM: bcf ccp2con,dc2b1
    ASM: movlw 0x00
    ASM: movwf ccpr2l
    PWMduty 1, dutyhacw
    Goto main
     
  12. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi E,
    I mentioned you and the bug in #8, but I think/hope that CCP is not needed for the 18LF4431 2431 PICs.
    EDIT: I think the uses of 2x blocks of code for clockwise and anticlockwise are similar to the paired PWM outputs in the 18LF4431 PICs, which are used for 'H' bridges. I don't need this, but only 1x ON/OFF period for each channel.
    EDITEDIT: 18LF4431 not 18LF4531
    Thanks, C.
     
    Last edited: Feb 17, 2018
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    From what I understand at the moment, and from the few tests I've done, I think the best way for what I want to do is:

    Use a largish PIC for the main program, which sends the PWM numbers to a second smaller PIC, which controls the PWMs only.

    C.
     
  14. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I'm trying to convert a SERVO PWM program written in 'C' to Oshonsoft BASIC.

    I'll try it on an 18LF4431 that only controls the PWM outputs from a serial input.

    Here is the 'C' program and my started conversion Oshonsoft program. I would appreciate any help in getting it to work, please.

    Camerart
     

    Attached Files:

  15. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,805
    Likes:
    958
    Location:
    Rochdale UK
    I have done this.... If it helps... I have not tested this at all... Just to show where it all goes..
     

    Attached Files:

  16. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    It does help a lot.

    I have changed it so it compiles in Oshonsoft, but there are problems. All changes have ??????????
    You will notice that the CCPR1H lines are commented out, as I can't get them to work.

    Thanks,
    C
     

    Attached Files:

  17. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,805
    Likes:
    958
    Location:
    Rochdale UK
    You might need to have a dummy

    dim dummy as word

    dummy = servo(cnt)
    CCPR1L = dummy.LB
    CCPR1H = dummy.HB
     
  18. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    I think that worked, as it's compiled.

    Next I've got to 'HSERIN' (or the other method) 6x values for 6x SERVOs (Between 1000 and 2000)

    Thanks, C.
     
  19. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    I used E's CODE for the RX sentence.
    Here:
    C.
     

    Attached Files:

  20. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    If you're still reading this thread?
    I've been 'round the houses' and think I've now got a program using TMR0 instead of TMR1 as it clashed with a second TMR1 used in the second part of the fuller program.
    What I want to know is: Can the CODE you posted on #13 be changed to TMR0?
    C.
     
  21. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,805
    Likes:
    958
    Location:
    Rochdale UK
    Yes!! Change PIR1.TMR1IF to INTCON.TMR0IF

    Remove PIE1.TMR1IE and put in INTCON.TMR0IE

    You will also need to set the timer period... If you post what has been set in T1CON. I'll give you what to set in T0CON..
     
  22. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,823
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    Before I try your CODE, will you try the '18LF2520 INT4MHz TIMESIN SERVOOUT 300518 0800' program posted Here: https://www.electro-tech-online.com/threads/calculating-and-setting-pic-tmr-loop.153994/

    Also NOTE: 'E's comment at #9
    C.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice