CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Simple tones program is not working

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tonkostz



Joined: 07 May 2011
Posts: 40
Location: Bulgaria

View user's profile Send private message

Simple tones program is not working
PostPosted: Fri Oct 05, 2012 8:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 05, 2012 8:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 05, 2012 9:07 am     Reply with quote

I added the line SETUP_ADC_PORTS(NO_ANALOGS); and still no success.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Oct 05, 2012 9:32 am     Reply with quote

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?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group