Counting timing with blinking led.

banda

Member
I am taking advice and am not going to give up on what I think could turn out to be an absorbing pastime.
I'm still full of questions though.
I've started back from scratch, and I ask advice because I could easily have made some beginner's booboo.

I run the following with 28x2 and an LED. I am using PICAXE VSM.

main:
for b1=0 to 9
high C.4
pause 500
low C.4
pause 500
next b1
end

For me, the timing is irregular, some short spells and others longer.
Is that to be expected?
I don't expect accurate split second timing, but shouldn't it be regular?
 

Technical

Technical Support
Staff member
The program is fine and also looks fine (similar on/off times) to us on a simple VSM simulation. Maybe post your .dsn file as an attachment so we can test it.
 

banda

Member
Thanks very much for your help.
I'm embarrassed to say that when I started everything up this morning the flashing was spot on.
It did vary at times yesterday though. I guess I must have nooby-like interfered with something in the guts of the machine.

I do have a far more important (for me) question though.

Is there anyone out there willing to show me a complete, working example of
SETTING A DS1307, AND READING THE TIME ON AN LCD OR A VIRTUAL TERMINAL?
I've spent days trying out the snippets that people and the tutorials have made public, but I'm too dumb to do the whole thing.

I am using PICAXE VSM, and I think I might be able to analyse a completed project rather than try to build one.
From there I might be able to add an alarm and generally progress.

Thanks vey much for anyone's help .
 

lbenson

Senior Member
This simulates correctly in PE6.

In the PE6 simulation pane, click options, check DS1307, LCD 2x16, Axe033. Click Simulate and run. Sertxd output looks ok. This should work on a real chip & LCD or in VSM. Time should be updated every 9 seconds or so. Leading zero needs to be added for single-digit numbers (exercise left to the reader).
Code:
  ' simulate date time
  symbol year=b20
  symbol month=b21
  symbol day=b22
  symbol hour=b23
  symbol minute=b24
  symbol second=b25

  symbol num = b26
  symbol loopCounter = b27

  i2cslave %11010000, i2cslow, i2cbyte ' ds1307 module i2c eeprom address
  writei2c 0, ($00, $36, $10, $01, $02, $03, $14, $10) ' smhwdmy
  pause 5000

