Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Some questions howto use the simulator / or if this feasible at all

2 posters

Go down  Message [Page 1 of 1]

msnrw



Hi, i am relatively new to simulide.
I watched its development some time but did not know enough about electronics and microcontroller to use it.

Now I think my knowledge has evolved, it tried the simulator and had some good results with my project. But now i am stuck a bit.

For one project i would like to simulate an attiny13(a) and programming it with Great Cow BASIC, reading an LDR and blinking a LED. The LED-Part works so far.

Q1: For the LDR-Part i had a software serial solution on the real hardware. This won't work with simulide, wouldn't it? My first attempt to open the serial monitor led to a crash of the simulide-program. Maybe someone knows a trick.

Q2: With respect to the LDR: it gave me readings of 255 which means 100% @3Volts in the simulation. After refining the circuit, it shows a zero in the variable. Could someone give me a hint how to change the values or howto fix the circuitry?

Q3: In the same program i am working with the watchdog - this seems not to work as well. Or do i have to tweak some Settings to see the watchdog work?

In the same project, i had originally a radio transmitting solution for transmitting the ldt measurements by "misusing" the softwareserial. I wanted to try some kind of manchester encoding and refine the solution.

Q4: Do I have any chances in building a circuit with two microcontroller one as sender and one as receiver? Did not try it, but thought i ask in advance before wasting time with a simulation which won't work in the end.

Here is the Code i am using at the moment:

Code:
#chip tiny13a, 4.8

#define PWM_Out1 PortB.0
#define ADSpeed MediumSpeed
#define USE_AD1 TRUE
#define USE_AD0 FALSE
#define USE_AD2 FALSE
#define USE_AD3 FALSE
DIR PWM_Out1 OUT
DIR PortB.2 IN
                          '8s WDT x MAX_NUM = time before the main program is really executed
#DEFINE MAX_NUM 1         'set to 225 to do something every 30 min, debug set to 1 (8s WDT)
watchdog_off              'deactivate the watchdog, good practice

'Set Variables
DIM TIMEOUT, LDR AS BYTE
dim tblCounter1, tablecounter2 as byte
DIM Invalue1, invalue2 AS WORD

TIMEOUT = MAX_NUM       'set timer intervall - while the mcu mostly sleeps
ON INTERRUPT WDT CALL wdt_wakeup

do
wdt_sleep
TIMEOUT -= 1
IF TIMEOUT = 0 THEN
  LDR = READAD(ADC1)
  wait 30 us
  LDR = READAD(ADC1)
  IF LDR <= 60 THEN
    for tblCounter1 = 1 to 120
      for tblcounter2 = 1 to 35
        ReadTable Brightness, tblCounter1, Invalue1
        Readtable Timings, tblcounter2, Invalue2
        PWMOut 1, invalue2, invalue1
      wait invalue2 us
      next
    next
    wait 500 us
    TIMEOUT = MAX_NUM
  ELSE
    TIMEOUT = MAX_NUM
  END IF
END IF
loop

SUB watchdog_off
    INToff
    wdr
    MCUSR = 0b00000000
    WDTCR = 0b00011000      'timed sequence to switch the WDT off
    WDTCR = 0b00000000
    INTon
END SUB

SUB watchdog_on
    INToff
    wdr
    'WDT-Prescaler value = 8 s, WDT set to Interrupt (WDTIE) not reset
    WDTCR=0b00011000
    WDTCR=0b01111001
    INTon
END SUB

SUB wdt_sleep
    PRR = 0b0000011 'Timer0 and ADC off
    DIDR0 = 0b00111111 'digital inputs off
    watchdog_on
    MCUCR=0b00110000 'sleep enable and mode poweroff
    sleep
END SUB

SUB wdt_wakeup
    MCUCR = 0b00000000 'sleep-enable off
    PRR = 0b00000000 'Timer0 and ADC on
    watchdog_off
END SUB

'generated random numbers for the brightness of the led, found that the table is more sufficient for timings
'did not change the name because it was easier while testing.
Table Brightness
842
970
796
428
501
818
838
425
947
674
481
578
808
166
612
721
184
1003
397
557
333
476
124
465
204
634
507
870
646
962
340
652
410
914
817
280
536
1006
199
523
374
467
149
688
337
959
259
819
411
991
815
716
837
366
1018
175
308
565
613
928
482
741
472
509
522
404
996
544
305
546
454
804
419
846
315
689
651
792
352
279
904
173
586
856
843
957
143
850
673
847
444
401
217
582
729
923
309
759
338
218
568
873
538
958
327
727
128
971
594
399
169
499
701
515
787
395
125
585
551
495
End Table

