View previous topic :: View next topic |
Author |
Message |
plehman
Joined: 18 Feb 2004 Posts: 12
|
Could use help figuring this one out. |
Posted: Fri Jan 06, 2006 8:29 am |
|
|
I'm trying to get the PWMs working with Timer4 on a PIC18F6720 instead of Timer2. Here's my problem...
If I use the following code snippet, I cannot get PWM5 to run
Code: | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED|T2_DIV_BY_1);
setup_timer_3(T3_INTERNAL|T3_DIV_BY_1|T3_CCP1_TO_5);
setup_timer_4(T4_DIV_BY_1,29,1);
set_pwm5_duty(14);
setup_ccp5(CCP_PWM); |
but, if instead, I use
Code: | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
setup_timer_2(T2_INTERNAL|T2_DIV_BY_1,29,1);
setup_timer_3(T3_INTERNAL|T3_DIV_BY_1|T3_CCP1_TO_5);
//setup_timer_4(T4_DIV_BY_1,29,1);
set_pwm5_duty(14);
setup_ccp5(CCP_PWM); |
the PWM will operate as expected. Note that the setup Timer4 instruction is apparently meaningless despite the fact that I requested Timer3's control register to use T3_CCP1_TO_5 which according to the data sheet for the part should use Timers 3 and 4 for all the CCP modules.
Reading the manual, which is admittedly old for the compiler, it apears that the set_pwmx_duty() commands will only make use of Timer2. Is that so?
Anyway, I'm missing something here and would greatly appreciate any help people can give.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 06, 2006 12:37 pm |
|
|
Neither of the two examples you posted will compile with PCH vs. 3.241.
They both give syntax errors on the setup_timer_2() function.
The first usage has too few arguments, and the 2nd one uses a constant
that is not defined in 18F6720.
It doesn't do any good to post "typed in" code. |
|
|
plehman
Joined: 18 Feb 2004 Posts: 12
|
|
Posted: Fri Jan 06, 2006 12:45 pm |
|
|
Sorry.
Remove the T2_INTERNAL constant. The correct setup_timer_2() calls should be :
setup_timer_2(T2_DISABLED|T2_DIV_BY_1,29,1);
and
setup_timer_2(T2_DIV_BY_1,29,1); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 07, 2006 1:55 pm |
|
|
Post your version of the compiler. You can find it at the top of the
.LST file in your project folder. It will be a number such as 3.191,
3.241, etc. |
|
|
plehman
Joined: 18 Feb 2004 Posts: 12
|
|
Posted: Mon Jan 09, 2006 6:20 am |
|
|
3.221 |
|
|
mdares
Joined: 26 Oct 2005 Posts: 19
|
|
Posted: Mon Jan 09, 2006 7:36 am |
|
|
I know there are some issues with the way the PWM functions are implemented on some pre 3.224 versions for at least some of the PIC18F's. This may not be your problem, but I would take a look at what the pwm control reg. are being set to by the compiler versus what you would expect. Also make sure that when you call any of the built in PWM functions it is not changing anything.
Sorry for being so vague but it was over a year ago I encountered a similiar problem and I don't quite remember the details. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 09, 2006 4:18 pm |
|
|
I don't have that version, so post the portion of the .LST file that
shows the ASM code for these 7 lines: (Don't post the entire .LST file).
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED|T2_DIV_BY_1);
setup_timer_3(T3_INTERNAL|T3_DIV_BY_1|T3_CCP1_TO_5);
setup_timer_4(T4_DIV_BY_1,29,1);
set_pwm5_duty(14);
setup_ccp5(CCP_PWM);
|
Make sure the listing file is in this format shown below. Then we
can analyze it for the proper register settings.
(Except post the listing for all 7 lines shown above)
Code: | .......... setup_ccp5(CCP_PWM);
0003E: MOVLW B7
00040: ANDWF FB1,F
00042: BCF F98.4
00044: BCF F8F.4
00046: MOVLW 0C
00048: MOVWF F70 |
|
|
|
|