View previous topic :: View next topic |
Author |
Message |
CMatic
Joined: 11 Jan 2012 Posts: 69
|
C program does not work after migrating PIC16F1825 |
Posted: Wed Oct 22, 2014 9:33 am |
|
|
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
|
|
|
CMatic
Joined: 11 Jan 2012 Posts: 69
|
C program does not work after migrating PIC16F1825 |
Posted: Thu Oct 23, 2014 10:36 am |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 23, 2014 11:22 am |
|
|
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: 19537
|
|
Posted: Thu Oct 23, 2014 12:00 pm |
|
|
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
|
|
Posted: Fri Oct 24, 2014 5:27 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Oct 24, 2014 5:50 am |
|
|
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: 19537
|
|
Posted: Fri Oct 24, 2014 8:25 am |
|
|
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
|
|
Posted: Fri Oct 24, 2014 9:07 pm |
|
|
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
|
|
Posted: Fri Oct 31, 2014 11:19 am |
|
|
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. |
|
|
|