'generated random numbers for the timing of the led, found that the table is more sufficient for brightness
'did not change the name because it was easier while testing.
Table Timings
389
128
365
343
304
289
211
354
148
487
91
50
109
111
485
344
339
162
404
415
118
56
418
63
73
153
380
266
440
394
419
121
177
292
463
End Table

And here is the circuit:

Some questions howto use the simulator / or if this feasible at all Tiny1310

Thank you in advance - any help is appreciated.

arcachofo

arcachofo

Hi msnrw.

Q1: For the LDR-Part i had a software serial solution on the real hardware. This won't work with simulide, wouldn't it? My first attempt to open the serial monitor led to a crash of the simulide-program. Maybe someone knows a trick.
No.. serial monitor catchs the microcontroller usart trafic, can't do nothing with software serial.
In next version something like this will possible, but not implemented yet.

If you only want to see the value of LDR variable, you can watch it in Mcu Monitor.
Also ADC, WDT Registers, etc.
Right-Click -> Open Mcu Monitor:

Some questions howto use the simulator / or if this feasible at all Wdt10


Q2: With respect to the LDR: it gave me readings of 255 which means 100% @3Volts in the simulation. After refining the circuit, it shows a zero in the variable. Could someone give me a hint how to change the values or howto fix the circuitry?
The first issue I can see is the battery only connected in one side, better use a "Rail" component.


Q3: In the same program i am working with the watchdog - this seems not to work as well. Or do i have to tweak some Settings to see the watchdog work?
Not sure, could be a error in simulide.
But I think there is one error in your code:

Code:
SUB watchdog_on
    INToff
    wdr
    'WDT-Prescaler value = 8 s, WDT set to Interrupt (WDTIE) not reset
    WDTCR=0b00011000
    WDTCR=0b01111001 ' Should be: 0b01101001
    INTon
END SUB

Datasheet: wrote:The sequence for clearing WDE and
changing time-out configuration is as follows:
1. In the same operation, write a logic one to the Watchdog change enable bit (WDCE)
and WDE. A logic one must be written to WDE regardless of the previous value of the
WDE bit.
2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP) as
desired, but with the WDCE bit cleared. This must be done in one operation.


Q4: Do I have any chances in building a circuit with two microcontroller one as sender and one as receiver? Did not try it, but thought i ask in advance before wasting time with a simulation which won't work in the end.
In 0.4.15 only one micro can  be in the circuit. So you can't even build that circuit.
But even if you could, AVRs in simulide don't simulate usart pin input/output.

In next version you will be able to use as many micros as you want.
And AVR usart pins work.

msnrw likes this post

msnrw



arcachofo wrote:Hi msnrw

No.. serial monitor catchs the microcontroller usart trafic, can't do nothing with software serial.
In next version something like this will possible, but not implemented yet.

Ok, it will surely work without.

If you only want to see the value of LDR variable, you can watch it in Mcu Monitor.
Also ADC, WDT Registers, etc.
Right-Click -> Open Mcu Monitor:

Some questions howto use the simulator / or if this feasible at all Wdt10


Q2: With respect to the LDR: it gave me readings of 255 which means 100% @3Volts in the simulation. After refining the circuit, it shows a zero in the variable. Could someone give me a hint how to change the values or howto fix the circuitry?
The first issue I can see is the battery only connected in one side, better use a "Rail" component.

Have to try that, maybe it's just that i puzzzled it up.

Q3: In the same program i am working with the watchdog - this seems not to work as well. Or do i have to tweak some Settings to see the watchdog work?
Not sure, could be a error in simulide.
But I think there is one error in your code:

Code:
SUB watchdog_on
    INToff
    wdr
    'WDT-Prescaler value = 8 s, WDT set to Interrupt (WDTIE) not reset
    WDTCR=0b00011000
    WDTCR=0b01111001 ' Should be: 0b01101001
    INTon
END SUB

Datasheet: wrote:The sequence for clearing WDE and
changing time-out configuration is as follows:
1. In the same operation, write a logic one to the Watchdog change enable bit (WDCE)
and WDE. A logic one must be written to WDE regardless of the previous value of the
WDE bit.
2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP) as
desired, but with the WDCE bit cleared. This must be done in one operation.

Hmm. On a real attiny13a it works - must compare the datadheets, maybe there are slight differences. Thanks for the pointer.

