clock devider 2

本文介绍了一种实现时钟频率除法器的方法,包括产生50%占空比的奇数除频和无占空比限制的1.5倍频。通过使用计数器和移位寄存器,结合逻辑门操作,实现了特定频率的时钟信号生成。

A clock frequency odd divider with nearly 50% duty.

ex1. the odd divider number is 3.

1. Using the posedge of clock, a 2-bit counter is cyclically added up from 0 to 2, and the new clock_1 will be reversed when cnt is 0 and 1. The counter can be replace with a 3-bit shift register.

2. Using the negedge of clock, repeat step 1.

3.  Using logic AND operator, and the new clock_1 to the new clock_2.

4.  The resule of step 3 is just the 3-divider clock with 50% duty.

 

ex2.A clock frequency 1.5-divider with no duty limited.

1~2. Repeat the step 1~2.

3. Shift the new clock_2, and the new clock_3 is got.

4. Then using the OR operator, OR the the new clock_1 to the new clock_3.

5. The resule of step 4 is just the 1.5-divider clock with no duty limited.

 

Note, The adder in step 1~2 can be replaced with a shift register, which just like using one-hot code.

### 发布时钟消息到ROS2话题 `/clock` 为了实现向`/clock`主题发布时钟消息,在ROS2环境中通常会创建一个专门用于此目的的节点。该节点利用rclcpp库中的功能来定时发送rosgraph_msgs::msg::Clock类型的消息。 下面是一个简单的C++代码示例,展示了如何构建这样一个发布者节点: ```cpp #include "rclcpp/rclcpp.hpp" #include "rosgraph_msgs/msg/clock.hpp" int main(int argc, char * argv[]) { rclcpp::init(argc, argv); auto node = std::make_shared<rclcpp::Node>("clock_publisher"); // 创建publisher对象并指定要发布的topic名称以及消息类型 auto publisher = node->create_publisher<rosgraph_msgs::msg::Clock>("/clock", 10); // 使用wall timer定期触发回调函数以发布新的时间戳数据 rclcpp::WallTimerBase::SharedPtr timer = node->create_wall_timer( std::chrono::seconds(1), [&]() { auto message = rosgraph_msgs::msg::Clock(); message.clock = builtin_interfaces::msg::Time(); message.clock.sec = static_cast<builtin_interfaces::msg::Time::_sec_type>( rclcpp::Clock().now().seconds()); RCLCPP_INFO(node->get_logger(), "Publishing time: '%d'", message.clock.sec); publisher->publish(message); }); rclcpp::spin(node); // 进入循环等待直到程序结束 rclcpp::shutdown(); return 0; } ``` 这段代码定义了一个名为`clock_publisher`的新节点,它每隔一秒就会往`/clock`这个主题上广播当前的时间戳信息[^1]。 当涉及到生命周期管理的时候,可以按照之前提到的状态转换命令操作对应的节点实例,比如通过命令行工具将其从初始未配置状态逐步转变为活跃状态以便正常工作[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值