BCD output from RTC - is this really BCD?

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI all. I am reading the seconds register from a DS1307 RTC and using Realterm to display the values as hex.

From the data sheet the seconds should be stored as BCD as in the pic:

Now, as I understand, bits 3:0 of the seconds register will only ever be 0 to 9. Bits 7:4 will be 0 to 5, representing 10's of seconds.

I initially display the output with a simple:

uart_putc(sec);

where sec is the seconds.

On the terminal I see 00(hex) to 3B(hex) (0 to 59 decimal): as in the second pic

 

Ok, but I'm confused - if this is BCD shouldn't I see 00(hex) to 59(hex) on the terminal?

I want to set two separate port bits: One for the MS Digit and one for the LS Digit to drive a nixie display:

So for example if the seconds are 34 (dec) then PORTx.3 is set  and PORTy.4 is set all others cleared.

Thanks

Russell

 

 

 

 

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BCD != ASCII

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Yes, understood. I'm just trying to understand how the LS nybble of that register is counting 0 to F (should it not be 0 to 9 ?)

Is the way that I'm displaying it perhaps my issue?

If I do:

uart_putc(sec & 0x0f);

Just to view bits 3:0  - should these not be 0 to 9 only? Am I confusing ASCII in the mix somehow?

Perhaps first I need:

sec = (((sec & 0x70) >> 4)*10)+(sec % 16);// to decimal

Edit: I think my code is doing some conversion before displaying - I need to have another look

regards

Last Edited: Sat. Aug 24, 2019 - 12:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having isolated 4 bits you still need to add '0' to make binary to ASCII conversion. If it was BCD you'll then see only 0..9 but if it's binary you'll see punctuation as well.

Last Edited: Sat. Aug 24, 2019 - 01:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From what I can see in the data sheet, you are right, you should see ...0x08, 0x09, 0x10, 0x11...

 

Gotta run out, no time for more thinking now, sorry.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your display method is not correct.   Calculate the seconds value with:    (((seconds_reg & 0x70)>>4)*10) + (seconds_reg & 0x0f)

Last Edited: Tue. Aug 27, 2019 - 12:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Your display method is not correct.   Calculate the seconds value with:    (((seconds_reg & 0x70)>>4)*10) + (seconds_reg & 0x0f)

 

Only issue is that the datasheet clearly shows that the OP should be able to read BCD data.  Instead the OP is seeing straight HEX.

 

The OP needs to show their code as there must be something that we are missing.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Only issue is that the datasheet clearly shows that the OP should be able to read BCD data.  Instead the OP is seeing straight HEX.

Right.  In particular, I don't see how the chip can be putting out seconds values of 0x0A, 0x0B...0x0F, and so on.

 

I can see that happening if there is a BCD/BINARY flag, but I don't see such a flag.

Last Edited: Tue. Aug 27, 2019 - 01:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:
I can see that happening if there is a BCD/BINARY flag, but I don't see such a flag.

 

Great minds think alike.  I too looked for the flag and found nothing.  I used a DS3234 in a project and it operates much the same as the DS1307.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Edit: I think my code is doing some conversion before displaying - I need to have another look

 

You are wasting your time trying to solve this non-problem- the 'sec' was already converted to binary, which is why he was getting 0-59. No doubt using some library that already does the conversion from bcd to 'sec'.

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

curtvm wrote:
No doubt using some library that already does the conversion from bcd to 'sec'.

Which is why the request to post the  OP's code was made.  You are most likely correct though

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user