[SOLVED] How to clear memory in mikrocontroller

Status
Not open for further replies.
I really don't understand, my setting is the same as shown but it still doesn't work.
This is your configuration. I decoded it to show that there's no problem of watchdog reset, as previously suspected by others.

But I didn't claim that your code "works". I already mentioned that it might be inappropriate for the CNC data you are receiving and asked for an example.
 


I just want to know why the pic is execute the program for 3 times without any reason! please all friend had this experience show me the way to solve this. actually I send string from computer contain 64 charter the values is only 1 and 0, after finished execution it must write back letter F to confirm the computer and request another string.
 

Mods please don't delete this post. The OP has requested for code and hence I am posting this project. The OP is using mikroC PRO PIC and hence I have modified his project and posting it.

The changes made are:

OP code used
Code:
UART_Read_Text()

function (non interrupt based) to receive serial data.

I am using a Serial receive interrupt to receive serial data. It receives 64 characters and then sets a flag and disables interrupts. The flag which is set is processFlag.

It is tested if this flag is set in main loop. If it is set then processing is done. The received ascii characters '0' and '1' in the array are converted to 0 and 1 integers and then assigned to PORTA with a delay of 50 ms after assigning each value. After all the 0 and 1 bits are sent to PORTA it prints 'F' on Serial terminal and then gets ready for next cycle.


In your original code this is the only mistake I found.

Code:
uart1_read_text(receive,'F',65);

It should be

Code:
uart1_read_text(receive,"F",65);

The delimiter F should be a string and not a charcater. The mikroC help files says so.
 

Attachments

  • CNC Driver.rar
    24.7 KB · Views: 120

It could also be a h/w issue. We know nothing about schematic and PCB layout. Probably, some capacitors missing. Or even whole schematic have to be reviewed.
 


it gives nothing output, you may look for the string I wanted to send to the pic.

- - - Updated - - -

It could also be a h/w issue. We know nothing about schematic and PCB layout. Probably, some capacitors missing. Or even whole schematic have to be reviewed.


please consider my schematic please
 

Try this new project. Delimiter is changed from 'F' to '\r'. In your mikroC USART Terminal do settings like shown in highlight. Send 64 1's and 0's (ascii characters) only. The USART Teminal will append \r at the end of the data.

Please draw the circuit (interfacing of CNC machine port to PIC) and scan it and post it here.

Edit:

Does your CNC Machine accepts data serially ? Is it only 1's and 0's ? Please provide the datasheet of your CNC Machine.
 

Attachments

  • CNC Driver Rev1.rar
    24.3 KB · Views: 117
  • CNC Data Sending.png
    43.1 KB · Views: 138
Last edited:

yes it repeating for 3 times!
Really hard to hear a clear answer. In post #25 you claimed no answer at all.

Anyway, did you already fix the character array overrun problem?
 

did you tried my improvement in the code is posted in #12? And please be clear actually what problem your facing? last posts depicts that you were facing problem in receiving chars and now you are saying the program runs three times? what is the problem actually?
 

yes I did, the code that you gave me can not compile
Code:
PIE1_bit=1
my problem is the pic is repeating the program for 3 times without any control. as the code I have shown. I send string from computer by serial port the string contain 65 character include "F" in the end of string is to tell pic that sending is finish. after pic execute program it send "F" back to computer to request next string. in this case I sent the first string pic executed send "F" back to computer, but it doesn't stop, it repeated for 3 times.
 

Add a semicolon.

Code:
PIE1_bit=1;


Maybe the CR + LF that your mikroC PRO PIC's USART Terminal is sending is causing the receive buffer to overflow and causing the problem. I can't guess. If PIC resets then buffer gets cleared and I don't know how it can run the data 3 times.

Did you try my project. If not, test it and reply.
 

it doesn't give any out put and computer doesn't receive anything.

 

Hi

Sorry, Please test the attached project. It will work.

Code:
RCIF_bit = 0;

was missing in the ISR.

Had to clear the RCIF bit to receive all characters.

Use mikroC PRO PIC's USART Terminal and send the data with CR (don't send LF or CR+LF). Only CR at the end of the data. No, F in the data.

Test it and reply.

- - - Updated - - -

In your mikroC PRO PIC's USART Terminal you have to check the "Append New Line" Check box. And also the option CR (0x0D). Then send 64 1's and 0's. it will work.

- - - Updated - - -

See attached images. It is working in Proteus.

- - - Updated - - -

it can not compile in PIE1_bit=1;

Use

Code:
PEIE_bit = 1;

- - - Updated - - -

Now I see. The Proteus Oscilloscope signal looks strange I sent 64 10 and it has to show signal like 10001000 but it is showing like 1010.

Why forum is updating the old post even after 1 hour of posting. Why it is not creating new post ?

- - - Updated - - -

There was a bug. Fixed it. Test the attached project (Rev3 Project). it will work fine. Now the signals on oscilloscope look fine.

This is the new fixed code in ISR.

Code:
if(receive[index - 1] == '\r') {

Instead of == I had used =.

In new code I have replaced for() loop inside while(1) with
Code:
while(receive[i] != '\r')

Now the signals are correct. it is like 10001000
 

Attachments

  • CNC Driver Rev2.rar
    24.5 KB · Views: 90
  • CNC Driver Simulation SS.png
    121.5 KB · Views: 152
  • CNC Driver USART Terminal.png
    55.1 KB · Views: 142
  • CNC Driver Rev3.rar
    51.2 KB · Views: 106
  • CNC Driver Simulation SS 2.png
    123.2 KB · Views: 156

Hi

Here is a better version of the project. Test it in hardware and reply. I have tested this in Proteus and it works fine. The changes made are Serial Interrupt is used to receive UART data and Timer Interrupt is used to send data to CNC Machine. All blocking codes are removed. You can do other things in while(1) loop if needed. This will not affect the functioning of the device.
 

Attachments

  • CNC Driver Rev6.rar
    88 KB · Views: 89
  • CNC Driver Proteus Simulation Screenshot.png
    134 KB · Views: 160
  • mikroC USART Terminal Screenshot.png
    140.3 KB · Views: 149
Thanks very much to every one it works, I change the 'F' to "F" in receive.
 

Nice to hear that its working but beware, sometimes it may don't work! The UART1_Read_Text don't work correctly sometimes. Instead use UART1_read as I suggested and receive all the data in array and then search for character F in received char array and do your control work. And no need to clear RCIF_bit as it clears in hardware as soon as you copy data from RCREG.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…