In PE6 it works and in 08m2 it doesn't!

emilio0

New Member
Good morning, everyone.
I explain my problem:
The short, simple program, attachment should alternatively switch the LEDs on to the four output ports using interrupt.
In PE6 it works regularly but when loading on 08m2, apart from the three lights of departure
which indicate the program start, whenever I press the c.3 button restart the program and
After a few seconds it makes the three flashes again instead of moving to the next ice.
On the above exit doors is connected an LED resistant to the negative.
The button is connected to c.3 and the resistance that keeps it low.
c.3-----button----positive
|
|
resistance
|
|
common

I changed three 08m2 with the same results.
Can someone please explain to me where the mystery of malfunction lies when
Is it installed in 08m2?
Thanks for listening.

P.S. Sorry. Google translation.

code
#picaxe 08m2

start0:
Symbol led_c.1 =c.1
Symbol led_c.2 =c.2
Symbol led_c.4 =c.4
Symbol led_c.0 =c.0

Symbol flag =b0
Symbol f_pulsante =bit0 ;Button pressure
Symbol conta =b3 ;Number of Button Pressures


Pullup %00001000

Pause 4000 ;recharge program ex new
disconnect ;makes available c.0
Pause 2000
for conta =0 to 2 ;indicates program start with three flashes
High led_c.0
pause 500
low led_c.0
pause 500
next conta
conta=0
gosub irq ;active interrupt


uno:
Do
select case conta ;exit port selection
case 0
case 1
High led_c.0
case 2
High led_c.1
case 3
High led_c.2
case 4
High led_c.4
conta=4
endselect
if f_pulsante=1 then ;when pressing the button
gosub purge
f_pulsante=0
inc conta
if conta =>5 then
conta =1
endif
endif
gosub irq ;active interrupt
Loop
goto uno

interrupt: ;bit represents port c3
f_pulsante=pinc.3 ;save pin status from call
Do
Loop While pinc.3 = 1 ;loop until the button and press
return

purge: ;empty doors
low led_c.0,led_c.1,led_c.2,led_c.4
return

IRQ:
Setint %00001000,%00001000 ; activate interrupt
Return
/code
 

lbenson

Senior Member
How is the button on pinC.3 wired? If it lacks a pulldown resistor to 0V (say 10K), then your problem may be that it is "floating"--that is randomly alternating from 0 to 1 at a high frequency. This will not show up in PE6, but frequently trips people up on real hardware.

(Note: to preserve formatting in your code, enclose it in the forum tags, [ code] . . . [ /code] (without the spaces after the opening bracket). You can go back and edit your post to do this.)
 

PhilHornby

Senior Member
The button is connected to c.3 and the resistance that keeps it low.
c.3-----button----positive
|
|
resistance
|
|
common
Observations:
  • C.3 seems to be active HIGH - yet the code contains a pullup to try and keep it HIGH?
  • The presence of the "Start0:" label implies it is Task #0 of a multi-tasking program. Even though there are no other 'Startn' labels, it might set the Picaxe frequency to 16MHz. (See this (slightly) related thread).
  • There are lengthy periods when the interrupt is not enabled - switch depressions may be missed during this time.
  • Some code tidying is in order - there are statements that can never be reached and such like.

See if you like this version :) :-

Rich (BB code):
#picaxe 08m2

;start0:    This label has a special meaning - denotes Task #0 when multi-tasking

Symbol led_c.1 =c.1
Symbol led_c.2 =c.2
Symbol led_c.4 =c.4
Symbol led_c.0 =c.0

Symbol flag =b0
Symbol f_pulsante =bit0 ;Button pressure
Symbol conta =b3 ;Number of Button Pressures


;     Pullup %00001000        But Pin is already pulled low by a resistor?

      Pause 4000 ;recharge program ex new
;     disconnect ;makes available c.0  ** Has no effect on C.0 **

      Pause 2000              ;Is this doing anything useful?
      for conta =0 to 2       ;indicates program start with three flashes
            High led_c.0
            pause 500
            low led_c.0
            pause 500
      next conta
      conta=0
      gosub irq               ;Arm the interrupt


