Delayed output 10 secs


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    The beep doesn't have to come from the sound command, I didn't know it could be generated another way! as long as it goes beep when LEDx changes state is good.

    I will learn from this project but I have a couple of other projects I will impress you with!

    Thank you soooooo much for your help.

    Mike

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yowwwsaaaa!

    I saw something interesting floating thru the forum's waters, and I grabbed at it.
    Ummm, excuse me ... can I give it back?
    It looked like a piece of Tuna, I didn't know there was a Hook in it!

    Oh OK, I guess not.

    So many timers and conditions and beeps,
    I'm just going to gnaw on this a little more ...
    see if I can't work that hook out of my cheek before I hit surface.
    <br>
    DT

  3. #3
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    I was kind of fiddling with part of your timer code and part of what I had and I was able to get all the timings, highs and lows at the right place but the beep with the sound command is really lowsy, instead of beep it goes brererererep!
    Of course If I had an scope I might see other strange things!

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You can probably just turn off the Interrupts (INTCON.7) during the beeps.

    It'll stop keeping time during the beep, but in the scope of several hours charge time, you'll never notice.
    <br>
    DT

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OK, well now that you already have it working ...

    I finally got mine working too.
    This one doesn't use interrupts, and is essentially the example I gave in post#3, expanded to meet the other requirements.

    May not be any help to you, but it might give some more ideas.
    View Highlighted code
    Code:
    CLEAR
    INCLUDE "AllDigital.pbp"         ; Disable Analog functions
    DEFINE OSC 8
    OSCCON = %01110001
    
    SW1     VAR PORTB.0
    SW2     VAR PORTB.1
    SW3     VAR PORTB.2
    SW4     VAR PORTB.3
    SW5     VAR PORTB.4
    SW6     VAR PORTB.5
    
    LED1    VAR PORTC.0
    LED2    VAR PORTC.1
    LED3    VAR PORTC.2
    LED4    VAR PORTC.3
    LED5    VAR PORTC.4
    LED6    VAR PORTC.5
    PZ      VAR PORTC.6               ; piezo (beep)
    
    TR1     VAR PORTA.0
    TR2     VAR PORTA.1
    TR3     VAR PORTA.2
    TR4     VAR PORTA.3
    TR5     VAR PORTA.4
    TR6     VAR PORTA.5
    
    ;---[Adjustable delay times]------------------------------------------------
    DebounceTime   CON 25            ; (ms) button debounce time 
    ChargeDelay    CON 10000         ; (ms) delay before it starts charging 
    ProgDelay      CON 5000          ; (ms) time to hold button for program mode 
    ProgHold       CON 3000          ; (ms) of inactivity to end Program Mode
    MaxCharge      CON 12            ; (hours) Maximum Charge Time [MAX 18]
    ;---------------------------------------------------------------------------
    Counters       VAR WORD[6]       ; 6 words, for 6 buttons
    ProgCounter    VAR WORD[6]       ; counts buttom time to enter Program Mode
    Debounce       VAR BYTE[6]       ; debounce counters
    ChargeTime     VAR BYTE[6]       ; counts charging time (hours) in Prog mode
    ChannelStates  VAR BYTE[6]       ; Channel state flags
    ChannelState   VAR BYTE
      LastState    VAR ChannelState.0 ; state of SW pin during last loop
      Pressed      VAR ChannelState.1 ; Button has been pressed
      ProgramMode  VAR ChannelState.2 ; indicates currently in program mode
      ChargeMode   VAR ChannelState.3 ; indicates currently in charge mode
    
    T0IF           VAR INTCON.2      ; TMR0 overflow flag   
    I              VAR BYTE          ; general use in for next
    X              VAR BYTE
    TempW          VAR BYTE
    OneSecond      VAR WORD
    SecondsChanged VAR BIT
    PinState       VAR BIT
    
    OneSecond = 1000
    OPTION_REG = %01010100            ; WPUon, TMR0 1:32 prescaler, internal clk
    
    DATA @0, 3, 3, 3, 3, 3, 3         ; set default Charge Time to 3 hours
    
    sound pz,[123,10]                 ; beep on power-up
    
    ;----[Main Loop]------------------------------------------------------------
    Main:
        WHILE !T0IF : WEND                  ; wait for timer to overflow
        TMR0 = 193                          ; load timer for 1ms
        T0IF = 0                            ; reset the overflow flag
        OneSecond = OneSecond - 1           ; count off 1 second intervals
        IF OneSecond = 0 THEN               ;   for charge timers
          OneSecond = 1000
          SecondsChanged = 1
        ENDIF
                                            ;-----------------------------------
        FOR X = 0 to 5                      ; cycle thru Channels
          ChannelState = ChannelStates(X)   ; get this channels state flags
          GOSUB GetSWState                  ; get the current state of the SW
          IF PinState != LastState THEN     ; debounce the pin
             LastState = PinState
             Debounce(X) = DebounceTime
          ENDIF
          IF Debounce(X) > 0 THEN           ; If debouncing
            Debounce(X) = Debounce(X) - 1   ;   decrement the counter
            IF Debounce(X) = 0 THEN         ;   when it gets to 0
              Pressed = !PinState           ;  button is stable, get the state
              
              IF Pressed THEN               ;==== Button Pressed Event =========
                IF ChargeMode THEN          ;   If we're in charge mode
                   ChargeMode = 0           ;     cancel charge mode
                   Counters(X) = 0          ;     clear the counter
                   GOSUB TriacOFF           ;   turn off the triac
                ELSE
                  IF ProgramMode THEN       ;---- Program Mode------------------
                    IF ChargeTime(X) < MaxCharge THEN ; limit to Max charge time
                      Counters(X) = ProgHold          ; reset Prog mode Timeout
                      ChargeTime(X) = ChargeTime(X) + 1  ; increment # of hours
                      GOSUB Beep            ; beep on each button press
                    ELSE                    ; If Max has been reached
                      sound pz,[123,10]     ;   funky beep
                      sound pz,[50,10]
                    ENDIF
                  ELSE                      ;---- Normal Mode ------------------
                    ProgCounter (X) = ProgDelay  ; start program detect delay
                    IF Counters(X) = 0 THEN      ;  if not counting yet
                      Counters(X) = ChargeDelay  ;  Set Delay before Charge mode
    '                  READ X, ChargeTime(X)      ; get charge time from EEPROM
    '                  for i = 1 to ChargeTime(X) ; beep once for each hour
    '                    GOSUB Beep               ;  so user knows current 
    '                  next i                     ; charge time before it starts
                      GOSUB LEDON                ;  turn on LED
                    ENDIF
                  ENDIF
                ENDIF
              ELSE                          ;---- button released --------------
                ProgCounter (X) = 0         ;  stop looking for program press
              ENDIF
            ENDIF
          ENDIF
          
          
          IF ProgCounter(X) > 0 THEN        ;---- Program Delay counter --------
             ProgCounter(X) = ProgCounter(X) - 1
             IF ProgCounter(X) = 0 THEN     ; when it times out
               Counters(X) = 0              ;   stop the Charge Delay period
               Counters(X) = ProgHold       ;   reset Program inactivity Timeout
               ChargeTime(X) = 0            ;   clear the hour counter
               for i = 1 to 11              ;   beep 11 times as requested
                 GOSUB Beep
               next i
               ProgramMode = 1              ;   -- Enter Program Mode --
             ENDIF
          ENDIF
          
          IF Counters(X) > 0 THEN            ;---- Main Delay Timers------------
            IF ChargeMode THEN               ;** In Charge Mode, time counts 
              IF SecondsChanged THEN         ;                    in seconds  **
                Counters(X) = Counters(X) - 1
                IF Counters(X) = 0 THEN      ;   End of Charge Time
                  GOSUB TriacOFF             ;     turn off the Triac
                  ChargeMode = 0             ;     cancel charge mode
                ENDIF
              ENDIF
            ELSE
              Counters(X) = Counters(X) - 1  ;** Normal mode counts ms **
              IF Counters(X) = 0 THEN        ; if counter timed out
                IF ProgramMode THEN          ;   and already in prog mode
                  ProgramMode = 0            ;   End Programming Mode
                  GOSUB LEDOFF               ;   everything OFF
                  GOSUB TriacOFF
                  IF ChargeTime(X) > 0 THEN  ; if user entered a charge time
                    WRITE X, ChargeTime(X)   ;   save it to EEPROM
                  ELSE                       ; if user didn't enter charge time
                    READ X, ChargeTime(X)    ;   restore time from EEPROM
                  ENDIF
                  for i = 1 to ChargeTime(X) ; beep once for each hour
                    GOSUB Beep
                  next i
                ELSE                         ;---- End of delay before charge --
                  ProgCounter(X) = 0         ;   Stop looking for program press
                  GOSUB LEDOFF               ;   LED OFF
                  GOSUB TriacON              ;   Triac ON - Start Charge
                  READ  X, TempW             ; Get charge time from EEPROM
                  Counters(X) = TempW * 3600 ; seconds to charge
                  ChargeMode = 1
                ENDIF
              ENDIF
            ENDIF
          ENDIF
          
          ChannelStates(X) = ChannelState   ; save channels state flags
        NEXT X                              ; Do the next channel
        SecondsChanged = 0                  ; clear SecondsChanged notification
    GOTO Main
    
    ;----I/O for each channel---------------------------------------------------
    GetSWState:
      SELECT CASE X                ; get state of this channels pin
        CASE 0 : PinState = SW1
        CASE 1 : PinState = SW2
        CASE 2 : PinState = SW3
        CASE 3 : PinState = SW4
        CASE 4 : PinState = SW5
        CASE 5 : PinState = SW6
        END SELECT
    RETURN
    
    LEDON:
      SELECT CASE X                ; turn ON the appropriate LED
        CASE 0 : HIGH led1
        CASE 1 : HIGH led2
        CASE 2 : HIGH led3
        CASE 3 : HIGH led4
        CASE 4 : HIGH led5
        CASE 5 : HIGH led6
      END SELECT
    RETURN
    
    LEDOFF:
      SELECT CASE X                ; turn OFF the appropriate LED
        CASE 0 : LOW led1
        CASE 1 : LOW led2
        CASE 2 : LOW led3
        CASE 3 : LOW led4
        CASE 4 : LOW led5
        CASE 5 : LOW led6
      END SELECT
    RETURN
    
    TriacON:
      SELECT CASE X                ; turn ON the channels Triac
        CASE 0 : HIGH TR1
        CASE 1 : HIGH TR2
        CASE 2 : HIGH TR3
        CASE 3 : HIGH TR4
        CASE 4 : HIGH TR5
        CASE 5 : HIGH TR6
      END SELECT
    RETURN
    
    TriacOFF:
      SELECT CASE X                ; turn OFF the channels Triac
        CASE 0 : LOW TR1
        CASE 1 : LOW TR2
        CASE 2 : LOW TR3
        CASE 3 : LOW TR4
        CASE 4 : LOW TR5
        CASE 5 : LOW TR6
      END SELECT
    RETURN
    
    ;----Beep-------------------------------------------------------------------
    Beep:
      GOSUB LEDON                           ; flash LED when beeping
      sound pz,[123,10]
      GOSUB LEDOFF
      pause 50
    RETURN
    There are a few commented lines in the "Normal Mode" section that will beep the number of hours when entering the "Delay before Charge" time. I thought it was handy to know how long it was set for before it starts charging.

    HTH,

  6. #6
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    Like I was saying I was just fiddling with my code (nothing close to final version)

    Now my code has 444 lines and yours has 234 and it does the same thing!

    Its just like when my wife tells me a story and then I tell the same story...

    This is helping me out a great deal (not my wife's stories but your version of the code) in fact everyone of your posts in this thread and in other threads have helpd me understand better.

    I can't figure out if you are 65 years old and you have done this all your life or if you are 16 and living in a bubble filled with pics but you are a master at what you are doing, you where very helpful and I appreciate everything you did. Not only for me but also for others.

    Thanks Darrel, you are the best!

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lilimike View Post
    I can't figure out if you are 65 years old and you have done this all your life or if you are 16 and living in a bubble filled with pics
    All of the above.
    16 Inside, 65 outside, and chronologically hitting the big five-OH this year.
    If I'm not playing with PICs, I'm playing video games online.
    OK, maybe it's 14 inside.

    Its just like when my wife tells me a story and then I tell the same story...
    No wifey, but I can totally relate ...

    Let me know how it all ends up.
    <br>
    DT

Similar Threads

  1. How to drive the Vinculum VDIP1 in UART mode
    By BrianT in forum Code Examples
    Replies: 41
    Last Post: - 23rd May 2013, 12:34
  2. USB-FTDI[UM232R] with PIC16f877a
    By bjox in forum USB
    Replies: 1
    Last Post: - 23rd February 2008, 22:40
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Serial Output 10 Bits
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th May 2005, 02:14
  5. Using 4 input to control 10 output
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th November 2004, 12:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts