View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
16F1936 misunderstandings with pins on port C |
Posted: Sun Jul 01, 2012 7:44 am |
|
|
Hello
I have PIC16F1963 with compiler version PCWHD 4.130, MPLAB V8.66 and programmer PICkit3.
Problem is next: when I want to to make all pins "output high" I have some pins in logical 1 and some pins logical 0.
C0 is 1
C1 is 0
C2 is 1
C3 is 1
C4 is 1
C5 is 1
C6 is 0
C7 is 1
Hardware powered with 4.47V (err+/-1%)
and on every output I have 1K load to GND.
My code example is:
Code: |
output_high(PIN_C0);
output_high(PIN_C1);
output_high(PIN_C2);
output_high(PIN_C3);
output_high(PIN_C4);
output_high(PIN_C5);
output_high(PIN_C6);
output_high(PIN_C7);
|
I try with:
Code: | output_c(0b11111111); |
but results are the same.
I changed PIC with another, but results are the same.
Regards |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 01, 2012 8:40 am |
|
|
You're only showing us part of your code.
All the pins have other functions besides general purpose I/O. Check with the data sheet that these are turned off.
Also check that status of TRISC and LATC, and that you have not got S/C to GND on pins C1 and C6.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Jul 01, 2012 9:49 am |
|
|
Now I post my code
Code: | #include <16F1936.h>
#device *=16
#device adc=8
#FUSES WDT //Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_NOSL //Watch Dog Timer, disabled during SLEEP
#FUSES PUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PROTECT //Code protected from reads
#FUSES CPD //Data EEPROM Code Protected
#FUSES WRT //Program Memory Write Protected
#FUSES PLL_SW //4X HW PLL disabled, 4X PLL enabled/disabled in software
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(int=8M)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8,stream=PORT1,stop=1,ERRORS)
#use fast_io(C)
#define IC3_SD PIN_C1
#define IC3_IN PIN_C0
#define IC4_SD PIN_C7
#define IC4_IN PIN_C6
#define IC5_SD PIN_C3
#define IC5_IN PIN_C2
#define NEON PIN_C4
#define MOTOR PIN_C5
#RESERVE 0x020:0x076 //stack0.1 cu 87 byti
#RESERVE 0x07B:0x07F //stack0.2 cu 5 byti
// 0x077-0x07A 4 byti rezervati de compilator
#RESERVE 0x0A0:0x0EF //stack1 cu 80 byti
#RESERVE 0x120:0x16F //stack2 cu 80 byti
#RESERVE 0x1A0:0x1EF //stack3 cu 80 byti
#RESERVE 0x220:0x26F //stack4 cu 80 byti
#RESERVE 0x2A0:0x2EF //stack5 cu 80 byti
//#RESERVE 0x320:0x320 //stack6 cu 16 byti
//restu stack 7-31 cu 0 byti
int8 V_PR1=0,V_PR2=0; //vitezele de rulare progrm
#BYTE V_PR1 = 0x07B //
#BYTE V_PR2 = 0x07C
int8 T0=0; //valoare timer 0
int8 TIMER1_LED=0; //timer led la spam
int8 BLOC1_TIMER1=0; //blocheaza timerul 1
int1 BUTON=0;
void main()
{
setup_adc_ports(sAN13);
setup_adc(ADC_CLOCK_DIV_32);
setup_lcd(LCD_DISABLED);
setup_wdt(WDT_ON);
setup_wdt(WDT_2S); //
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_bit); //13.1 ms overflow
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //65.5 ms overflow
setup_timer_2(T2_DIV_BY_16,255,1); //4.0 ms overflow, 4.0 ms interrupt
setup_timer_4(T4_DISABLED,0,1);
setup_timer_6(T6_DISABLED,0,1);
setup_ccp2(CCP_PWM|CCP_SHUTDOWN_AC_H|CCP_SHUTDOWN_BD_H);
setup_ccp3(CCP_PWM|CCP_SHUTDOWN_AC_H|CCP_SHUTDOWN_BD_H);
setup_ccp5(CCP_PWM);
set_pwm2_duty((int16)0);
set_pwm3_duty((int16)0);
set_pwm5_duty((int16)0);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_PLL_OFF,0);
port_E_pullups(0xFF);
SET_TRIS_C(0x00); //tot canalul C este iesire
// output_c(0b11111111); //
output_high(PIN_C0);
output_high(PIN_C1);
output_high(PIN_C2);
output_high(PIN_C3);
output_high(PIN_C4);
output_high(PIN_C5);
output_high(PIN_C6);
output_high(PIN_C7);
delay_ms(100);
for(;;)
{
restart_wdt();
//SLEEP();
// output_high(PIN_C0);
// output_high(PIN_C1);
// output_high(PIN_C2);
// output_high(PIN_C3);
// output_high(PIN_C4);
// output_high(PIN_C5);
// output_high(PIN_C6);
// output_high(PIN_C7);
} |
Regards |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 01, 2012 11:20 am |
|
|
I don't have a PIC16F1936 to try.
However you are making several fundamental errors.
(1) You should not need to use fast_io. Most of the time the CCS compilers take care of this for you.
(2) Without fast_io you then don't need to write to TRISC.
You are setting up RS232. RC6 is the USART TX. Could be a source of conflict.
You are also setting up CCP2 which uses RC1 as CCP2/P2A. Could be another problem.
Have you checked the status of the TRISC and LATC registers?
You've got a problem with PORTC. So get rid of all the other stuff and concentrate on the problem in hand. Work on the KISS principle.
Mike
PS Page 143 of the data sheet gives a summary of all the registers associated with PORTC. It's fairly formidable. |
|
![](templates/subSilver/images/spacer.gif) |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Jul 01, 2012 12:21 pm |
|
|
Dear Mike
I have another problem like logical problems.
I will try with PCW 4.084 and simulate.
On paper and when I read code work's fine... In my mind.
#1 I use fast_io because I need speed in normal mode. I have speed 47Hz and in fast mode I have speed 98Hz.
I try without fast mode and results are the same...
#2 RC6 USART TX is not active /declared so it must not be a conflict
CCP2 is compare/capture so is for input signal or PWM output, in my case is use for output mode so again is no conflict. Of course I try in normal mode but not works.
This pin's works fine as input or output, high or low.
I'm starting to think this could be a bug. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sun Jul 01, 2012 1:58 pm |
|
|
If you say you're still having a problem setting/resetting pins on port C, go back to basics.
Get rid of all the timers,pwm,rs232,LCd,etc.
Use standard I/O NOT fast I/O so the compiler handles the ddrs.
Write a simple program to toggle portc.0 that has an LED and 1Kr on it,at say 1/2second rate. Confirm that works. Then copy the program, edit to use portC.1.compile,test,confirm.Do this for all 8 pins on the port.
Once you've confirmed all pins toggle then you know there's nothing wrong with the basic code.Build upon that until you fail, then go back one step and compare the programs to see what is different.That will show you the problem area.
hth jay |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jul 01, 2012 2:20 pm |
|
|
Quote: | Of course I try in normal mode but not works. | This does not help, it's too vague, you're making us guess. You need to tell us what is/isn't happening.
Temtronic and I are saying the same thing, (albeit in different ways).
Get PORTC to work correctly first, then progress.
Quote: | I'm starting to think this could be a bug. | Yes, it's possible. At this stage you can't prove it. You must simplify.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Jul 01, 2012 3:31 pm |
|
|
At this moment I have 2 problems:
first
with port C and I will try like I said with older version...
second
logical programming.
Before to post here I check in normal mode with simplest way.
I need 3-4 day's and after that I will post solution/decision that I find.
At this moment in my opinion is bug and solution is with change device.
Best wishes.... |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Jul 02, 2012 3:42 am |
|
|
RC1 is the output of CCP2 in PWM mode, and RC6 is the output of CPP3 in PWM mode. You are using both in PWM mode, these will override the use of the bits as general IO.
Try not setting the CCPs as PWMs and tell us what happens to your outputs.
Also be aware that just because an output is at the logic level you expect, that doesn't guarantee its doing what you expect... Put another way, if the PWMs are overriding RC1 and RC6, then if they happened to have been high rather than low, you would not necessarily have noticed anything was wrong.
RF Developer |
|
![](templates/subSilver/images/spacer.gif) |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Jul 02, 2012 9:07 am |
|
|
Yes Developer
This was the problem.
I disabled all CCP and now works well.
(I test the wizards and was my fault of configuration , by clicking on it).
Thank you.
PS: You saved my 2 days of work + other 3 days to develop new hardware.
Regards |
|
![](templates/subSilver/images/spacer.gif) |
|