Sound2

Markd77

Joined Sep 7, 2009
2,806

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I undertand but I cant right now...I give myself 45 minutes to figure out the bug or else I just give up...I have a HUGE exam in two days time and I have not even started yet..but problem is this sound2 is due 2moro!...looks like im in deep s**t...

I tought it was so simple...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
this works...but when I try to integrate the push button it stops working!

Im getting there!;)
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
OK, sorry if this sounds a bit harsh, I'll still help you but I won't be doing any simulating after this.
I've found one bug, you are changing tmr0_cnt2 in the delay33ms section so nothing is happening.
I've made a video of me simulating it and finding the bug, I suggest you should watch it as soon as you have time (link when I've uploaded it). It shows how easy it is, and if you are going to be making a robot you need to learn the simulator first, it's too complicated to work on without the simulator and you would never finish it in time.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
OK, sorry if this sounds a bit harsh, I'll still help you but I won't be doing any simulating after this.
I've found one bug, you are changing tmr0_cnt2 in the delay33ms section so nothing is happening.
I've made a video of me simulating it and finding the bug, I suggest you should watch it as soon as you have time (link when I've uploaded it). It shows how easy it is, and if you are going to be making a robot you need to learn the simulator first, it's too complicated to work on without the simulator and you would never finish it in time.
Nah! doesn't sound Harsh at all...all y'all are RIGHT!!! I must learn the 'simulation' ASAP...just that Im in a panic mode right now...

I will definitely learn the 'Simulator' for the robot...lemme check the bug you have found!

Thanks Derstrom8, MMclaren and Markd77
 

MMcLaren

Joined Feb 14, 2010
861
Problem is you're always in "panic mode" (lol).

Anyway, here's an example I threw together using an entirely different approach. It took about an hour and it simulates fine. I hope you might find something useful in it.

Good luck with your project Eric...

Rich (BB code):
;******************************************************************
;                                                                 *
;   Filename: Sim Door Bell.asm                                   *
;     Author: Mike McLaren, K8LH                                  *
;    (C)2012: Micro Application Consultants                       *
;       Date: 30-Sep-12                                           *
;                                                                 *
;    16F690 (8-MHz INTOSC) Door Bell Demo'                        *
;                                                                 *
;                                                                 *
;      MPLab: 8.84    (tabs=8)                                    *
;      MPAsm: 5.44                                                *
;                                                                 *
;******************************************************************

        #include <p16f690.inc>
        radix dec
        list st=off
        errorlevel -302,-224

;--< config fuses >------------------------------------------------

  __config  _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO

;  _FCMEN_OFF           ; -- fail safe clock monitor enable off
;  _IESO_OFF            ; -- int/ext switch over enable off
;  _BOR_ON              ; default, brown out reset on
;  _CPD_OFF             ; default, data eeprom protection off
;  _CP_OFF              ; default, program code protection off
;  _MCLR_OFF            ; -- use MCLR pin as digital input
;  _PWRTE_OFF           ; default, power up timer off
;  _WDT_OFF             ; -- watch dog timer off
;  _INTOSCIO            ; -- internal osc, OSC1 and OSC2 I/O

;--< variables >---------------------------------------------------

        cblock  0x20
swold                   ; switch state latch
swnew                   ; switch "new press" flags
delayhi                 ; DelayCy() subsystem variable
countlo                 ;
counthi                 ;
        endc

;--< constants >---------------------------------------------------

#define piezo   0       ; bit index for piezo spkr on RA0 pin
#define button  7       ; bit index for button on RB7 pin

;==================================================================
;  K8LH DelayCy() subsystem macro generates four instructions	  =
;==================================================================
        radix   dec
clock   equ     8               ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier

DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm

;******************************************************************
;  reset vector							  *
;******************************************************************
	org	0x000
v_reset
  	clrf	STATUS		; force bank 0 and IRP = 0	  |B0
	goto	init		;				  |B0

;******************************************************************
;  interrupt vector						  *
;******************************************************************
	org	0x004
v_interrupt

;******************************************************************
;  main init                                                      *
;******************************************************************

init
        bsf     STATUS,RP1      ; bank 2                          |B2
        clrf    ANSEL           ; turn off ADC for digital I/O    |B2
        clrf    ANSELH          ;                                 |B2
;
;  configure INTOSC for 8-MHz
;
        bcf     STATUS,RP1      ; bank 0                          |B0
        bsf     STATUS,RP0      ; bank 1                          |B1
        movlw   b'01110000'     ; setup INTOSC for 8-MHz          |B1
        movwf   OSCCON          ;                                 |B1
