• 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.

18lf4431 for PWM

camerart

Active Member
Thread starter #1
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:

Les Jones

Well-Known Member
#2
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.
 

camerart

Active Member
Thread starter #3
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.
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.
 

camerart

Active Member
Thread starter #5
You can't use PWM for servo control but you can use the same module. You use the Compare mode with set/clear output on match and Timer 1. Don't have access to code now but I have an example somewhere.

Mike.
Edit, have a read of https://www.electro-tech-online.com/threads/junebug-servo-c18-code.36127/
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.
 

Pommie

Well-Known Member
Most Helpful Member
#6
Hi M,
I was hoping for an example without CCP.
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#7
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..
 

camerart

Active Member
Thread starter #8
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:

ericgibbs

Well-Known Member
Most Helpful Member
#9
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
 

camerart

Active Member
Thread starter #10
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
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:

camerart

Active Member
Thread starter #11
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.
 

camerart

Active Member
Thread starter #12
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
 

Attachments

camerart

Active Member
Thread starter #14
I have done this.... If it helps... I have not tested this at all... Just to show where it all goes..
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
 

Attachments

camerart

Active Member
Thread starter #16
You might need to have a dummy

dim dummy as word

dummy = servo(cnt)
CCPR1L = dummy.LB
CCPR1H = dummy.HB
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.
 

camerart

Active Member
Thread starter #18
I have done this.... If it helps... I have not tested this at all... Just to show where it all goes..
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#19
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..
 

camerart

Active Member
Thread starter #20

Latest threads

EE World Online Articles

Loading

 
Top