| View previous topic :: View next topic |
| Author |
Message |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Wed Feb 24, 2016 3:48 pm |
|
|
| Ttelmah wrote: | | You'd tried to use #use PWM. With a period of 32MHz... |
Oh no no no.. That was only in a comment in the code I labelled "Source A" from a previous post. Sorry for leaving that in and causing confusion.
Actually, that is the code ("A") that seems to be reliable. Every time I build and program a chip with it ,PWM works.
Just tried another experiment with "Source B" (your code). Two out of three chips did not work, but one did. I read the code from all three and the checksums all match. Now I'm really confused. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Wed Feb 24, 2016 5:08 pm |
|
|
hmm...might be a hardware issue, are all three tried on different PCBs or the same one ?
Jay |
|
 |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Wed Feb 24, 2016 5:23 pm |
|
|
| temtronic wrote: | hmm...might be a hardware issue, are all three tried on different PCBs or the same one ?
Jay |
All three in the same socket one at a time on the same board which is only a perf board wired to a bypass cap and a power supply. Only Vdd and ground connected. Nothing else. The output on C3 always works, so I know the chip is executing. Just the PWM output on C2 is the problem.
Here's the thing:
Code "A" (using the registers directly and only the duty cycle CCS function) works every time.
Code "B" (using the CCS functions) works only some times.
Silicon or compiler bug? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 24, 2016 5:44 pm |
|
|
| Quote: | | only a perf board wired to a bypass cap and a power supply. |
1. Does this mean the bypass cap is close to the power supply ?
Is there a 100 nF bypass cap from the Vdd pin on the PIC to ground ?
Is the cap very close to the Vdd pin on the PIC ? You need this.
| Quote: | | Only Vdd and ground connected. Nothing else |
2. Is there a pull-up resistor (to Vdd) connected to the MCLR pin ? |
|
 |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Wed Feb 24, 2016 6:08 pm |
|
|
| PCM programmer wrote: | | Quote: | | only a perf board wired to a bypass cap and a power supply. |
1. Does this mean the bypass cap is close to the power supply ?
Is there a 100 nF bypass cap from the Vdd pin on the PIC to ground ?
Is the cap very close to the Vdd pin on the PIC ? You need this.
| Quote: | | Only Vdd and ground connected. Nothing else |
2. Is there a pull-up resistor (to Vdd) connected to the MCLR pin ? |
1. The 0.1 uF cap is across pins 1 and 14. Also there is a second cap of 0.47uF across the pins. Both mounted as close as they can be to the pins.
2. No. Datasheet says a PU is there for MCLR. Also voltage on the pin measures Vdd (5v) so I think it is working.
Edit: I should mention that the project has just changed and I'll be using a 16F1788 instead. So solving this problem isn't critical now, but I am very curious why it happens. Thanks much. |
|
 |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu Feb 25, 2016 11:45 am |