;uno: ** NOT USED **
Do
      select case conta       ;exit port selection
            ;case 0           ;does nothing
            case 1
                  High led_c.0
            case 2
                  High led_c.1
            case 3
                  High led_c.2
            case 4
                  High led_c.4
                  ;conta=4    ** Conta is already 4! **
      endselect

      if f_pulsante=1 then ;when pressing the button
            ;gosub purge
            ;purge: ;empty doors
            low led_c.0,led_c.1,led_c.2,led_c.4 ;only used once!
            
            f_pulsante=0
            inc conta
            if conta =>5 then
                  conta =1
            endif
      endif
;     gosub irq ;active interrupt
Loop
;goto uno   ** NO PATH TO THIS STATEMENT **

interrupt: ;bit represents port c3
      f_pulsante=pinc.3 ;save pin status from call
      Do
            ;
            ; Wait for button release?
            ;
      Loop While pinc.3 = 1   ;loop until the button and press
IRQ:
      ;
      ;(Re)arm interrupt
      ;
      Setint %00001000,%00001000 ; activate interrupt
      return
 

emilio0

New Member
Observations:
  • C.3 seems to be active HIGH - yet the code contains a pullup to try and keep it HIGH?
  • The presence of the "Start0:" label implies it is Task #0 of a multi-tasking program. Even though there are no other 'Startn' labels, it might set the Picaxe frequency to 16MHz. (See this (slightly) related thread).
  • There are lengthy periods when the interrupt is not enabled - switch depressions may be missed during this time.
  • Some code tidying is in order - there are statements that can never be reached and such like.

See if you like this version :) :-

Rich (BB code):
#picaxe 08m2

;start0:    This label has a special meaning - denotes Task #0 when multi-tasking

Symbol led_c.1 =c.1
Symbol led_c.2 =c.2
Symbol led_c.4 =c.4
Symbol led_c.0 =c.0

Symbol flag =b0
Symbol f_pulsante =bit0 ;Button pressure
Symbol conta =b3 ;Number of Button Pressures


;     Pullup %00001000        But Pin is already pulled low by a resistor?

      Pause 4000 ;recharge program ex new
;     disconnect ;makes available c.0  ** Has no effect on C.0 **

      Pause 2000              ;Is this doing anything useful?
      for conta =0 to 2       ;indicates program start with three flashes
            High led_c.0
            pause 500
            low led_c.0
            pause 500
      next conta
      conta=0
      gosub irq               ;Arm the interrupt


;uno: ** NOT USED **
Do
      select case conta       ;exit port selection
            ;case 0           ;does nothing
            case 1
                  High led_c.0
            case 2
                  High led_c.1
            case 3
                  High led_c.2
            case 4
                  High led_c.4
                  ;conta=4    ** Conta is already 4! **
      endselect

      if f_pulsante=1 then ;when pressing the button
            ;gosub purge
            ;purge: ;empty doors
            low led_c.0,led_c.1,led_c.2,led_c.4 ;only used once!
            
            f_pulsante=0
            inc conta
            if conta =>5 then
                  conta =1
            endif
      endif
;     gosub irq ;active interrupt
Loop
;goto uno   ** NO PATH TO THIS STATEMENT **

interrupt: ;bit represents port c3
      f_pulsante=pinc.3 ;save pin status from call
      Do
            ;
            ; Wait for button release?
            ;
      Loop While pinc.3 = 1   ;loop until the button and press
IRQ:
      ;
      ;(Re)arm interrupt
      ;
      Setint %00001000,%00001000 ; activate interrupt
      return
 

emilio0

New Member
For Ibenson:
I attach diagram of the simple test that answers your question and to understand the program that is acting up.
I put in the tags as you say but can't seem to edit the first one.

For PhilHornby:
I've made the changes as you suggest, (thanks for the information I didn't know, ex disconnect, start 0:, and pullup %00001000) but the final operation is as stated in my initial post has the same error.

Code:
#picaxe 08m2

Symbol led_c.1       =c.1
Symbol led_c.2       =c.2
Symbol led_c.4       =c.4
Symbol led_c.0       =c.0

Symbol flag              =b0
;bit7= ;
;bit6= ;
;bit5= ;
;bit4= ;
Symbol f_pulsante               =bit1 ;push button

Symbol conta                    =b1 ;count the no. button presses

Pause 4000 ;to load new version after reset
for conta =0 to 2
    High led_c.0
    pause 500
    low led_c.0
    pause 500
next conta
conta=0
gosub irq

