Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

naming not accepted by compiler ? - Solved by $sim removed f

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 74
Location: Aachen

germany.gif
PostPosted: Thu Oct 01, 2020 2:31 pm    Post subject: naming not accepted by compiler ? - Solved by $sim removed f Reply with quote

Dear All,
for an existing application I wanted just to add the functionality that a LED will be turned on as an indicator of a state in the device.
I did the testing in the device circuit and later also in the evaluation board.
I did a small program just to see if the programming/syntx is correct.
Code:

$lib "mcs.lbx"
$regfile = "m328pdef.dat"                ' Specify The Used Micro "       ' specify the used micro
$prog &HFF , &HE7 , &HDF , &HF8         ' generated. Take care that the chip supports all fuse bytes.
$crystal = 6144000                      ' used crystal frequency 0 error in UART
$baud = 19200                           ' use baud rate
$hwstack = 64                           ' default use 32 for the hardware stack
$swstack = 64                           ' default use 10 for the SW stack
$framesize = 64
'$dbg
'$sim



Config Portd.5 = Output            'Pin 11
Alarm_LED Alias Portd.5

Config PortD.7 = Output            'Pin 12
Buzzer Alias PortD.7

Dim i as byte



   Buzzer =1
   wait 5
   Buzzer =0
   Wait 2
   Buzzer =1
   Wait 5
   Buzzer =0

   for i =1 to 5


      Alarm_led= 1
      wait 2
      Alarm_led =0
      Wait 2
      Alarm_led =1
      Waitms 300
      Alarm_led=0
      Waitms 300
      Alarm_led=1
      Waitms 300
      Alarm_led =0
      wait 3


   next i
  end

Program and hardware worked as expected.

Then I checked with my application in which I added the code for Alarm LED and buzzer.
For testing I put some code for the alarm_led and the buzzer into the init soubroutine.

In the simulator it looks well.
In the evaluation board strange things are happening.

The pin D.7 that I aliased with mybuzzer is not activacted at all.
Even more strange when I aliased D.5 as buzzer and D.7 as Alarm_LED D.5 was not activated and the buzzer beeped in the pattern programmed for the Alarm_LED.
When trying to activate D.7 by PortD.7 = 1 nothing happens.
There must be a logical reason.

Here some code:
Configuration:

Code:

Config PortD.6 = Output            
Alarm_LED Alias PortD.6

Config PortD.7 = Output            
mybuzzer Alias PortD.7

 

aftr the configuration and declaration part there is a Goto Main.
First command at the label main is call init.
So init has to be executed befor the endless loop starts.

Here the snippet with the beginning of the init subroutine:
Testmodus is declared as constant with value 0. I use testmodus=1 to skip the wait when using the simulator.

Code:

Sub Init()
disable interrupts

' beeping

mybuzzer =1

#if testmodus = 0
  wait 3
#endif

 wait 1

  for  i= 1 to 2

   Alarm_led =1
   #if testmodus =0
   Wait 5
   #endif

   Alarm_led =0
    #if testmodus =0
   Wait 1
    #endif
   Alarm_led =1
    #if testmodus =0
   Waitms 200
    #endif
   Alarm_led =0
    #if testmodus =0
   waitms 1000
    #endif

   Alarm_led =1
    #if testmodus =0
       Waitms 500
    #endif
   Alarm_led =0
    #if testmodus =0
       wait 1
    #endif


  next i

  alarm_led =1
  #if testmodus =0
  wait 10
  #endif
  alarm_led =0


   Ocr0a = UpperLimit_timer_0        'max pulse width
   Enable Compare0a                     ' Timer für 20 ms loop
   Enable Timer0
   Enable Timer2
 


The part with the LED is executed well.
My application uses timer0 and timer2.
Here the config of the timers:
Code:



Config Timer0 = Ctc , Clear_timer = 1 , Prescale = 1024
On Compare0a 20ms_timer0_isr Nosave

'Put TCCR2A Register to 10000001 and TCCR2B   Register to 00001001

'CTC Modus, Output pins not connected

   ' TCCR0A
   '   'Bit        7     6     5        4  3 2   1     0
   '   '(0xB0) COM02A1 COM0A0 COM0B1 COM0B0 – – WGM01 WGM00
Tccr0a = &B00000010

   '   'TCCR0B
   '   'Bit      7     6   5 4  3     2     1      0
   '   '(0xB1) FOC0A FOC0B – – WGM02 CS02 CS01 CS00

'Tccr0b = &B00000101
Tccr0b = &B00000000     ' Timer stopped. Will be started in the end of Sub Init

Config Timer2 = Timer, Prescale = 64


On Compare2a Servopuls_isr_t2 Nosave

Tccr2a = &B00000010                     'CTC Mode, Output disconnected

Tccr2b = &B00000000                     'Timer 2 stopped here will be started by timer0 ISR


 


According to the datasheet Port D.7 has nothing to do with the timers.
I also checked on further appearance of D.7 or mybuzzer in the program code. Found nothing.


I have no idea what is happening here.
I guess it is something very basic but I cannot find it for hours.

(BASCOM-AVR version : 2.0.8.3 )

