View previous topic :: View next topic |
Author |
Message |
tonkostz
Joined: 07 May 2011 Posts: 40 Location: Bulgaria
|
Simple tones program is not working |
Posted: Fri Oct 05, 2012 8:28 am |
|
|
I tested this program with PIC12F683 the day before yesterday and eveything was fine. Now i'm trying to make it work for PIC16F684 with no success at all. There is nothing at the C2 output pin. Compiler version is 4.128. Clock is the 4MHz internal oscillator. The song is not happy birthday - only the name is the same.
Code: |
#include <16f684.h>
#fuses INTRC_IO,NOWDT,NOMCLR
#use delay(internal=4000000)
#include <tones.c>
#define SIZE 35
const struct note
{
long tone;
long length;
}
happy_bday[SIZE] = {
D_note[3],20, E_note[3],20, F_note[3],20, G_note[3],20, A_note[3],20};
void main(void)
{
int i;
while(TRUE)
{
for(i=0; i<SIZE; ++i)
{
generate_tone(happy_bday[i].tone,happy_bday[i].length);
delay_ms(40);
}
}
}
|
tones.c is the file from the PICC drivers folder.
output pin is C2.
here it is:
Code: |
#define TONE_PIN PIN_C2
|
+++++++++++++++++++++++++++
Tones.c deleted. Only changes kept.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers
You know the rules.
- Forum Moderator
+++++++++++++++++++++++++++ |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Oct 05, 2012 8:58 am |
|
|
On the PIC processors often the I/O pins are shared between many functions. Check the datasheet. For example your C2 pin can be a standard I/O pin, Analog input or Enhanced CCP output. The I/O pin can only service one of these functions at a time.
Now check Table 4.2 of the datasheet and you will see that by default all analog input pins are activated. This means your digital output is disabled.
Disable the analog ports by adding the following line to the start of your main: Code: | SETUP_ADC_PORTS(NO_ANALOGS); |
|
|
|
tonkostz
Joined: 07 May 2011 Posts: 40 Location: Bulgaria
|
|
Posted: Fri Oct 05, 2012 9:07 am |
|
|
I added the line SETUP_ADC_PORTS(NO_ANALOGS); and still no success. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Oct 05, 2012 9:32 am |
|
|
ECCP on the RC2 pin is disabled by default, so that can't be the problem.
Two problems in your code however:
1) The code was designed for 20MHz. You are running at 4MHz but didn't adjust the tone frequency calculations.
2) You have defined Size as 35 but only 5 tones are defined. This will give garbage output for tones 6 to 35.
Are you sure the processor is running? What happens when you try a blinking LED test program? |
|
|
|