stable  btfss   OSCCON,HTS      ; osc stable? yes, skip, else     |B1
        goto    stable          ; loop (wait until stable)        |B1
;
;  configure I/O ports
;
        clrf    TRISA           ; port A all outputs              |B1
        movlw   1<<button       ; bit index for switch on RB7     |B1
        movwf   TRISB           ; all others outputs              |B1
        clrf    TRISC           ; port C all outputs              |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTA           ; clear port A output latches     |B0
        clrf    PORTB           ; clear port B output latches     |B0
        clrf    PORTC           ; clear port C output latches     |B0
;
;  initialize program variables
;
        clrf    swold           ; clear switch state latch        |B0

;******************************************************************
;  main loop                                                      *
;******************************************************************

loop
        DelayCy(16*msecs)       ; 16-msec 'debounce' intervals    |B0
;
;  K8LH parallel switch state logic (using "new press" filter)
;
;   wreg  ___---___---___---___   active hi switch sample 
;  swold  ____---___---___---__   switch state latch
;   wreg  ___-__-__-__-__-__-__   changes, press or release
;   wreg  ___-_____-_____-_____   filter out 'release' bits
;
        movf    PORTB,W         ; sample active high switches     |B0
        andlw   b'10000000'     ; on the RB7 pin only             |B0
        xorwf   swold,W         ; changes, press or release       |B0
        xorwf   swold,F         ; update switch state latch       |B0
        andwf   swold,W         ; filter out 'release' bits       |B0
        skpnz                   ; a new press? yes, skip, else    |B0
        goto    loop            ; branch (wait for input)         |B0
;
;  generate a 1-second 661-Hz tone (toggle the piezo speaker at
;  756-usec intervals 1322 times)
;
        movlw   1000000/756%256 ;                                 |B0
        movwf   countlo         ;                                 |B0
        movlw   1000000/756/256 ;                                 |B0
        movwf   counthi         ;                                 |B0
tone661
        movlw   1<<piezo        ; bit mask for piezo spkr (RA0)   |B0
        xorwf   PORTA,F         ; toggle piezo spkr output        |B0
        DelayCy(756*usecs-11)   ; precise 756 usec loop time      |B0
        movf    countlo,W       ;                                 |B0
        skpnz                   ;                                 |B0
        decf    counthi,F       ;                                 |B0
        decf    countlo,F       ;                                 |B0
        movf    countlo,W       ; check for 1-second elapsed      |B0
        iorwf   counthi,W       ; has tone been on for 1 second?  |B0
        skpz                    ; yes, skip, else                 |B0
        goto    tone661         ; branch                          |B0
;
;  generate a 496-Hz tone for 1 second (toggle the piezo speaker
;  at 1008-usec intervals 992 times)
;
        movlw  1000000/1008%256 ; # intervals for 1 second        |B0
        movwf   countlo         ;                                 |B0
        movlw  1000000/1008/256 ;                                 |B0
        movwf   counthi         ;                                 |B0
tone496
        movlw   1<<piezo        ; bit mask for piezo spkr (RA0)   |B0
        xorwf   PORTA,F         ; toggle piezo spkr output        |B0
        DelayCy(1008*usecs-11)  ; precise 1008 usec loop time     |B0
        movf    countlo,W       ;                                 |B0
        skpnz                   ;                                 |B0
        decf    counthi,F       ;                                 |B0
        decf    countlo,F       ;                                 |B0
        movf    countlo,W       ; check for 1-second elapsed      |B0
        iorwf   counthi,W       ; has tone been on for 1 second?  |B0
        skpz                    ; yes, skip, else                 |B0
        goto    tone496         ; branch                          |B0
        goto    loop            ; loop                            |B0

;******************************************************************
;  K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine     *
;******************************************************************
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract 5 cycle loop time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  delayhi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0

;******************************************************************
        end
 
Last edited:

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
You are right...panic mode all the time! LOL

I just tried your code but there is no response! I assume the push botton is the problem...I also realize I did not ground the push button when trying with previous code!
 

DerStrom8

Joined Feb 20, 2011
2,390
You are right...panic mode all the time!

I just tried your code but there is no response! I assume the push botton is the problem...I also realize I did not ground the push button when trying with previous code!
Are you using a pull-up or pull-down resistor for the button?
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I think it 'pullup' it the same configuration I use all the time!