|
|
In case anyone is interested...
Here's the assembly listing for the "B" code (the one with the CCS functions that doesn't work all the time.)
| 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 05C (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
.................... {
.................... port_a_pullups(0xFF); //8 bit mask required
0034: MOVLW FF
0035: MOVLB 04
0036: MOVWF 0C
0037: MOVLB 01
0038: BCF 15.7
.................... port_c_pullups(0xFF);
0039: MOVLB 04
003A: MOVWF 0E
.................... set_tris_c(0);
003B: MOVLW 00
003C: MOVLB 01
003D: MOVWF 0E
.................... setup_pwm5(PWM_STANDARD | PWM_CLK_FOSC | PWM_CLK_DIV_BY_1);
003E: MOVLB 1B
003F: BCF 1B.7
0040: MOVLB 01
0041: BCF 0E.2
0042: MOVLB 1B
0043: CLRF 20
0044: CLRF 5F
0045: CLRF 5C
0046: CLRF 1E
0047: MOVLW 80
0048: MOVWF 1B
.................... set_pwm5_period(0x3FFF);
0049: MOVLW 3F
004A: MOVWF 16
004B: MOVLW FF
004C: MOVWF 15
004D: BSF 1F.7
.................... set_pwm5_duty(0x1FFF);
004E: MOVLW 1F
004F: MOVWF 14
0050: MOVLW FF
0051: MOVWF 13
0052: BSF 1F.7
.................... while(TRUE)
.................... {
.................... output_toggle(PIN_C3); //chip is alive. Instruction clock = 8 MHz
0053: MOVLB 01
0054: BCF 0E.3
0055: MOVLW 08
0056: MOVLB 02
0057: XORWF 0E,F
.................... delay_us(125);
0058: MOVLW 7D
0059: MOVLB 00
005A: MOVWF 26
005B: GOTO 003
005C: MOVLB 1B
005D: GOTO 053
.................... }
.................... }
005E: 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
|
|
|
 |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu Feb 25, 2016 11:47 am |
|
|
... and the listing for the "A" code (the one that works all the time.)
| Code: |
.................... #fuses INTRC_IO,NOWDT,PUT,MCLR,NOPROTECT,NOBROWNOUT, PLLEN,NODEBUG,NOLVP,
.................... #use delay(clock = 32000000)
....................
....................
.................... #byte PWM5PRH = 0xD96
.................... #byte PWM5PRL = 0xD95
.................... #byte PWM5DCH = 0xD94
.................... #byte PWM5DCL = 0xD93
.................... #byte PWM5CON = 0xD9B
.................... #byte PWM5CLKCON = 0xD9E
.................... #byte RC2PPS = 0xEA2
.................... #byte PWM5PHL = 0xD91
.................... #byte PWM5PHH = 0xD92
....................
.................... #word PWM5DC = getenv("SFR:PWM5DCL")
....................
.................... ////#use pwm(pwm5, output=PIN_C2, period=32000000,pwm_on)
.................... ///
.................... void main(void)
0003: MOVLW F0
0004: MOVLB 01
0005: MOVWF 19
0006: MOVLB 03
0007: CLRF 0C
0008: CLRF 0E
0009: MOVLB 02
000A: CLRF 12
000B: CLRF 13
000C: CLRF 11
000D: MOVLW 04
000E: MOVWF 10
000F: MOVLB 00
0010: CLRF 20
0011: CLRF 21
.................... {
.................... int X;
.................... port_a_pullups(0b11111);
0012: MOVLW 1F
0013: MOVLB 04
0014: MOVWF 0C
0015: MOVLB 01
0016: BCF 15.7
.................... port_c_pullups(0b11111);
0017: MOVLB 04
0018: MOVWF 0E
.................... set_tris_c(0);
0019: MOVLW 00
001A: MOVLB 01
001B: MOVWF 0E
.................... setup_adc(ADC_OFF);
001C: BCF 1D.0
.................... PWM5PRH = 0x3F;
001D: MOVLW 3F
001E: MOVLB 1B
001F: MOVWF 16
.................... PWM5PRL = 0xFF;
0020: MOVLW FF
0021: MOVWF 15
....................
.................... PWM5DCH = 0; //0x1F; // 1FFF ----> 50% DC
0022: CLRF 14
.................... PWM5DCL = 0xFF;
0023: MOVWF 13
....................
.................... PWM5CON = 0x80;
0024: MOVLW 80
0025: MOVWF 1B
.................... PWM5CLKCON = 0x0; // Fosc source
0026: CLRF 1E
....................
.................... RC2PPS = 0x10; //PWM5 out on C2
0027: MOVLW 10
0028: MOVLB 1D
0029: MOVWF 22
.................... PWM5PHL = 0x0;
002A: MOVLB 1B
002B: CLRF 11
.................... PWM5PHH = 0x0;
002C: CLRF 12
....................
.................... set_pwm5_duty(7000);
002D: MOVLW 1B
002E: MOVWF 14
002F: MOVLW 58
0030: MOVWF 13
0031: BSF 1F.7
.................... //
....................
.................... while(1)
.................... {
.................... output_toggle(PIN_C3); //chip is alive. Instruction clock = 8 MHz
0032: MOVLB 01
0033: BCF 0E.3
0034: MOVLW 08
0035: MOVLB 02
0036: XORWF 0E,F
.................... delay_cycles(250);
0037: MOVLW 53
0038: MOVWF 77
0039: DECFSZ 77,F
003A: GOTO 039
.................... delay_cycles(250); delay_cycles(250); delay_cycles(250);
003B: MOVLW 53
003C: MOVWF 77
003D: DECFSZ 77,F
003E: GOTO 03D
003F: MOVLW 53
0040: MOVWF 77
0041: DECFSZ 77,F
0042: GOTO 041
0043: MOVLW 53
0044: MOVWF 77
0045: DECFSZ 77,F
0046: GOTO 045
0047: MOVLB 1B
0048: GOTO 032
....................
.................... }
....................
....................
....................
.................... }
0049: SLEEP
Configuration Fuses:
Word 1: 39C4 INTRC_IO NOWDT PUT MCLR NOPROTECT NOBROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1EFF NOWRT PPS1WAY ZCDDIS NOPLLEN STVREN BORV19 NOLPBOR NODEBUG NOLVP
|
|
|
 |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Feb 25, 2016 12:15 pm |
|
|
hoping to be helpful with one thing:
you use set_tris();
thus you ought to read about
#USE FAST_IO
for it's implications to coding |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Thu Feb 25, 2016 12:27 pm |
|
|
first programs fuses....
Word 2: 1EFB NOWRT NOPPS1WAY ZCDDIS NOPLLEN STVREN BORV19 NOLPBOR NODEBUG NOLVP
second programs fuses....
Word 2: 1EFF NOWRT PPS1WAY ZCDDIS NOPLLEN STVREN BORV19 NOLPBOR NODEBUG NOLVP
NOT the same ! Don't know if it's important but not apples vs apples
haven't checked anything else as this 'bothers' me...
Jay |
|
 |
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Thu Feb 25, 2016 12:41 pm |
|
|
| Nope. I commented out #fuses NOPPS1WAY on the B version and it still didn't work (2 out of three chips had no PWM output.) |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9632 Location: Greensville,Ontario
|
|
Posted: Thu Feb 25, 2016 1:40 pm |
|
|
I looked at the asm but you actually have some thing different so I can't compare 'apples to apples'.
Hate to be 'nitpicky' but it'd be nice if they were apples and apples.
I know the 'LED function doesn't really matter but......
things like setting up port a might....
Jay |
|
 |
|