Update:
I replaced the buzzer by a LED (less noisy)
Then I installed a label progend at the very end of the code.
To see what is happening I programmed the jump to the label.
1st version


Code:

Sub Init()
disable interrupts

' ' call beep

mybuzzer =0
waitms 200
MyBuzzer =1
dummybyte=0
wait 3
 goto progend

#if testmodus = 0
  wait 5
#endif

 wait 1
 

The MyBuzzer LED was continuously glowing

Then I modified the code
Code:

Sub Init()
disable interrupts

' ' call beep

mybuzzer =0
waitms 200
MyBuzzer =1
dummybyte=0
wait 3


#if testmodus = 0
  wait 5
#endif

 wait 1



   Alarm_led =1
   #if testmodus =0
   Wait 5
   #endif

   Alarm_led =0
    #if testmodus =0
   Wait 1
    #endif
   Alarm_led =1
    #if testmodus =0
   Waitms 200
    #endif
   Alarm_led =0
    #if testmodus =0
   waitms 1000
    #endif

   Alarm_led =1
    #if testmodus =0
       Waitms 500
    #endif
   Alarm_led =0
    #if testmodus =0
       wait 1
    #endif

 goto progend
 

With the result that the MyBuzzer LED was continuously glowing but the Alarm_LED does nothing.

Finally I removed the jump to progend.

Code:

Sub Init()
disable interrupts

' ' call beep

mybuzzer =0
waitms 200
MyBuzzer =1
dummybyte=0
wait 3


#if testmodus = 0
  wait 5
#endif

 wait 1



   Alarm_led =1
   #if testmodus =0
   Wait 5
   #endif

   Alarm_led =0
    #if testmodus =0
   Wait 1
    #endif
   Alarm_led =1
    #if testmodus =0
   Waitms 200
    #endif
   Alarm_led =0
    #if testmodus =0
   waitms 1000
    #endif

   Alarm_led =1
    #if testmodus =0
       Waitms 500
    #endif
   Alarm_led =0
    #if testmodus =0
       wait 1
    #endif
 

There is a short flicker on both LED when pushing the reset button.
Then MyBuzzer LED stays dark and the Alarm LED starts glowing after 7.7 s ( should be 9s?)
Instead of 5s glow it stopped glowing after appr. 3s. Then the pattern is roughly executed.
I do not expect high accuracy but it seems strange.
On the crystal I could read the 6.144 MHz.

Possibly remedy found:
$dbg
$sim
removed from code. 9s timing correct. Both LED glowing.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1903

blank.gif
PostPosted: Thu Oct 01, 2020 4:30 pm    Post subject: Reply with quote

As I noticed you've solved your problem, I dumped some comment, but still have some:

1) the auto-guidance function still needs some fine-tuning Very Happy
2) post more code and less prose, i.e. description of code.
3) by using 'Nosave' you walk a slippery slope and you should know exactly what you do. Do you?
The negative effects of misusing Nosave may not matter at crude code like 'beep wait beep', but it will bite you in the back as soon the code becomes more complex.
edit:
4) this is superfluous:
Code:
#if testmodus =0
  waitms 1000
#endif
as it is handled already by $SIM, quote from help:
Quote:
Simulation of a WAIT statement can take a long time especially when memory view windows are opened.
The $SIM compiler directive instructs the compiler to not generate code for WAITMS and WAIT. This will of course allows faster simulation.
When your application is ready you must remark the $SIM directive or otherwise the WAIT and WAITMS statements will not work as expected.

You learned it the hard way:
Quote:
Solved by $sim removed
The easy way would have been to read the help about the compiler directives you use.
5) do not misled the forum's readers and potential helpers.
Your first posted code shows:
Code:
'...
'$dbg
'$sim
with $SIM inactive.
Nobody can guess that in other code which you don't show $SIM is active again.
This could have been avoided by observing point (2.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 245
Location: D.F.

mexico.gif
PostPosted: Fri Oct 02, 2020 9:39 pm    Post subject: Reply with quote

In the simulator it looks well.

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
$sim
 


In the evaluation board strange things are happening.


Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
 
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 245
Location: D.F.

mexico.gif
PostPosted: Fri Oct 02, 2020 9:58 pm    Post subject: Reply with quote

[img][/img] Very Happy Very Happy
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1903

blank.gif
PostPosted: Sat Oct 03, 2020 8:36 am    Post subject: Reply with quote

Printpix52 wrote:
In the simulator it looks well.
In the evaluation board strange things are happening.

Would you explain the sense of your posts?
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 245
Location: D.F.

mexico.gif
PostPosted: Sat Oct 03, 2020 11:18 pm    Post subject: Reply with quote

Printpix52 wrote:
In the simulator it looks well.

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
$sim
 


In the evaluation board strange things are happening.


Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
 


With the simulator work with "$ sim" and to work with real card deactivate "$ sim"
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1903

blank.gif
PostPosted: Sun Oct 04, 2020 11:33 am    Post subject: Reply with quote

Printpix52 wrote:
With the simulator work with "$ sim" and to work with real card deactivate "$ sim"
Yes, also the TO found it out.
I've just wondered about your post, as you parrot an already known and solved issue.
Looks like your post is the type of 'Everything was already said, but not by everyone'.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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