do
  gosub getDateTime
  serout c.0,n2400,(254,128,255) ' clear and move to start of first line
  pause 200
  serout c.0,n2400,("Date: ", #year,":",#month,":",#day)
  pause 1000
  serout c.0,n2400,(254,192,255) ' move to start of second line 
  pause 200
  serout c.0,n2400,("Time: ", #hour,":",#minute,":",#second)
  pause 5000
loop

getDateTime:  
    i2cslave %11010000, i2cslow, i2cbyte ' ds1307 module i2c eeprom address
'  writei2c 0, ($00, $22, $20, $00, $04, $01, $14, $10) ' smhwdmy
  pause 40
  gosub getDate
  sertxd ("Date is ", #year,":",#month,":",#day,13,10)
  gosub getTime
  sertxd ("Time is ", #hour,":",#minute,":",#second,13,10)
'  goto continue1
  return

getTime:
  readi2c 0, (b1,b2,b3)
  bcdtoascii b1, b5, b6
  second = b5-"0"*10+b6-"0"
  b4 = b2
  bcdtoascii b4, b1, b2
  minute = b1-"0"*10+b2-"0"
'sertxd ("n4 n1 n2 minute: ", #n4," ",n1," ",n2," ",#minute, 13, 10)
  bcdtoascii b3, b4, b5
  hour = b4-"0"*10+b5-"0"
  return

getDate:  ' 
  readi2c 0, (b1,b2,b3,b1,b1,b2,b3) ' xxxxdmy
'    sertxd ("Getting Date ", #n1," ",#n2," ",#n3, 13, 10)
  'day = bcdtobin n1
  'month = bcdtobin n2
  'year = bcdtobin n3
  bcdtoascii b1, b5, b6
  day = b5-"0"*10+b6-"0"
  b4 = b2
  bcdtoascii b2, b5, b6
  month = b5-"0"*10+b6-"0"
  bcdtoascii b3, b5, b6
  year = b5-"0"*10+b6-"0"
  return
Corrections to code welcomed.
 

Attachments

Last edited:

banda

Member
Thanks very much Ibenson. You have given me something to get my teeth into.
However, you say that the time is updated every 9 secs. What I get is the SAME date and time entry
that we used to SET the ds1307, REPEATED every 9seconds. That is readable on the AXE033, from the PE6, Date: 14:3:12 etc
but when running the full program the AXE033 only reads Time: 0:0:0 and Date: 0:0:0.
The virtual screen repeats the SETUP values only.

Does that mean that I'm not connected to the clock? What do you think?

I'd still like anyone else who has a working example of what I want, to let me see it.
With more than one example I feel I could learn a lot more.

Thanks to all.
 

lbenson

Senior Member
I don't have VSM so I don't know whether it actually simulates the DS1307 the way PE6 does. Should work with real chips, though.

It sounds like you're either not connected to the DS1307, or the DS1307 is not simulated in VSM. What kind of simulation do you want to do which cannot be accomplished in PE6?

What do you mean by "running the full program?" Post program maybe?

In the PE6 simulator, I see the time being updated. Do you not? Post code.
 

banda

Member
I'm so new to this I don't know how to post code in that nice little box.
I can only say that the time doesn't advance in my PICAXE VMS.
I've tried to study the Sample Design called AXE110 PICAXE 18X - New Datalogger Mission Logger.
I can't see where the clock is connected to the readings at all. I don't think it is.

I can't help thinking though that we're at cross purposes.
I am dealing ONLY with PICAXE VSM. For me to follow, everything must operate solely on PICAXE VSM.
I imagined that I could learn with PICAXE VSM then later transfer the project to breadboard.
I've tried for weeks to find out how to understand a DS1307 (or better still, ds3232), using only PICAXE VSM.

I can't believe that somewhere in our wide world there isn't someone who can show me how to make a ds1307 work,
using only PICAXE VSM. If I can see a working example I believe I could learn by analysing such an example.

There is another possible reason nobody can show me. It might not be possible to make a d1307 work with PICAXE VSM.
One way or another I'd like to know.

Thanks again for your help.
 

hippy

Technical Support
Staff member
Is there anyone out there willing to show me a complete, working example of SETTING A DS1307, AND READING THE TIME ON AN LCD OR A VIRTUAL TERMINAL?
This code works for me when using PICAXE VSM with the provided AXE110 Datalogger design ...

Code:
SerOut B.7, N4800, ( "DS1307 Test", CR, LF )
HI2cSetup I2cMaster, $D0, I2cSlow, I2cByte

;            SS  MM  HH DOW  DD  MM  YY 
HI2cOut $0,($00,$00,$00,$00,$00,$00,$00,$10)

b8 = -1
do
  Pause 100
  HI2cIn $0,(b0,b1,b2,b3,b4,b5,b6,b7 )
  If b0 <> b8 Then
    b8 = b0 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b1 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b2 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b3 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b4 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b5 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b6 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b7 : Gosub ShowHex : SerOut B.7, N4800, ( " - 20" )
    b8 = b6 : Gosub ShowHex : SerOut B.7, N4800, ( "-" )
    b8 = b5 : Gosub ShowHex : SerOut B.7, N4800, ( "-" )
    b8 = b4 : Gosub ShowHex : SerOut B.7, N4800, ( " " )
    b8 = b2 : Gosub ShowHex : SerOut B.7, N4800, ( ":" )
    b8 = b1 : Gosub ShowHex : SerOut B.7, N4800, ( ":" )
    b8 = b0 : Gosub ShowHex : SerOut B.7, N4800, ( CR, LF )
    b8 = b0
  End If
loop

ShowHex:
  b9 = b8 / $10 + "0"
  If b9 > "9" Then : b9 = b9+7 : End If
  SerOut B.7, N4800, ( b9 )
  b9 = b8 & $0F + "0"
  If b9 > "9" Then : b9 = b9+7 : End If
  SerOut B.7, N4800, ( b9 )
  Return
This initialises the DS1307 to zero so shows elapsed time from starting. You can edit the HI2COUT to set it to some other time or date.
 

hippy

Technical Support
Staff member
I have placed a more complete PICAXE VSM demonstration for using the DS1307 here ...

http://www.picaxeforum.co.uk/showthread.php?25506-PICAXE-VSM-simulation-for-DS1307

It is not clear if this has been your problem but PICAXE VSM does not store DS1307 settings between simulations. So if you run a simulation which sets the DS1307 date and time, that will not be remembered if a simulation is subsequently run which reads a DS1307.

If you double-click the DS1307 within the design there is an option to "Automatically initialize from the PC clock". If not ticked the DS1307 will start counting from "00-00-00 00:00:00", if ticked it will be initialised to the PC's clock. This can be useful if the code does not set the DS1307 itself. If the code does set the DS1307 then this will set the date and time regardless of the initialisation setting.
 

banda

Member
Rejoice! Rejoice! Help has arrived!
Thank you, thank you, thank you Hippy.
Your second, refined programme worked flawlessly,
and I've no doubt your first one will also.
Now I can unstitch your files line by line and find what it's all about.
Great work!

Code:
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
I've also found out how to do this.
 
Top