Do
    select case conta
    case 1
        High led_c.0
    case 2
        High led_c.1
    case 3
        High led_c.2
    case 4
        High led_c.4
        conta=5
    endselect
    pause 1000
    if f_pulsante=1 then
        low led_c.0,led_c.1,led_c.2,led_c.4
        f_pulsante=0
        inc conta
        if conta =>5 then
            conta =1
        endif
    endif
Loop

interrupt: ;the bit represents port c3
f_pulsante=pinc.3 ;save pin status from call
Do
Loop While pinc.3 = 1 ;loop here until the button is pressed

IRQ:
Setint %00001000,%00001000 ; re-activate interrupt
Return
 

Attachments

PhilHornby

Senior Member
Well the code seems OK now ....
...though that depends on what it is supposed to do ;)

I downloaded your new code and tried it. After a delay, I get three flashes, then the LEDs cycle every time I press the button.

 

hippy

Technical Support
Staff member
Code:
interrupt: ;the bit represents port c3
f_pulsante=pinc.3 ;save pin status from call
Do
Loop While pinc.3 = 1 ;loop here until the button is pressed
One issue with this code is that pinC.3 may have some bounce when pushed so it is possible that the interrupt is fired, the button bounces, and pinC.3 is read as zero when 'f_pulsante' is set. With 'f_pulsante' set to zero the main code won't see that a button has been pushed.

It would be better to just use "f_pulsante = 1"
 

Goeytex

Senior Member
whenever I press the c.3 button restart the program and
After a few seconds it makes the three flashes again instead...
If I understand this correctly, it indicates that the 08M2 is resetting. This could be due to several reasons.

1) The download circuit is wired incorrectly ( Schematic Looks OK)
2) Noise/Spikes on PinC.3
3) Power loss / Pin shorted

C.3 is the "Master Clear" pin on a PIC16F1840 from which the 08M2 is derived. This pin has no protection diodes. A short positive pulse/spike on this pin greater than about 7V could cause the 08M2 to reset even though the Picaxe Firmware has MCLRE disabled.

When using this PinC.3 as an input, I would add some series resistance and a protection diode like a BAT85 to prevent the possibility of spurious resets or even damage to the Picaxe.



25136
 
Last edited:

emilio0

New Member
If I understand this correctly, it indicates that the 08M2 is resetting. This could be due to several reasons.

1) The download circuit is wired incorrectly ( Schematic Looks OK)
2) Noise/Spikes on PinC.3
3) Power loss / Pin shorted

C.3 is the "Master Clear" pin on a PIC16F1840 from which the 08M2 is derived. This pin has no protection diodes. A short positive pulse/spike on this pin greater than about 7V could cause the 08M2 to reset even though the Picaxe Firmware has MCLRE disabled.

When using this PinC.3 as an input, I would add some series resistance and a protection diode like a BAT85 to prevent the possibility of spurious resets or even damage to the Picaxe.



View attachment 25136
 

emilio0

New Member
After test after test with negative results, I decided to build another circuit, with the same processor and the same SW on a board like the one used in the movie by PhilHornby.
Perfect, it worked first time and switches with the button on the LEDs as per PhilHornby's film.
Too bad because the original was already mounted on the circuit board millefori.
Anyway, let that be a lesson to me. I lost almost two weeks to this problem.
After your intervention, which advised me of the much appreciated SW changes I checked all the resistors, leds and the button carried c.3 to positive.
So officially the circuit has no HW problems.
I suspect the 08m2 plinth and millefori have some as yet unknown problem.
I thank very sincerely Ibenson, PhilHornby, Goeytex, and hippy, who helped me out of this problem and I greet them cordially.

Breaking news: Probable culprit and the new tin used to mount the circuit on the millefori that came to me (lead-free type. I was using 60/40 until now). When mounting the capacitor between positive and negative of the 08m2 socket I noticed that unlike the 60/40 that you can solder the same solder without problems, I was getting a partial melting like jelly blocks, with low adhesion.
I'll redo the same circuit on millefori with 60/40 tin, so I'll be sure.

Thanks again to all of you.

emilio
 

lbenson

Senior Member
I noticed that unlike the 60/40 that you can solder the same solder without problems, I was getting a partial melting like jelly blocks, with low adhesion.
Yet another strike against lead-free in the hobby domain. Glad you found the actual cause of this perplexing problem, instead of it remaining a mystery. Congratulations.
 
Top