Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problems with Fusing statement

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
madhav1080

Bascom Member



Joined: 06 Jan 2008
Posts: 41
Location: Hyderabad

india.gif
PostPosted: Sat Nov 01, 2008 2:21 am    Post subject: Problems with Fusing statement Reply with quote

Hello

I have observed problems when using the Fusing command. Earlier the same code was working fine. I have observed that the microcontroller either hangs or behaves in a very erratic manner.

I have used the fusing statement to trim the Single values returned from a function that reads the ADC. I have observed that when ever a negative value is returned ( My ADC is MAX127, bi-polar AD converter) the value from fusing simply disappears. In this project the microcontroller is M128

In another project, based on M32, when using fusing with uni-polar data (0-2V) I observe that the controller get reset frequently, I have changed the stack settings yet the problem persists.

This problem seems to have appeared only in the current version, oh yes, this problem occurs only when other interrupts occur periodically, like the timer, INT0, INT1 or the serial .

Did any one else observe these issues.

Regards

Madhav
Back to top
View user's profile Visit poster's website
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sat Nov 01, 2008 6:58 am    Post subject: Reply with quote

Processor resets are usually caused by stack crashes, especially in otherwise working code.
Fusing certainly uses string functions, so you must have sufficient stack and frame space. You dont say whether the problem is now worse after updating the compiler, or just after you changed something else ?
Suggest you post the code for the routine reading the ADC and converting to single.
You are not by any chance calling the ADC routine or fusing statement from within an IRQ ? If so, be aware that uses a LOT more stack space - 33 bytes extra at least.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
madhav1080

Bascom Member



Joined: 06 Jan 2008
Posts: 41
Location: Hyderabad

india.gif
PostPosted: Tue Nov 18, 2008 10:10 am    Post subject: Reply with quote

Sorry, was away, hence couldn't reply...

The problem is very much there... I have attached the code used in my program, no the ADC is not called in ISR, I have added sufficient stack, still I have the same problem.

I have built a 128 channel Data Aquisition system based on AVR ATMEGA128 & MAX1270, Typically the system has 8 cards each with two Max1270 chips. A master collects the data from each of the card by addressing the specific card, the data on the slave card is stored in integer form, i.e data read from MAX1270. Master collects this data converts into a float value based on the transfer function of MAX1270, I have no problem when I directly display the float data, the moment I use fusing statement, garbage data appears, this is not specific to AVRM128, on other processors too the same was observed.


Code:
 
'###########################################################################
'                      Data Aquisition System Master Card
'###########################################################################
$crystal = 14746000
$baud = 115200
$baud1 = 115200

Open "COM1:" For Binary As #1
Open "COM2:" For Binary As #2

Config Pind.0 = Output
Portd.0 = 1

Config Portd.1 = Output



Config Scl = Porte.6                                        ' IIC Serial Clock Line
Config Sda = Porte.7                                        ' IIC Serial Data line

Config Porta = Output
Config Portc = Input

Config Portg.0 = Output
Config Portg.1 = Output
Config Portg.2 = Output

Portg.0 = 1
Portg.1 = 1
Portg.2 = 1


Config Timer0 = Timer , Prescale = 64

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                          IIC BUS Variables
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim Waddress As Byte , Raddress As Byte , M_add As Word , Count As Integer
Dim Flg As Bit , Rxbyte As Byte




Dim Ch0vlt As String * 6 , Ch1vlt As String * 6 , Ch2vlt As String * 6 , Ch3vlt As String * 6
Dim Ch4vlt As String * 6 , Ch5vlt As String * 6 , Ch6vlt As String * 6 , Ch7vlt As String * 6
Dim Ch8vlt As String * 6 , Ch9vlt As String * 6 , Ch10vlt As String * 6 , Ch11vlt As String * 6
Dim Ch12vlt As String * 6 , Ch13vlt As String * 6 , Ch14vlt As String * 6 , Ch15vlt As String * 6

Dim Chno As Byte , Cab As Byte , Smplno As Byte , Termin As Byte , Crdcnt As Byte


Declare Sub Aquire()
Declare Sub Getdata()
Declare Sub Smplbus()



Enable Interrupts
On Timer0 Tmr0isr

Crdcnt = Pinf And &H0F
Waitms 5
Termin = 0
Count = 0


Call Aquire

Do
   If Count >= 10000 Then
      Stop Timer0
      Call Getdata
      If Termin = 1 Then
         Termin = 0
         Count = 0
         Call Aquire
      End If
   End If
Loop
Print #1 , "This is it"
End


Sub Aquire()
   Enable Timer0
   Load Timer0 , 73
   Start Timer0
End Sub

