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

C program does not work after migrating PIC16F1825

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



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

C program does not work after migrating PIC16F1825
PostPosted: Wed Oct 22, 2014 9:33 am     Reply with quote

C Program does not work when ported from PIC16F688 to PIC16F1825
I've been working on a CCS C program which read temperature from DS18B20 device and displays it to the LCD using sprintf statement. While my program works like a charm on PIC16F688 but once I upgrade the chip to PIC16F1825 it seems to crash when reading the temperature from DS1820.
Code:

void DisplayLCD(void)
{
static char temp_str[20];
static float temperature;
temperature = ds1820_read();  <<-----This is where it seems to fail.
temperature = (temperature* 0.0625*9/5)+32; // Deg F;
sprintf(temp_str,"%2.1f",temperature);
lcdStr(temp_str,4);//Degree F
}

If I replace this statement with "temperature = -4.75;"
Then the LCD displays the temperature correctly. The DS1820 device is connected to PortA pin A2.
Any ideas or pointers would be very helpful, thankyou.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 22, 2014 9:50 am     Reply with quote

That's the T0CKI pin. This looks like the old OPTION register biz again.
See this recent thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=53002
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

C program does not work after migrating PIC16F1825
PostPosted: Thu Oct 23, 2014 10:36 am     Reply with quote

I have used the Set_Option() to set the T0CKI disabled. And in addition I also disabled all Alternate Port A pin functions such as Analog functions like AD, CAP SENSE, etc. But still it does not work. I am really scratching my head Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 23, 2014 11:22 am     Reply with quote

Check if you can blink an LED on pin A2. That will tell you if the pin is
working. (Temporarily disconnect the ds18b20 for this test).

Or, test your program on another pin.
Ttelmah



Joined: 11 Mar 2010
Posts: 19561

View user's profile Send private message

PostPosted: Thu Oct 23, 2014 12:00 pm     Reply with quote

Are you running the same clock rate on both processors?.
If not, have you actually done the old 'flash an LED' test, to verify the chip actually is running at the speed you think?.

Have you verified that A2, is working as a normal pin?.
I see PCM_programmer said exactly the same thing on the pin question.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Fri Oct 24, 2014 5:27 am     Reply with quote

LED Pin test was an "eye opener" as simple as it sounds but I had to breadboard a new PIC16F1825 and connect an LED & resistor to pin A2. It turns out that there are two things about pin A2. First, the datasheet shows that A2 is Schmit Trigger not TTL logic? While all the other Port A pins are TTL (seems to me like a Microchip typo). And second, I found out that the LED will blink twice and then shut off because of the Port A Interrupt-on-Change ISR.

And while the LED test is now working great, pin A2 is still not working as an input for the DS18B20 chip.

- For the "Same Clock" on both chips....Yes, I am running same 4Mhz on both chips. If you both can think of any others please do let me know and thank you. I will continue to try other features and report back.
temtronic



Joined: 01 Jul 2010
Posts: 9253
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 24, 2014 5:50 am     Reply with quote

just downloaded the datasheet.....

That pin is muxed with NINE peripherals !

I'm thinking you haven't disabled all of them ? YOU must configure it the way YOU want,as the 'defaults' never seem to be 'correct'.

Please post your complete 1Hz LED test code.

The more eyes on the code, the faster someone can spot what might be the problem.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19561

View user's profile Send private message

PostPosted: Fri Oct 24, 2014 8:25 am     Reply with quote

The Schmitt levels could well be part of the problem with trying to use it on a single wire device.
Microchip on a lot of their later devices have the INT input pin using Schmitt levels to reduce the chances of noise triggering an interrupt.
The interrupt on change should not interfere with a flash an LED test. Post the code.
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Fri Oct 24, 2014 9:07 pm     Reply with quote

I like both your ideas and I am working on configuring the 9 peripherals exactly the way I want and shutting the rest. I will report back to you very soon. Thanks
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Fri Oct 31, 2014 11:19 am     Reply with quote

The problem is now resolved. So as promised, here is what worked on making the PIC16F1825 pin A2 work with DS18B20.

- The old PIC16F688 chip had the Interrupt-On-change on PortA. This interrupt was not correct for the PIC16F1825 because the correct configuration for the '1825 requires that IOCIE bit be set.

- The pullup resistor on DS18B20 DQ pin was incorrect, when changed to 4.7K it initialized properly, by checking on the logic analyzer.

- getenv("SFR:ANSELA") was used to check the Analog pin settings for PORT A.

Now my program is working and thanks again for all your tips and clues.
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