one end of resistor goes to + and the other end goes to pushbutton pin & RB7
the other pin of pushbutton goes to gnd!

this configuration works on my other circuit.... *getting stressed##

I think I got to take a break with this and study my exam...will get back to it in 2 hours...but will keep on checking posts..

it unbeleivable how I am wasting time on a little project like this!
 

DerStrom8

Joined Feb 20, 2011
2,390
I think it 'pullup' it the same configuration I use all the time!

one end of resistor goes to + and the other end goes to pushbutton pin & RB7
the other pin of pushbutton goes to gnd!

this configuration works on my other circuit.... *getting stressed##

I think I got to take a break with this and study my exam...will get back to it in 2 hours...but will keep on checking posts..

it unbeleivable how I am wasting time on a little project like this!
Okay, so with a pull-up resistor, it means you're looking for the pin to go low. When the pin goes low, it means the switch is pressed. I haven't read the code all the way through, because to be perfectly honest, I don't really understand it :D

So my question is, in the code, did you tell the interrupt to "trip" when the pin reads a 1, or when it reads a 0?
 

MMcLaren

Joined Feb 14, 2010
861
To go from "active high" to "active low" with that parallel switch state logic simply requires inverting the sample input. Compare the "active hi" code to the "active lo" code;

Rich (BB code):
loop
        DelayCy(16*msecs)       ; 16-msec 'debounce' intervals    |B0
;
;  K8LH parallel switch state logic (using "new press" filter)
;
;   wreg  ___---___---___---___   active hi switch sample 
;  swold  ____---___---___---__   switch state latch
;   wreg  ___-__-__-__-__-__-__   changes, press or release
;   wreg  ___-_____-_____-_____   filter out 'release' bits
;
        movf    PORTB,W         ; sample active hi switches       |B0
        andlw   b'10000000'     ; on the RB7 pin only             |B0
        xorwf   swold,W         ; changes, press or release       |B0
        xorwf   swold,F         ; update switch state latch       |B0
        andwf   swold,W         ; filter out 'release' bits       |B0
        skpnz                   ; a new press? yes, skip, else    |B0
        goto    loop            ; branch (wait for input)         |B0
Rich (BB code):
loop
        DelayCy(16*msecs)       ; 16-msec 'debounce' intervals    |B0
;
;  K8LH parallel switch state logic (using "new press" filter)
;
;   wreg  ___---___---___---___   inverted active lo sample 
;  swold  ____---___---___---__   switch state latch
;   wreg  ___-__-__-__-__-__-__   changes, press or release
;   wreg  ___-_____-_____-_____   filter out 'release' bits
;
        comf    PORTB,W         ; sample active lo switches       |B0
        andlw   b'10000000'     ; on the RB7 pin only             |B0
        xorwf   swold,W         ; changes, press or release       |B0
        xorwf   swold,F         ; update switch state latch       |B0
        andwf   swold,W         ; filter out 'release' bits       |B0
        skpnz                   ; a new press? yes, skip, else    |B0
        goto    loop            ; branch (wait for input)         |B0
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Okay, so with a pull-up resistor, it means you're looking for the pin to go low. When the pin goes low, it means the switch is pressed. I haven't read the code all the way through, because to be perfectly honest, I don't really understand it :D

So my question is, in the code, did you tell the interrupt to "trip" when the pin reads a 1, or when it reads a 0?
LOL...

yeah when it goes low = button pressed! I have double checked what you just mentioned but nothing...I'm wondering if it because I stop (reset) 'global and timer0 interrupt' when counting for 1 second...

I'm now confused too!:confused:
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
looks like I am just a dead man! :(

@MMclaren: I tried both loops--> nothing

@Mark: Im loading the video...that will really help!
Have you found any bug on the push button since you were simulating it

Will keep on checkin post but for now I am studying...#really stressed#


this little project exhausting me..:(
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I didn't see you turn on the internal pull-up resistors in your code so you must be using an external pull-up resistor???
yep! the resistor is external!

@ markkd77: I have watched the video...thanks a million ...I got the picture of simulating but I have to watch it again a couple of time + reading on it!

but why you initializing INTCON with the TRISX...they are not in the same bank...

Hope I get some help with this push button that all that is left!

thanks all
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
INTCON is in all the banks, so it doesn't matter. Just after I put those lines and rebuilt you can see INTCON changing in the Special Function Registers window. As I've already got the project up, I'll have a quick look and see if I can see anything else.
 
Top