Sub Getdata()
   Local Pdd As Word
   Local Pdat As Byte
   Local Chadd As String * 2
   Local Devid As Byte
   Cab = 0

   Do
      Portd.1 = 1
      Chadd = Lookupstr(cab , Scrdadd)
      Portg.0 = 1
      Portg.1 = 0
      Ddrc = &H00
      Portc = &HFF
      Porta = Hexval(chadd)
      If Pinc = Hexval(chadd) Then
         For Smplno = 1 To 48
            For Chno = 0 To 15
               Call Smplbus
            Next
            Print #1 , Ch0vlt ; "," ; Ch1vlt ; "," ; Ch2vlt ; "," ; Ch3vlt ; "," ; Ch4vlt ; "," ; Ch5vlt ; "," ; Ch6vlt ; "," ; Ch7vlt ; ",";
            Print #1 , Ch8vlt ; "," ; Ch9vlt ; "," ; Ch10vlt ; "," ; Ch11vlt ; "," ; Ch12vlt ; "," ; Ch13vlt ; "," ; Ch14vlt ; "," ; Ch15vlt
            Print #2 , Ch0vlt ; "," ; Ch1vlt ; "," ; Ch2vlt ; "," ; Ch3vlt ; "," ; Ch4vlt ; "," ; Ch5vlt ; "," ; Ch6vlt ; "," ; Ch7vlt ; ",";
            Print #2 , Ch8vlt ; "," ; Ch9vlt ; "," ; Ch10vlt ; "," ; Ch11vlt ; "," ; Ch12vlt ; "," ; Ch13vlt ; "," ; Ch14vlt ; "," ; Ch15vlt
         Next
      End If
      Wait 1
      Print #1 , "Card:" ; Cab ; " scan complete"
      Cab = Cab + 1
   Loop Until Cab = Crdcnt
   Termin = 1
   'Print #1 , "This is the end of Scan of 8 cards"
   Portd.1 = 0
   Waitms 25
End Sub


Sub Smplbus()
   Local Volt As Single
   Local Pdata As Word
   Local Pdd As Word
   Local Pl As Byte
   Local Ph As Byte
   Portg.0 = 0
   Portg.1 = 0
   Portg.2 = 1
   Waitus 25
   Pl = Pinc
   Waitus 25
   Portg.1 = 1
   Waitus 25
   Ph = Pinc
   Waitus 25
   Portg.2 = 0
   Portg.1 = 1
   Portg.0 = 1
   Ddrc = &H00
   Portc = &H00
   Pdata = Makeint(pl , Ph)
   Pdd = Pdata And 2048
   If Pdd = 2048 Then
      Pdata = Pdata - 1
      Pdata = Pdata Xor &H0FFF
      Volt = Pdata * 0.00244140625
      Volt = Volt * -1
   Else
      Volt = Pdata * 0.00244140625
   End If
   Select Case Chno
      Case Is = 0:
         Ch0vlt = Fusing(Volt, "#.###")
      Case Is = 1:
         Ch1vlt = Fusing(volt , "#.###")
      Case Is = 2:
         Ch2vlt = Fusing(volt , "#.###")
      Case Is = 3:
         Ch3vlt = Fusing(volt , "#.###")
      Case Is = 4:
         Ch4vlt = Fusing(volt , "#.###")
      Case Is = 5:
         Ch5vlt = Fusing(volt , "#.###")
      Case Is = 6:
         Ch6vlt = Fusing(volt , "#.###")
      Case Is = 7:
         Ch7vlt = Fusing(volt , "#.###")
      Case Is = 8:
         Ch8vlt = Fusing(volt , "#.###")
      Case Is = 9:
         Ch9vlt = Fusing(volt , "#.###")
      Case Is = 10:
         Ch10vlt = Fusing(volt , "#.###")
      Case Is = 11:
         Ch11vlt = Fusing(volt , "#.###")
      Case Is = 12:
         Ch12vlt = Fusing(volt , "#.###")
      Case Is = 13:
         Ch13vlt = Fusing(volt , "#.###")
      Case Is = 14:
         Ch14vlt = Fusing(volt , "#.###")
      Case Is = 15:
         Ch15vlt = Fusing(volt , "#.###")
   End Select
End Sub





Tmr0isr:
   If Pind.0 = 0 Then
      Set Portd.0

   Else
      Incr Count

      Reset Portd.0
   End If
   Load Timer0 , 73
Return

Srl0isr:
   Rxbyte = Udr
Return

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'                                Data Tables
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Scrdadd:
Data "81" , "82" , "83" , "84" , "85" , "86" , "87" , "88"

Close #1
Close #2

 
Back to top
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Tue Nov 18, 2008 10:46 am    Post subject: Reply with quote

Hi,

Not really a solution but some hints,
Calculation can better be done with the same type of variables. For example change PDATA to single.
And finally a single can be 10 characters long, but you dimension all your Chxvlt As String * 6. Try dimming them larger, you never know what Bascom needs under the hood.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue Nov 18, 2008 9:50 pm    Post subject: Reply with quote

I agree with Evert. Do a single Fusing conversion from Volt to a temp string, dimensioned at least 10 characters. Then do a Left on that to ensure its only 6 chars long, and then assign it to each of the Ch(n)vlt strings, if you really must have 10 different variables and all the select case stuff. ( Why not a string array ? )
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum