HOW to disable USART Interupt 16F688

General discussion on mikroPascal.
Post Reply
Author
Message
Llama
Posts: 9
Joined: 26 Sep 2008 00:25

HOW to disable USART Interupt 16F688

#1 Post by Llama » 18 Nov 2009 04:36

Hi All,
I am having trouble finding more hair to pull out :(

Pic :16f688,
Purpose of the program is to convert integer (from usart) value to step direction outputs to opperate a Gecko drive with stepper.

I have intefaced a couple of circuits via usart and have no issue with comms etc.

If I write a byte and recieve a byte on thePic I can write out of delphi at 15ms delays and the stepper responds very well doesnt loose steps is stable etc.

> value of 255 I need to write as a string and convert on PIC to integer. All is well with that.

However there is as I understand it an interrupt on the Usart_recieve_text on the pic that throws a spanner in the works and either hangs my PIC up or puts my stepper in continued loop. I am certain (I may very well be wrong) that this is the culprit, as if i write the values out the PC via hyper terminal OR increase my time delay on the timer in delphi the PIC has enough time to complete getting the old value to equal the new value before it is interupted.

So the BIG question how do we disable this interup? I have had a look at the 16f688 data sheet and see that the interrupt is RCIE. How do I set this to do what I want?

Thanks in advance!

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 18 Nov 2009 09:20

you better show some code, if you have not enabled this interrupt yourself it cannot be the guilty one as the ME Library's do not use interrupts.
Au royaume des aveugles, les borgnes sont rois.

Llama
Posts: 9
Joined: 26 Sep 2008 00:25

#3 Post by Llama » 18 Nov 2009 16:18

Hi JPC, thanks for the help here is the code

////INTEGER TO STEP DIRECTION CONVERSION////
///HARDWARE 16F688 4 MHZ CLOCK//////////////

program Integer_StepDir;

var

COMMAND:integer; ///WANTED POSITION
COMMAND2:integer; /// SAME AS ABOVE USED FOR CONVERSIONS

COMMANDSTR:STRING[5];/// WANTED POSITION (STRING)
DELIM:STRING[3]; //DELIMITER
MOTORPOS:integer; ///ACTUAL POSITION


PROCEDURE CW ; /// GO CLOCK-WISE
BEGIN
REPEAT
INC(MOTORPOS); ///INCREMENT ACTUAL POSITION COUNT
PORTC:=255; /// TURN ON PORT C FOR DIRECTION BIT
PORTA := not PORTA; ///PULSE PORT A'S STATE FOR STEP
Delay_us(500); /// DELAY
UNTIL MOTORPOS =COMMAND2; /// KEEP DOING UNTIL ACTUAL POS = WANTED POS
end;

PROCEDURE CCW ; /// SAME AS ABOVE JUST COUNTER CLOCK-WISE

BEGIN
REPEAT

DEC(MOTORPOS);
PORTC:=0;
PORTA := not PORTA;
Delay_uS(500);
UNTIL MOTORPOS =COMMAND2;
END;

PROCEDURE READWANTEDPOS; //// READ PROCEDURE
BEGIN
USART_READ_TEXT(COMMANDSTR,DELIM); //READ STRING
COMMAND:=STRTOINT(COMMANDSTR); //CONVERT STRING TO INTEGER
COMMAND2:=COMMAND // USED FOR AND MULIPLICATION SCALING
END;

begin
USART_Init(28800); ///INIT USART
CMCON0:=7; ///INIT COMPARATORS OFF
ANSEL:=%11110000; ///INIT ANALOG OFF
PORTA := 0; ///PORTA AS OUTPUTS
TRISA:= 0; ///INIT PORTA =0
TRISC:=%110011; ///INIT PORTC =0
COMMAND:=0; ///INITIAL VALUES
COMMAND2:=0; ///INITIAL VALUES
MOTORPOS:=0; ///INITIAL VALUES
DELIM:='EOT'; ///DELIMITER 'END OF TRANSMITTION'



while true do
begin

READWANTEDPOS;///READ WANTED POSITION

if COMMAND2 > MOTORPOS THEN // IF WANTED POS > MOTORPOS THEN CLOCK-WISE
CW

ELSE

if COMMAND2 < MOTORPOS THEn // IF WANTED POS > MOTORPOS THEN COUNTER CLOCK-WISE
CCW;

end;
end.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#4 Post by jpc » 18 Nov 2009 17:30

there is no sign of interrupt in your code, as Uart_read_text is a blocking call this cannot work , you should search forum for interrupt driven uart.
You migh also consider running the stepper as interrupt or ultimately both as you might want to add more to your code.
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “mikroPascal General”