Help with realtime clock and timer


Closed Thread
Results 1 to 21 of 21

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Oh yeah, I forgot,

    The only real problem I found in the program was that the Comparator Interrupt section is resetting the Enable bit instead of the Interrupt Flag.

    After the first time through, the comparator won't cause an interrupt anymore. But, it will keep the External Interrupt section from ever executing.<br>
    Last edited by Darrel Taylor; - 1st October 2005 at 20:17.
    DT

  2. #2
    geselaw's Avatar
    geselaw Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you Darrel for your suggestion ,here is the new code.

    COMP_INT BSF _Charger ;porta.0 will be on.it will be used for charging the battery
    MOVF CMCON,F ;read and clear comparator mismatch condition
    bcf PIR1, CMIF ;clear comparator interrupt flag
    movf _hour,w ;*** read hour to w register
    addlw 008h ;*** add 8 to hour which is in the w register
    movwf _Bat_hour ;move the result to the Bat_hour var
    goto Unsave

    The schematic was never meant to be published ,it was only for reference.I know this is lame excuse so I am working on it and I will post it ASAP.In the mean time you said you don't like the circuit,good. Which part do you think need improvement/change. I don't ask people to do my leg work for me .All I am asking is for suggestion.

    I am a Network Engineer by profession never had formal education in electronics. All the small things I know ,I learned it from internet. I really need to make this project work .Please help.

  3. #3
    geselaw's Avatar
    geselaw Guest


    Did you find this post helpful? Yes | No

    Default New Schematic

    I have tried to make the schematic readable. The schematic that I posted last time was unreadable even to me ,and I found so many silly mistakes and tried to correct them. If you find any more mistakes ,it is just because I don't know better for the time being ,but I am hear to learn.

    I have also made minor correction under the "Start" Label

    Start:

    'Initial Battery charging (if not intiated yet by low battery from assembely interupt)
    if (charger = 1) and (bat_hour != 0) then 'This will stop the programe from adding another charging-
    goto System_Start '-hour if the battery is already being charged caused by low battery-
    endif '-in the begining of the programe
    bat_hour = hour + 8 '*** charge the battery no matter what at start
    charger = 1 'Charge pin on
    Attached Images Attached Images  

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Look, lets start with basics...

    1. Go download the Datasheet for your PIC...
    2. Go see where the Crystal IS SUPPOSED TO BE CONNECTED

    Come back and tell us which pins it has got to be nailed to, and then tell us why you insist on having it on RB6/7 in your schematic. This I've got to hear...

    And whilst were teaching schematics, you never, ever, ever draw lines or connections through a component! Go around it.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Looks like he's using the internal osc with external crystal for Timer1, but there are still a TON of errors in that schematic.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    geselaw's Avatar
    geselaw Guest


    Did you find this post helpful? Yes | No

    Default

    As you could see in my program("@ device intrc_osc_noclkout" and "PCON.3=1") , I am using the built-in 4MHz internal OSC .The one you see on the schematic was the one that I used for the real time clock on Tmr1 (32.768khz). You will find below the device setup that I used for quick reference.

    Could you please tell me those errors that you saw in the schematic ? I some times have second thought about mixing the digital circuit with the main power (ACS108). I found an error in the schematic and corrected it.The collector part of the phototransistor was connected to the Gnd. It should have been connected to the +ve.The new schematic is attached.

    DEFINE INTHAND myint
    @ device intrc_osc_noclkout
    @ device wdt_off
    @ device lvp_off
    @ device pwrt_on
    @ device cpd_off
    @ device bod_off
    @ device mclr_off
    @ device PROTECT_OFF

    ' **************
    ' *Device setup*
    ' **************
    PIE1.6 = 0 'disable the comparator before mesing with cmcon & vrcon
    VRCON = %10001011 'Voltage Refernece enabled and voltage = 2.97
    pause 10 'for stabiliazing
    CMCON = %10000101 'Single comparator enabled RA0 & RA3 are free for I/O
    PAUSE 10
    PIR1.6 = 0 'clear residing interrupt flag
    PIE1.6 = 1 'enable comparator flag
    pcon.3=1 '1=Internal oscillator 4mhz ,0=37khz
    T1con =%00001111 ' Turn on Timer1 with prescaler = 1
    Pir1.0 = 0 'disable comp & timr1 int flag
    trisb = %00000001
    trisa = %10100110 'PortA 1&2 are analog input ,the rest are digital I/O
    PIE1.0 = 1 ' Enable TMR1 overflow and Comparator interrupt
    INTCON = %11010000 ' Enable global ,peripheral , external interrupts
    Attached Images Attached Images  
    Last edited by geselaw; - 5th October 2005 at 16:17. Reason: Add

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


    Did you find this post helpful? Yes | No

    Default

    geselaw,

    Got your PM. Been gone for a couple days.

    While I'm not real "keen" on the idea of tying AC neutral to VDD, I understand why you did it (for the ACS108's). And if all electricians were guaranteed to wire everything correctly, it may not be a problem. But one day your going to plug this thing into an outlet that's been wired backwards, and somebody's going to get a RUDE awakening when they touch it. Personally, I would use an optically isolated solid state relay, but then, that's just me.

    I see you've increased the resistance to the LED's in the interrupters good, but you didn't increase the ones going to the normal LED's. They'll not last very long with only 15 ohms.

    The collector side of the photo-transistors, after going through the sensitivity adjustment pots, connect to Vss. They need to go to VDD instead.

    The MCLR pin is connected to the 5V out from the 7805. The PIC will RESET when you are trying to run on battery power. It needs to be after the ICL7673. Also, what is R1?

    Hey Bruce, do you see anything else?
    <br>
    DT

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Clock with timer interrupt0
    By boban in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th November 2009, 14:59
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  5. clock and date without using real timer
    By eepro in forum Off Topic
    Replies: 1
    Last Post: - 21st September 2008, 02:38

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