View previous topic :: View next topic |
Author |
Message |
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
programing problem porte | pic18f4550 | picc pcb 4.11 |
Posted: Thu Dec 20, 2012 8:35 pm |
|
|
Hello,
I wrote a code to run my servo and I defined two servo signals output in pins RE0 and RE1.
I run my program but the servo don't work in the two signals.
With the signal from RE0 it works fine but with RE1 there is a problem.
I checked my pic, it's fine there is nothing burn!
I tested my program in Isis too. The output it looks good but when I debug the program and I verify the porte register I noticed that the porte is coded by 9 bits and not 8 bits.
Code: |
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOMCLR
#USE DELAY(CLOCK=20MHZ, CRYSTAL)
#use rs232 (BAUD=9600, xmit=PIN_C6, rcv=PIN_C7)
/*#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)*/
//intenal regiter
#byte porta = 0xF80
#byte portb = 0xF81
#byte portc = 0xF82
#byte portd = 0xF83
#byte porte = 0xF84
#byte trisa = 0xF92
#byte trisb = 0xF93
#byte trisc = 0xF94
#byte trisd = 0xF95
#byte trise = 0xF96
//liste de capteur
#bit clg0=portd.3
#bit clg1=portd.2
#bit clg2=portd.1
#bit clg3=portd.0
#bit cld0=portd.4
#bit cld1=portd.5
#bit cld2=portd.6
#bit cld3=portd.7
//commande moteur
#bit sense_1=portb.3 //ccp1
#bit sense_2=portb.2 //ccp2
//externs
#bit epi=portc.0
#bit servo1=porte.1
#bit servo2=porte.0
#bit epic=porte.2
//nc
#bit a3=porta.3
#bit a4=porta.4
#bit a5=porta.5
#bit d4=portb.4
#bit d5=portb.5
#bit d6=portb.6
#bit d7=portb.7
int16 cycle=390;
int16 angle1=30; //min 20
int16 angle2=30;
int16 i=0;
//commande servomo-moteur
#INT_TIMER0 //each 51.2us
void servo() //20 => 1ms ; 39 => 2ms
{
// i++;
cycle++;
if (cycle == 391) {servo1=1;servo2=1;cycle=0;}
if (cycle == angle1) servo1=0;
if (cycle == angle2) servo2=0;
}
void main (){
//76543210
trisa=0b11111111; //1:in ; 0:out
//76543210
trisb=0b11110011;
//76543210
trisc=0b10111001;
//76543210
trisd=0b11111111;
//76543210
trise=0b11111000;
//pp
//
setup_timer_0(T0_INTERNAL|T0_DIV_1|T0_8_BIT); //625 by 32 -- 391 by 20 -- 156 by 8
set_timer0(0);
ENABLE_INTERRUPTS(INT_TIMER0);
//
ENABLE_INTERRUPTS(GLOBAL);
while(1){
epic=1;delay_ms(1000);epic=0;delay_ms(1000);
}
} |
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Dec 21, 2012 10:05 am |
|
|
Do you really need a 51.2us INT rate ???
This does not leave a lot of time for other functions to execute w/o stiff background interruption.
i mean there are only 256 I-cycles between interrupts and you need to subtract the #INT servicer setup/takedown code FROM that 256 total!!!
what do you expect to accomplish with THAT ??
By 'servo' I assume hobby RC servo with pulse timing control??
BTW: "SERVO" covers a lot more ground than just model control RC devices. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Dec 22, 2012 6:08 am |
|
|
I tried your program in the MPLAB simulator and there the correct values are written to the output registers (I didn't check actual outputs).
I tested with PCH v4.140
This is not the correct version number of your compiler. A version number always has 3 numbers after the dot, like: 4.123
Also, PCB is the compiler for the PIC12 processors, not for your PIC18. For the PIC18 it should be PCH, or a bundled version like PCWH.
Another comment is to post as short code as possible, now there are a lot of unused code lines. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Dec 22, 2012 8:51 am |
|
|
I suggest he looks at the 'next door' thread. "IO problems". I'd suspect he might well have the RMW problem, depending on what load is on the pins....
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Dec 23, 2012 7:01 am |
|
|
Ttelmah wrote: | I suggest he looks at the 'next door' thread. "IO problems". I'd suspect he might well have the RMW problem, depending on what load is on the pins.... | I expect you are right!
I always use the CCS output functions so this slipped my mind, but the RMW problem is the reason why Microchip introduced the port latch register. Instead of directly writing to the port register you should write to the latch register. Try replacing Code: | #byte porte = 0xF84 | by: Code: | #byte porte = getenv("SFR:LATE") |
|
|
|
|