View previous topic :: View next topic |
Author |
Message |
newbieToCCS Guest
|
PWM for PIC18F45K20 |
Posted: Fri Aug 01, 2008 5:04 am |
|
|
Hello
I have ccs 4.062, and have seen some strange things.
Firstly I am trying to use the inbuilt functions to activate a piezo buzzer, I have a prototype board which has a 16Mhz crystal and I am using H4 fuse so that I am running the device at 64Mhz I have the buzzer attached to pin B3 of the PIC which is the second ccp/pwm2 module. Everything else works except the buzzer
I have the following
Code: |
#include<18F45K20.h>
#fuses H4
#use delay(clock=64000000)
void main(void){
setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM Pin B3
setup_timer_2(T2_DIV_BY_16, 127, 1);
set_pwm2_duty(200);
while(1);
}
|
I expect the buzzer to be buzzing, have i got the duty cycle to high???
In addtion I tried it using my own register defines which is
Code: |
#include<18F45K20.h>
#fuses H4
#use delay(clock=64000000)
#include "PIC18F45K20_registers.h" // Holds register addresses
void main(void){
TRISB3 = 0;
CCP2CON = 0x0c; //0x0c /* PWM Mode, LSB 2 bits = 00 */
PR2 = 200;
CCPR2L = 0x00; // OFF
T2CON = 0x07;
CCPR2L = 0x64; // ON
}
|
both seem to fail please help.
In addition I am using ICD2 MPLab to program the device, However I can not debug the device and can only program
I have attached a zener Diode to the MCLR pin and that is working fine.
When I want to connect for example I get in debug mode
Quote: |
... Failed Self Test. See ICD2 Settings (status tab) for details.
|
when i try to program in debug mode only i get
Quote: |
ICD0083: Debug: Unable to enter debug mode. Please double click this message for more information.
|
please note I am sure that the board is powered and working..
From the MPLab icd2 settings tab status the following is showing
Target Vdd:- Pass
Module Vpp:- High
MCLR Gnd:- Pass
MCLR Vdd:- Pass
MCLR Vpp:- High
THe power tab shows
Target Vdd:- 3.44
Target Vpp:- 13.10
MPLab ICD 2 Vpp:- 13.26
As I said I can prgram the chip but can not debug mode, is there something i need to disable on MPLab?? I have asked MIcrochip they havent got back to me yet. |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Fri Aug 01, 2008 9:16 am |
|
|
OK, firstly for anyone who hasn't used a 'K' series PIC, he is talking about a zener on MCLR because the 'K' series require <9V on MCLR during programming.
Now, Pin B3 is not the default pin for CCP2, it is the alternate pin. (ie It can be multiplexed to B3, but it is not B3 by default). By default it is pin C1.
From data sheet:
Note 1: CCP2 multiplexed with RB3 when CONFIG3H<0> = 0
2: CCP2 multiplexed with RC1 when CONFIG3H<0> = 1
So, have you cleared this bit? |
|
|
newbieToCCS Guest
|
|
Posted: Fri Aug 01, 2008 9:24 am |
|
|
Hey elder
You have spotted the stupid mistake I didnt configure the multiplex PWM pin to output to pin_B3
In terms of CCS software config bits this is
Cant believe it took me all day to find this...
Cheers
PS: the other problem about debugging the PIC18F45K20 has not yet be solved when I do I will report back |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Fri Aug 01, 2008 9:56 am |
|
|
No longer a CCS problem so they prob won't want the other problem talked about here. I can tell you I just checked and ICD2 debug works on my 18F25K20 which is pretty much the same chip as yours. I'm using a zener too, can't remember what resistor is used with it though. I ran on internal osc at 16Mhz when testing debug. Good luck. |
|
|
mewbieToCCS Guest
|
|
Posted: Tue Aug 05, 2008 2:00 am |
|
|
Just a quick update Regarding the ICD2 and programming the PIC18F45K20 the problem is solved. Just needed to update to MPLab version 8.10 |
|
|
|