Shop OBEX P1 Docs P2 Docs Learn Events
Optimized Clock Engine - Page 2 — Parallax Forums

Optimized Clock Engine

2»

Comments

  • KyeKye Posts: 2,200
    edited 2009-10-22 18:02
    @photomankc - Ah, well, just put in a special thanks section for my I2C code and BCD conversion code. I belive you cannot optimize it more than I have done without more complex techniques.

    @propwell - You understanding is dead on. You'll find my driver have been purposefully made to be as novice/idiot proof as possible as I am writing them for high school students. Simply change the pin names and all is good. Also, the DS1307 can just directly connect to the props I/O lines. So Life is easy.

    Also, do you guys like the timing functions included in the driver? They are pretty nice as they have a resolution up to 2^31 of milliseconds or seconds and they loose no accuracy relative to the clock.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • photomankcphotomankc Posts: 943
    edited 2009-10-22 19:39
    @Kye - Will do. My code will not be quite as tight as yours but I can work on that. Having to unpack two and three values from the same register is a pain. I was really impressed by the speed of the I2C spin code. I've been used to about 23KHz even at 100MHz with other more generic spin objects, but with this I'm getting 30+ KHz accourding to my scope at 80MHz clock so pretty nice. I'm figuring that could reach up close to 36KHz on my 100MHz boards.
  • KyeKye Posts: 2,200
    edited 2009-10-22 21:24
    That's a good speed. Its all about just learning to SPIN the code to the right size. Pun intended.

    Take a look at the code posted for faster I2C for EEPROM.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • propwellpropwell Posts: 87
    edited 2009-10-22 23:09
    Hi Kye, thank you so much for your fast answer!
    But i still can't connect to the RTC!
    Attached is my schematics and now the code i use:

    rtc.setSeconds(0)
    rtc.setMinutes(5)
    rtc.setHours(8)
    rtc.setDay(4)
    rtc.setDate(22)
    rtc.setMonth(10)
    rtc.setYear(2009)
    
    seconds:=rtc.getSeconds
    gr.text(-70,-70,sn.decf(seconds,5))
    


    But all i get is a "165"!

    Thank you,
    Max
    772 x 780 - 16K
  • KyeKye Posts: 2,200
    edited 2009-10-23 03:19
    Um, try the code that I put up in the first post vs the code in the obex. Maybe I broke something with all the updates. I don't know however as it works on my end and no ones has complained.

    Everything looks like it should work. Are you sure there aren't any other problems?

    Also note that the driver uses opendrain mode to communicate so if you are driving the outa ports on those pins nothing will function. The I2C code should be the only thing running on those ports.

    Maybe the voltage isn't going low enough? IDK, try a bunch of stuff. I doubt its the driver.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • photomankcphotomankc Posts: 943
    edited 2009-10-23 05:17
    Why do you have series resistors if you are only pulling the SCL and SDA lines to 3.3V?· Looks like that would create a voltage divider that would raise the floor on the bus' 0 state·by a 150mV or so.· Doubt that's the root cause but it doesn't make sense to me either.· I'd try the BasicI2C driver and just test to see if you get a hit from "DevicePresent" on the clock address.· At least then you know the bus works.
  • SapiehaSapieha Posts: 2,964
    edited 2009-10-23 07:30
    Hi photomankc.

    Propeller not have open colector outputs and if You connect that lines directly You can have casses that You drive lines 3.3V from prop and Slave drive lines to GND -- Not good.

    I use 100R to 150R as serie resistors in that casses

    Regards ChJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • photomankcphotomankc Posts: 943
    edited 2009-10-23 13:19
    Sapieha,

    I see what you are saying but if you have pull-ups on both lines then you shouldn't need to drive 3.3V on the bus anyway and as I understood it you should never do that on the SDA line. The driver Kye wrote does not drive SCL from what I see, it just toggles between low and input. Anyway it's probably a moot issue I doubt that is causing his issues here.



    propwell,

    165 means your code is seeing all ones on bus and the BCD conversion code in the driver is returning 150 + 15 since %1111 = 15. When I first started playing with my NXP RTC I had the same issue and it came down to the fact my address was wrong. What do you have for RTC_Address in the driver code and what does the Data Sheet say the address is? Make sure your SCL and SDA lines are what you think they are and not crossed too.
  • SapiehaSapieha Posts: 2,964
    edited 2009-10-23 14:17
    Hi photomankc.

    I have not looked in that code.
    But You can see it as semi-open colector circuit. That Reguire PULL upp·obviously else SCA/SD lines on Slave side can't decide treshold of 1 state.
    BUT still You reguire serie resistors for worst casse scenario.
    In Yours casse look if You have correct Values of Pull upp resistors 4.7-10K. I had problems some times width bad resistors on Pull upp.
    In both casses if it is to small else brocen You can have communications problem betwen IC's

    Sorry my bad English

    Regards
    ChJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha

    Post Edited (Sapieha) : 10/23/2009 2:22:09 PM GMT
  • photomankcphotomankc Posts: 943
    edited 2009-10-23 14:47
    Sapieha,

    No problem.... I understand what you are saying.
  • propwellpropwell Posts: 87
    edited 2009-11-04 09:05
    Hi together!

    i'm getting on with my RTC-project!
    When i don't use the battery, and connect the V_Bat-Pin to Ground, it works!!
    But when i connect V_Bat with the battery (3V), i get he 165s again!

    I'm not sure, but do i have to set the NVRAM anyhow?
    That's the code i use at the moment:
      clk.setMinutes(15)
      clk.setSeconds(10)
      clk.setHours(7)
      repeat   
        i:=clk.getMinutes
        j:=clk.getSeconds
        k:=clk.getHours
        sm.dec(i)
        sm.tx(13)
        sm.dec(j)
        sm.tx(13)
        sm.dec(k)
        sm.tx(13)
        sm.tx(13)  
        waitcnt(10_000_000 + cnt)
    
    



    with battery, i get:
    Parallax Serial Terminal said...

    165
    165
    165

    165
    165
    165

    and without:
    Parallax Serial Terminal said...

    15
    10
    7

    15
    11
    17

    any ideas?

    Thank you very much!

    Max
  • KyeKye Posts: 2,200
    edited 2009-11-04 13:30
    Um, the battery should just be plug and play with it. The NVRAM is just general purpose memory.

    I do not understand why this would not work correctly. Maybe the chip you are using is bad or something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • propwellpropwell Posts: 87
    edited 2009-11-04 13:49
    hi kye,
    hm strange.. so i don't have to start the RTC in a special way? Just run the programm with "setSeconds" and all these functions, and the RTC keeps the time?

    Thank you,
    Max
  • KyeKye Posts: 2,200
    edited 2009-11-05 00:34
    Um, you have to set the seconds first so that the RTC begins to count. Check the data sheet on the ds1307 and look at the oscilator enable bit. I belive my software sets it to run after calling set seconds, but maybe something has changed in your setup.

    So, try setting all of the date values first with the battery attached and then polling for the time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.