View previous topic :: View next topic |
Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 167
|
PORTC does follow LATC |
Posted: Wed Jan 10, 2018 12:55 pm |
|
|
Simple issue: Can't set PIN_C1 low. LATC bit 1 follows code, but PortC bit 1 can never be cleared. TRIS register is correctly set to 0 (an output). Watching registers in CCS IDE and watching pin on O'scope.
Output used as general I-O. Connected to a motor driver input pin.
Anyone see something that i don't?
Thanks!
Processor- PIC16F1787
IDE- CCS
Compiler PCWH 5.071
Code: |
//=============================================================================
void main()
{
//pwm_off(); //all PWM channels off
output_bit (PIN_C1, 0);
output_bit (PIN_C1,1);
//Ramp_Drive_Motor (500);
while(TRUE)
{
delay_us(1);
}
}
//=============================================================================
|
Code: |
.h file:
#include <16F1787.h>
#device ICD=TRUE
#use delay(clock=4000000)
#use pwm(output=PIN_E0, timer=2, frequency=1kHz, duty=0, stream= Drive) //CCP3 Drive PWM
#define Green_LED PIN_D1 //green diag LED
#define Red_LED PIN_D0 //red diagnostic LED
#define Steer_IN1 PIN_C2 //steer driver in1
#define Steer_IN2 PIN_C1 //steer driver in2
//CONSTANTS
//steer motor direction
#define Brake 0 //directs steering motor to brake
#define Clock 1 //directs steering motor to turn clockwise
#define Counter_Clock 2 //directs steering motor to turn counter-clockwise
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 10, 2018 1:35 pm |
|
|
Quote: | void main()
{
//pwm_off(); //all PWM channels off
output_bit (PIN_C1, 0); // *** Set Pin C0 low for 1 us
output_bit (PIN_C1,1); // *** Then set it high
//Ramp_Drive_Motor (500);
while(TRUE)
{
delay_us(1);
}
}
|
Your program will only clear pin C1 for a microsecond.
Then you set it high. You wouldn't see it cleared with that test program. |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Wed Jan 10, 2018 2:17 pm |
|
|
Hi PCM:
No, I used break points on these two lines and stepped through each. Believe me, PORT pin C1 will not clear. LATC bit 1 does change states, however.
Any other suggestions?
Thanks! |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Wed Jan 10, 2018 2:31 pm |
|
|
Solved--Kind of.
Wasn't the PIC or code at all. For some reason INPUT2 on a Infineon TLE5205-2G has something pulling its input up to 5 volts HARD! Guess it's Infineon's issue.
Thanks! |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
Pin_C1 sink current |
Posted: Wed Jan 10, 2018 3:00 pm |
|
|
I'm back, sorry...
Looks like the PIC may not be able to sink any current on PIN_C1. I can pull this pin low successfully using a milliamp meter which read about 5uA.
Is there any reason i shouldn't be able to pull 5uA to ground with a PIC16F1787? No significant current requirements on any port C pins.
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Wed Jan 10, 2018 3:13 pm |
|
|
Could have been damaged if it has been shorted to 5v....
However general rule, always make sure every peripheral on the pin is disabled. So the PSMC controller, timer 1 oscillator, and CCP2. |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Wed Jan 10, 2018 3:23 pm |
|
|
Hello Ttelmah:
I have two prototypes, professionally built and they look good and perform the same. No inadvertent wrong connections placed on C1. I think I have all the peripheral disabled on C1. I am using CCP3 and timer2. I don't know how to disable the secondary oscillator or PSMC, they were never enabled. Looks like the PIC should default with peripheral off unless specifically enabled.
I am going to run-down all the peripherals.
Thanks Ttelmah! |
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Wed Jan 10, 2018 3:27 pm |
|
|
This must be it. Microchip data sheet says (13.7.6) PSMC1B and CCP2 have priority over general IO. Now, how do you cut both off?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Thu Jan 11, 2018 1:39 am |
|
|
The PSMC, is meant to be disabled by default. However if something has resulted in anything being written to the PSMC1OEN register it could be acting.
Code: |
SETUP_CCP2(CCP_OFF); //disables the CCP
PSMC_PINS(1,FALSE); //de-select PSMC1 from driving any pins
|
|
|
|
JerryR
Joined: 07 Feb 2008 Posts: 167
|
|
Posted: Thu Jan 11, 2018 6:16 am |
|
|
Ttelmah:
Thanks! Yes, I just fixed the issue by both the "higher priority" peripherals. I believe CCP2 was responsible for "blocking" PIN_C1. I can't understand why the peripheral was active given my code,and why general IO doesn't rank higher in priority.
You were also good enough to answer a recent "SOS" regarding MPLAB IDE not working with CCS Compiler and Microchip debugger on a single PC. Still haven't figured that one out, but my current set-up on the PC uses CCS IDE and one of their debuggers. I LIKE CCS IDE so I'm happy for the change.
Thanks you so much for all you do to help others in the group through tough problems.
Best regards |
|
|
|