Posted By

tecnoplaga on 01/07/19


Tagged

DateTime RTC processors Motorola fpga CDL ATA PLC NXP


Versions (?)

Convert Time To ATA RTC and CDL RTC


 / Published in: C#
 

The Motorola / NXP processors use very specific runtime clock controllers, these can be ATARTC or CDLRTC, these two routines are very useful when we are working in real time with PLC's based on these processors.

  1. /// <summary>
  2. /// Some of the Motorola / NXP processors use this real-time format for their microcontrollers. This small routine provides support to convert time value to the ATARTC format.
  3. /// </summary>
  4. /// <param name="Time">Date time value</param>
  5. /// <returns>A list of bytes in ATARTC format, which is used in some NXP or Motorola microcontrollers.</returns>
  6. public static List<byte> ConvertTimeToATARTC(DateTime Time)
  7. {
  8. List<byte> nums = new List<byte>(6)
  9. {
  10. (byte)((double)Time.Second / 0.25),
  11. (byte)Time.Minute,
  12. (byte)Time.Hour,
  13. (byte)((double)Time.Day / 0.25),
  14. (byte)Time.Month,
  15. (byte)(Time.Year - 1985)
  16. };
  17. List<byte> item = nums;
  18. List<byte> nums1 = item;
  19. item[3] = (byte)(nums1[3] - (byte)(3 - Math.Floor((double)Time.Hour / 6)));
  20. return nums;
  21. }
  22.  
  23. /// <summary>
  24. /// Some of the Motorola / NXP processors use this real-time format for their microcontrollers. This small routine provides support to convert time value to the CDLRTC format.
  25. /// </summary>
  26. /// <param name="Time">Date time value</param>
  27. /// <returns>A list of bytes in CDLRTC format, which is used in some NXP or Motorola microcontrollers.</returns>
  28. public static List<byte> ConvertTimeToCDLRTC(DateTime Time)
  29. {
  30. List<byte> nums = new List<byte>(6)
  31. {
  32. (byte)((double)Time.Second / 0.25),
  33. (byte)Time.Minute,
  34. (byte)Time.Hour,
  35. (byte)Time.Month,
  36. (byte)((double)Time.Day / 0.25),
  37. (byte)(Time.Year - 1985)
  38. };
  39. List<byte> item = nums;
  40. List<byte> nums1 = item;
  41. item[4] = (byte)(nums1[4] - (byte)(3 - Math.Floor((double)Time.Hour / 6)));
  42. return nums;
  43. }

Report this snippet  

You need to login to post a comment.