PDA

View Full Version : PWM on pic16f1825 issues - 1.pbp v2.60c bug found, fix shown, 2.CCP2 on ALT pin probl



ofuzzy1
- 3rd April 2011, 08:31
'LESSONS LEARNED
' 1. pbpbasic hpwm 2,64,1 works properly for the 16f1825 for ccp2 on pin7 RC3
' 2. must use TRISC.3 =0 to enable
' 3. needed to add definition for CCPTMRS0 in the MPASM P16F1825.inc
' 4. 16f1825/29 default cpu speed is 500Khz NOT 4Mhz


This code works on pin 7 default for ccp2

'COMPILED FOR PIC16F1825
'for pic16f182x
define ccp2_reg PORTC
define ccp2_bit 3 'ra5=ccp2 pin 2 VLED
DEFINE HPWM2_TIMER 2

dc var byte

ANSELA = 0 ' disable A2D
ANSELC = 0
CM1CON0 = $0
CM1CON1 = $0
CM2CON0 = $0
CM2CON1 = $0

APFCON0.7 = 1 'assign RX/DT to RA1 from RA5
APFCON1.0 = 0 'assign ccp2 to 1= ra5 0=RC3
' APFCON1.0 = 1 'assign ccp2 to ra5 FROM RC3

TRISC.3 = 0 ' pimary location for ccp2 pin7
trisa.5 = 0 ' alt location for ccp2 pin2
do

for dc =255 to 1 step -1


hpwm 2,dc,1000

pause 100

next dc
loop


end

Issue #1.
compiled & got

error [113] c:pbp\pbppi14e.lib 2089: sysmbol not previously defined [CCPTMSR0]



'FROM MPASM PIC16F1825 processor include: p16F1825.inc
'CCPTMRS EQU H'029E'
'CCPTMRS0 EQU H'029E' ; ADDED this and it worked just fine

here's why


'code from c:pbp\pbppi14e.lib
'hpwmch2
...
line #2089
' movlb CCPTMRS0 >> 7


Issue #2: CCP2 does not out put to RA5



'for pic16f182x
define ccp2_reg PORTA
define ccp2_bit 5 'ra5=ccp2 pin 2 VLED
DEFINE HPWM2_TIMER 2

APFCON0.7 = 1 'assign RX/DT to RA1 from RA5
APFCON1.0 = 1 'assign ccp2 to 1= ra5 0=RC3
TRISA.5 =0 ' the other way to enable the pwm output

....
hpwm 2,dc,1000


Any thoughts / fixes would be appreciated.

Bruce
- 3rd April 2011, 15:36
The TRIS problem will be fixed by using CAPs in your defines.

DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 3
DEFINE HPWM2_TIMER 2

MPASM is case sensitive.

In your P16F1825.INC file just add CCPTMRS0 below CCPTMRS. It's OK to have more than 1 name defined for a file register.

CCPTMRS EQU H'029E'
CCPTMRS0 EQU H'029E'

Both just let the compiler know the file registers address.

Not all PIC16F1xxx types have CCPTMRS0 and CCPTMRS1. The ones that don't normally have the timer select register defined as CCPTMRS.

ofuzzy1
- 4th April 2011, 01:07
Thanks Bruce,

Will pay more attention to the caps issue.

Any thoughts or considerations on the alternate location for CCP2?

This did not work.

APFCON0.7 = 1 'assign RX/DT to RA1 from RA5
APFCON1.0 = 1 'assign ccp2 to 1= ra5 0=RC3

Bruce
- 9th April 2011, 17:47
Unless you're using the internal oscillator, you can't use RA5 as an output pin.

ofuzzy1
- 10th April 2011, 08:44
Yup, Figured that out the other night.

It's them config words and assuming the compiler is doing what you want not what it was told to do. : )

posted the details on the Microchip site.
http://www.microchip.com/forums/m570397.aspx

===========================
I knew I just need to set another bit, well actually it was 3 bits.

You know what happens when you assUme.

Lesson learned:
1. don't assume the config words are set correctly shock
2. rtfm some more. LoL

RA5 is also OSCIN & CLKIN

Since the thing ran, I assumed the FOSC was set correctly by the compiler.

configword1 FOSC<2:0> was = 010 needed to be 100

bit 2-0 FOSC<2:0>: Oscillator Selection bits
111 =ECH: External Clock, High-Power mode (4-32MHz): device clock supplied to CLKIN pin
110 =ECM: External Clock, Medium-Power mode (0.5-4MHz): device clock supplied to CLKIN pin
101 =ECL: External Clock, Low-Power mode (0-0.5MHz): device clock supplied to CLKIN pin
100 =INTOSC oscillator: I/O function on CLKIN pin
011 =EXTRC oscillator: External RC circuit connected to CLKIN pin
010 =HS oscillator: High-speed crystal/resonator connected between OSC1 and OSC2 pins
001 =XT oscillator: Crystal/resonator connected between OSC1 and OSC2 pins
000 =LP oscillator: Low-power crystal connected between OSC1 and OSC2 pins

Okay, so now I can use the layout for my PCB without cutting.
PWM on the Backlight led will now work. mr green

Board specs:
1.5" x 1" prototyping area with a V+ & GND bus on the ends
RS-232 both 5v & full +/-12v via DB9
Use the PICkIT "PROG" connector to also talk to it via rs232-TTL uses RA3 (in) and RA0 (out)
LCD connectors for both styles of HD44780 Modules -- 1x16 & 2x8 on 0.1 centers
Laid out for the 14pin PIC to control the LCD so the remaining pins can be used for fun things. Even the 14pin Pic has 2 pins open.

Thanks for the help! :)
pcb schematic, layout and 3d by KICAD [free]
top view
PCB (c)2011 Ofuzzy1.com
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=5340&d=1302421397
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=5341&d=1302421397

Dave
- 10th April 2011, 12:48
ofuzzy1 , Your layout look pretty good but I notice one thing. You would have to use a cable for the ICSP because it is too close to the coaxial power connector. I always lay my boards out so that you can plug the PicKit2 into them directly. Just my preference I pupose. I less cable to loose....

Dave Purola,
N8NTA