Q4: Do I have any chances in building a circuit with two microcontroller one as sender and one as receiver? Did not try it, but thought i ask in advance before wasting time with a simulation which won't work in the end.
In 0.4.15 only one micro can  be in the circuit. So you can't even build that circuit.
But even if you could, AVRs in simulide don't simulate usart pin input/output.

In next version you will be able to use as many micros as you want.
And AVR usart pins work.

That would be a cool Feature - will test it.

Keep up the good work!

4Some questions howto use the simulator / or if this feasible at all Empty Watchdog issues (solved) Sun Aug 22, 2021 12:24 am

msnrw



Hi arcachofo,

changed the simualtion a bit according to your hints:

with a rail the LDR shows results,
the watchdog code works for a attiny13a (this mcu is the one i have in real hardware and on breadboard this works quite well) but the watchdog on the attiny13 works a bit different, so i have to read a bit, how to distinguish the two and work something out, that the code work in real hardware and in simulation.

On the other hand i'd like to encourage you to add the attiny13a in the Mikrocontroller list Smile

But for the project in mind it should help to figure out the right code and to bring it to breadboard after refining software.

Thank you!

arcachofo

arcachofo

the watchdog code works for a attiny13a (this mcu is the one i have in real hardware and on breadboard this works quite well) but the watchdog on the attiny13 works a bit different, so i have to read a bit, how to distinguish the two and work something out, that the code work in real hardware and in simulation.
Thanks, this information is very useful.
I was not aware of these differences.

Next Version (0.5.16) will use a new MCU simulator.
I started to implement attiny13 the day before your firs post, so your circuit was very useful for testing and fixing the WDT.
I will have a look to the differences with "a" versions and implement these devices as well.
When I have something working I will let you know...

msnrw



arcachofo wrote:
Thanks, this information is very useful.
I was not aware of these differences.

Next Version (0.5.16) will use a new MCU simulator.
I started to implement attiny13 the day before your firs post, so your circuit was very useful for testing and fixing the WDT.
I will have a look to the differences with "a" versions and implement these devices as well.
When I have something working I will let you know...


To give some pointer:

The PRR register is New to the attiny13a as far as i read.
And the WDTCR is slightly different - in which way i have to figure out myself at the moment.

Good to hear that there is progress Wink

To complete the thread, here is a simplified version of the code with a working sleep routine for the attiny13 (the chips are so close to another, that you have to scrutiny that drop of water):

Code:
#CHIP tiny13, 1.2
#OPTION Explicit

'Config ADC, LED-PIN
#DEFINE ADSpeed MediumSpeed
#DEFINE LED PortB.0
                          '8s WDT x MAX_NUM = time before the main program is really executed
#DEFINE MAX_NUM 1         'set to 225 to do something every 30 min, debug set to 1 (8s WDT)
watchdog_off              'deactivate the watchdog, good practice

'Set PIN Directions
DIR LED OUT
DIR PortB.2 IN

'Set Variables
DIM TIMEOUT, LDR AS BYTE

TIMEOUT = MAX_NUM       'set timer intervall - while the mcu mostly sleeps
ON INTERRUPT WDT CALL wdt_wakeup

LED = 0

'Main program
DO
wdt_sleep
TIMEOUT -= 1
IF TIMEOUT = 0 THEN
      LDR = READAD(ADC1)      'send the value from the LDR
      LED = !LED
      WAIT LDR ms
      TIMEOUT = MAX_NUM
END IF
LOOP

SUB watchdog_off
    INToff
    wdr
    MCUSR = 0b00000000
    WDTCR = 0b00011000      'timed sequence to switch the WDT off
    WDTCR = 0b00000000
    INTon
END SUB

SUB watchdog_on
    INToff
    wdr
    'WDT-Prescaler value = 8 s, WDT set to Interrupt (WDTIE) not reset
    WDTCR=0b00011000
    WDTCR=0b01110001 'slightly different to attiny13a
    INTon
END SUB

SUB wdt_sleep
    'PRR = 0b0000011 'Timer0 and ADC off - n/a on attiny13
    LED = !LED
    DIDR0 = 0b00111111 'digital inputs off
    watchdog_on
    MCUCR=0b00110000 'sleep enable and mode poweroff
    sleep
END SUB

SUB wdt_wakeup
    MCUCR = 0b00000000 'sleep-enable off
    'PRR = 0b00000000 'Timer0 and ADC on - n/a on attiny13
    watchdog_off
END SUB

Next step in code enhancement would be a #ifdef or something to not change the code every now and then. But i think i can manage that Smile

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum