It is currently 27 Jun 2017 17:15

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 19 Jun 2017 03:28 
Offline

Joined: 05 Oct 2016 12:45
Posts: 2
I am using 25% of RAM and 61% of ROM for a PIC16F1829 project. Since the programm is growing larger and larger i am getting more and more confusing problems in my code. But I am not getting any errors from the compiler.

However I think I have a problem, where my variables are overwritten by other variables or data. But I dont know why. Variables that keep the the elapsed time (counting from 0) are extremely huge and other variables are affected as well.

I know that there are some issues with the PIC16 family but I dont understand what I am doing wrong here.

For example this simple code in my project does not work as expected:

The main routine calls the procedure 'SendProtocol' with the parameter 0 or 1. The local parameter 'direction' in the procedure 'SendProtocol' is used by both 'select case' statements within the procedure. The first 'select case' statement works but then the value of 'direction' changes from 0/1 to decimal 45 and the second select case statement does not work. The parameter 'direction' is at RAM adress 0x00D1 (according to the statistics window in the editor). It seems that the conversion function 'LongWordToStr(...)' affects the 'direction' parameter. But why ?

sub procedure SendProtocol(dim direction as byte)     ' 0 = open, 1 = close

 select case direction

   case 0
   txt = "---------OPENING PROTOCOL---------"
 
   case 1
   txt = "---------CLOSING PROTOCOL---------"
 
 end select

 UART1_Write_Text(txt)
 UART1_Write(13)
 UART1_Write(10)
 UART1_Write(10)
 
 select case direction

   case 0                                                                   
   UART1_Write_Text("OPEN ACTION TIME:      ")
   LongWordToStr(open_time_needed,txt)
   UART1_Write_Text(txt)                                         
   UART1_Write_Text("ms")
   UART1_Write(13)
   UART1_Write(10)

   case 1                                                                   
   UART1_Write_Text("CLOSE RESPONSE TIME:   ")
   LongWordToStr(close_time_needed,txt)
   UART1_Write_Text(txt)                                         
   UART1_Write_Text("ms")
   UART1_Write(13)
   UART1_Write(10)

 end select

 end sub


main:
  Init()                                                                             ' Initialising
  SendLogging()                                                                 ' send Logging
 
 while (TRUE)                                                                    ' Endless loop
   OpenControl()
   SendProtocol(0)                                                              ' Send Protocol direction OPEN
   CloseControl()
   SendProtocol(1)                                                              ' Send Protocol direction CLOSE
 wend


Top
 Profile  
 
PostPosted: 19 Jun 2017 10:00 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3718
Location: Nieuwpoort, Belgium
Can you show the declaration of the variables?

Perhaps also this can help: https://libstock.mikroe.com/projects/view/1068/article-ram-corruption-reasons-in-mp-and-mb.

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
PostPosted: 19 Jun 2017 10:53 
Offline

Joined: 05 Oct 2016 12:45
Posts: 2
Dany wrote:
Can you show the declaration of the variables?

Perhaps also this can help: https://libstock.mikroe.com/projects/view/1068/article-ram-corruption-reasons-in-mp-and-mb.


Hello Dany and thanks for your fast response. Oh oh... I was very lazy with the var declarations. I assigned a string with more than 10 bytes to a string var with only 10 bytes. The document in your link had all the information i needed. Thanks a lot for your help and sorry for the confusion. Hope it works now.

Holger


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: paolo tacconi and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: