PDA

View Full Version : PWM problem with PIC16F777



orjon1
- 23rd June 2011, 19:51
Would really appreciate some help on getting the 3rd PWM to work on my PIC16F777.

I'm using the three PWM's to control R G B led strips. My PortB.5 will not light!

The code I'm using - primarily from this forum is below. I know that the circuit is fine, as all three colours work when I manually switch the pins high and low.

I've stripped the code down - for simplicity - to just flash through the three colours... but alas only ever get two!



'-- Setup ---------------------------------------------------------------------
@ DEVICE PIC16F777, INTRC_OSC_NOCLKOUT

DEFINE OSC 8

OSCCON = %01110010 'see data sheet for INTRC speed setting

' Word vars for 10-bit value of each PWM duty cycle
DutyR VAR WORD ' Channel #1
DutyG VAR WORD ' #2
DutyB VAR WORD ' #3

' Set CCPx pins to outputs
TRISC.2=0 ' CCP1 output
TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
TRISB.5=0 ' CCP3 output

' Set CCP modules to PWM mode
CCP1CON = %00001100 ' Mode select = PWM
CCP2CON = %00001100 ' Mode select = PWM
CCP3CON = %00001100 ' Mode select = PWM

' Set period up for 1.22kHz PWM freq
PR2 = $FF

' Set TMR2 up for 1:16 prescale & turn it on
T2CON = %00000110 ' TMR2 ON 1:16 prescale


'-- Program ---------------------------------------------------------------------
MainRoutine:

dutyR = 719
dutyg = 0
dutyb = 0
gosub colourset
PAUSE 1000

dutyR = 0
dutyg = 719
dutyb = 0
gosub colourset
PAUSE 1000

dutyR = 0
dutyg = 0
dutyb = 719
gosub colourset
PAUSE 1000

goto MainRoutine

'-------------------------------------------------------------------------------

colourset:
CCP1CON.4 = Dutyr.0 ' Setup 10-bit duty cycle as
CCP1CON.5 = Dutyr.1 ' a 10-bit word
CCPR1L = Dutyr >> 2

CCP2CON.4 = Dutyg.0
CCP2CON.5 = Dutyg.1
CCPR2L = Dutyg >> 2

CCP3CON.4 = Dutyb.0
CCP3CON.5 = Dutyb.1
CCPR3L = Dutyb >> 2
return


Many thanks in advance,
orjon.

mister_e
- 23rd June 2011, 20:04
Rule #1: Always check the pinout.

http://circuits.datasheetdir.com/19/PIC16F777-pinout.jpg

What's on PORTB.5?
Yeah right AN13... Now check the datasheet page 155 (ADCON1 register) to see how to disable the ADC on this pin.

orjon1
- 23rd June 2011, 20:35
Hi Steve,

Thank you for the prompt reply.

I've been looking through the datasheet in the A/D section, but it's quite over my head! I have done some searches and see that setting the ADCON1 to %00000001 for instance would set AN0 to A/D. But see not reference to AN13 (portb.5) in the table...

Another clue ... please?!

mackrackit
- 23rd June 2011, 21:39
ADCON1 = 15 ' All I/O pins digital

orjon1
- 23rd June 2011, 21:53
Thanks!

Phew - that wasn't fun...

It is possible to set them individually?

Thank you both very much - you have just completed the spectrum for me!

mackrackit
- 23rd June 2011, 22:03
Yes, goto the table Steve mentioned and take a look.
1111 = 15
:D

orjon1
- 23rd June 2011, 22:32
Ahhh... Sorry guys - I was looking at Page 155 (as per page number at bottom) and beyond - not Page 155 of the PDF! So I started (struggling) to read through missing the two pages before!

....This table looks much more understandable than Table 12-2 which I eventually go to on page 160 (162 of pdf)

Thanks again.

oswalam
- 25th February 2013, 15:59
hey.... i am working on application note AN889...... open loop v/f control of pic16f777....... getting error as follows.......... ' Error - section '.udata_shr' can not fit the section. Section '.udata_shr' length=0x00000010' plz some one help with this error....Thanks

Acetronics2
- 25th February 2013, 16:53
hey.... i am working on application note AN889...... open loop v/f control of pic16f777....... getting error as follows.......... ' Error - section '.udata_shr' can not fit the section. Section '.udata_shr' length=0x00000010' plz some one help with this error....Thanks

looks you are asking questions about Microchip assembler aboard a Picbasic pro forum ...
sorry but you've hit the wrong door ...

Alain