View previous topic :: View next topic |
Author |
Message |
johnl
Joined: 30 Sep 2003 Posts: 120
|
16F1764 PWM5 not working |
Posted: Wed May 04, 2016 9:44 pm |
|
|
Pin C3 toggles as it's supposed to, but there's no PWM output on pin C2 (or any other pin.). PCM V. 5.055
Code: | #include <16f1764.h>
#include <stdlib.h>
#fuses INTRC_IO,NOWDT, PUT, MCLR, NOPROTECT,NOBROWNOUT, NODEBUG, NOLVP
#fuses NOPPS1WAY
#use delay(INTERNAL = 32000000)
#PIN_SELECT PWM5=PIN_C2 //select the PWM 5 pin
void main(void)
{ set_tris_c(0);
port_a_pullups(0b1011);
set_tris_a(0b1011);
setup_pwm5(PWM_STANDARD | PWM_CLK_FOSC | PWM_CLK_DIV_BY_1);
set_pwm5_period(0x3FFF);
set_pwm5_duty(0x1FFF);
while(TRUE)
{
output_toggle(PIN_C3); //chip is alive. Instruction clock = 8 MHz
delay_us(125);
}
} |
|
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu May 05, 2016 5:22 pm |
|
|
Does the C code look like it should work?
If so, and it's not my hardware which only contains a 0.1uF bypass cap and a programming header, could this be compiler bug?
Here's the asm file (minus the includes):
Code: | .................... #fuses INTRC_IO,NOWDT, PUT, MCLR, NOPROTECT,NOBROWNOUT, NODEBUG, NOLVP
.................... #fuses NOPPS1WAY
....................
.................... #use delay(INTERNAL = 32000000)
0003: MOVLW 02
0004: SUBWF 26,F
0005: BTFSS 03.0
0006: GOTO 014
0007: MOVLW 20
0008: MOVWF 05
0009: MOVLW 06
000A: MOVWF 04
000B: MOVF 00,W
000C: BTFSC 03.2
000D: GOTO 014
000E: GOTO 012
000F: GOTO 010
0010: GOTO 011
0011: NOP
0012: DECFSZ 00,F
0013: GOTO 00F
0014: MOVLP 00
0015: GOTO 05B (RETURN)
.................... #PIN_SELECT PWM5=PIN_C2 //select the PWM 5 pin
....................
.................... void main(void)
0016: MOVLW 55
0017: MOVLB 1C
0018: MOVWF 0F
0019: MOVLW AA
001A: MOVWF 0F
001B: BCF 0F.0
001C: MOVLW 10
001D: MOVLB 1D
001E: MOVWF 22
001F: MOVLW 55
0020: MOVLB 1C
0021: MOVWF 0F
0022: MOVLW AA
0023: MOVWF 0F
0024: BSF 0F.0
0025: MOVLW F0
0026: MOVLB 01
0027: MOVWF 19
0028: MOVLB 03
0029: CLRF 0C
002A: CLRF 0E
002B: MOVLB 02
002C: CLRF 12
002D: CLRF 13
002E: CLRF 11
002F: MOVLW 04
0030: MOVWF 10
0031: MOVLB 00
0032: CLRF 20
0033: CLRF 21
.................... { set_tris_c(0);
0034: MOVLW 00
0035: MOVLB 01
0036: MOVWF 0E
.................... port_a_pullups(0b1011);
0037: MOVLW 0B
0038: MOVLB 04
0039: MOVWF 0C
003A: MOVLB 01
003B: BCF 15.7
.................... set_tris_a(0b1011);
003C: MOVWF 0C
.................... setup_pwm5(PWM_STANDARD | PWM_CLK_FOSC | PWM_CLK_DIV_BY_1);
003D: MOVLB 1B
003E: BCF 1B.7
003F: MOVLB 01
0040: BCF 0E.2
0041: MOVLB 1B
0042: CLRF 20
0043: CLRF 5F
0044: CLRF 5C
0045: CLRF 1E
0046: MOVLW 80
0047: MOVWF 1B
.................... set_pwm5_period(0x3FFF);
0048: MOVLW 3F
0049: MOVWF 16
004A: MOVLW FF
004B: MOVWF 15
004C: BSF 1F.7
.................... set_pwm5_duty(0x1FFF);
004D: MOVLW 1F
004E: MOVWF 14
004F: MOVLW FF
0050: MOVWF 13
0051: BSF 1F.7
.................... while(TRUE)
.................... {
.................... output_toggle(PIN_C3); //chip is alive. Instruction clock = 8 MHz
0052: MOVLB 01
0053: BCF 0E.3
0054: MOVLW 08
0055: MOVLB 02
0056: XORWF 0E,F
.................... delay_us(125);
0057: MOVLW 7D
0058: MOVLB 00
0059: MOVWF 26
005A: GOTO 003
005B: MOVLB 1B
005C: GOTO 052
.................... }
.................... }
005D: SLEEP
Configuration Fuses:
Word 1: 39C4 INTRC_IO NOWDT PUT MCLR NOPROTECT NOBROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1EFB NOWRT NOPPS1WAY ZCDDIS NOPLLEN STVREN BORV19 NOLPBOR NODEBUG NOLVP |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 05, 2016 6:20 pm |
|
|
Quote: |
#fuses INTRC_IO,NOWDT, PUT, MCLR, NOPROTECT,NOBROWNOUT, NODEBUG, NOLVP
#fuses NOPPS1WAY
If so, and it's not my hardware which only contains a 0.1uF bypass cap
and a programming header, could this be compiler bug?
|
You have MCLR enabled. You need an MCLR pull-up resistor. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu May 05, 2016 6:31 pm |
|
|
PCM programmer wrote: | Quote: |
#fuses INTRC_IO,NOWDT, PUT, MCLR, NOPROTECT,NOBROWNOUT, NODEBUG, NOLVP
#fuses NOPPS1WAY
If so, and it's not my hardware which only contains a 0.1uF bypass cap
and a programming header, could this be compiler bug?
|
You have MCLR enabled. You need an MCLR pull-up resistor. |
The data sheet says that when the config bit enables MCLR, then the PU resistor is enabled. Besides the chip is running, so it's not in the reset state. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 05, 2016 7:19 pm |
|
|
You're right. You pointed that out to me in the previous thread.
I notice you're not setting the Phase register. What happens if you set
it to some small value ? |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu May 05, 2016 8:01 pm |
|
|
PCM programmer wrote: |
I notice you're not setting the Phase register. What happens if you set
it to some small value ? |
Wow...Good call!
I tried it with two chips on two boards and it worked both times.
Thanks!
Code: | set_pwm5_phase (32); |
|
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu May 05, 2016 8:02 pm |
|
|
Does this qualify as a compiler bug? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 05, 2016 9:05 pm |
|
|
I don't think so. The PIC data sheet shows that the Phase register must
be set to something in the timing diagram for Standard 16-bit pwm mode. |
|
|
|