18LF2520 TMR1 for PWM

Status
Not open for further replies.

camerart

Well-Known Member
Hi,
I've been trying different PWM settings mainly on the 18LF4431 PIC, and it's to complicated for me.
Also having thought about what I need for 6x PWM, I think a simpler TMR type program will be ok.

What I am trying is to set a TIMER LOOP (using TMR1, unless there are other suggestions) to time a 20MS 'SERVO PERIOD' LOOP, then as the LOOP starts, switch ON/OFF RB0-RB5 in sequence for up to 2MS each . The 'DUTY ON' time will be set from inputting 6 times using USART.

Here is a program I've been trying from an earlier one on a 16F648 PIC, which of course has lots of differences.

It nearly works, but I'm puzzled why the TMR1H/L keep clearing?

Camerart.
 

Attachments

  • 18LF2520 INT4MHz PWM 260518 0800.bas
    1.8 KB · Views: 328
Hi,
I've tried again, with the original program from a 12F683 PIC, and now it runs
There are two toggling PINS one in a LOOP and one in the interrupt. I've used the PIR1 bit as a switch, is this ok?
C.
 

Attachments

  • 18LF2520 INT4MHz PWM 260518 1400.bas
    1.4 KB · Views: 348
Last edited:
The reason it didn't.... The config bits were wrong for a 4Mhz crystal... I just regenerated... Also TO8BIT isn't correct... It's TO16BIT... Works okay here... 20.45mS period...
 
The reason it didn't.... The config bits were wrong for a 4Mhz crystal... I just regenerated... Also TO8BIT isn't correct... It's TO16BIT... Works okay here... 20.45mS period...
Hi,
I had to abandon TMR1 because it clashes with another section of program to be added, which is written also using TMR1.
C.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…