├── LICENSE.md ├── README.md ├── ubitx_20 ├── ubitx_20.ino ├── ubitx_cat.ino ├── ubitx_factory_alignment.ino ├── ubitx_keyer.ino ├── ubitx_menu.ino ├── ubitx_si5351.ino └── ubitx_ui.ino ├── ubitx_wiring.png └── ubitxv3.pdf /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | uBITX - An Arduino sketch to control the uBITX transceiver 635 | Copyright (C) 2017, Ashhar Farhan 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | uBITX firmware, written for the Raduino/Arduino control of uBITX transceigers 3 | 4 | Copyright (C) 2017, Ashhar Farhan 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_20.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * This source file is under General Public License version 3. 3 | * 4 | * This verision uses a built-in Si5351 library 5 | * Most source code are meant to be understood by the compilers and the computers. 6 | * Code that has to be hackable needs to be well understood and properly documented. 7 | * Donald Knuth coined the term Literate Programming to indicate code that is written be 8 | * easily read and understood. 9 | * 10 | * The Raduino is a small board that includes the Arduin Nano, a 16x2 LCD display and 11 | * an Si5351a frequency synthesizer. This board is manufactured by Paradigm Ecomm Pvt Ltd 12 | * 13 | * To learn more about Arduino you may visit www.arduino.cc. 14 | * 15 | * The Arduino works by starts executing the code in a function called setup() and then it 16 | * repeatedly keeps calling loop() forever. All the initialization code is kept in setup() 17 | * and code to continuously sense the tuning knob, the function button, transmit/receive, 18 | * etc is all in the loop() function. If you wish to study the code top down, then scroll 19 | * to the bottom of this file and read your way up. 20 | * 21 | * Below are the libraries to be included for building the Raduino 22 | * The EEPROM library is used to store settings like the frequency memory, caliberation data, 23 | * callsign etc . 24 | * 25 | * The main chip which generates upto three oscillators of various frequencies in the 26 | * Raduino is the Si5351a. To learn more about Si5351a you can download the datasheet 27 | * from www.silabs.com although, strictly speaking it is not a requirment to understand this code. 28 | * Instead, you can look up the Si5351 library written by xxx, yyy. You can download and 29 | * install it from www.url.com to complile this file. 30 | * The Wire.h library is used to talk to the Si5351 and we also declare an instance of 31 | * Si5351 object to control the clocks. 32 | */ 33 | #include 34 | #include 35 | 36 | /** 37 | The main chip which generates upto three oscillators of various frequencies in the 38 | Raduino is the Si5351a. To learn more about Si5351a you can download the datasheet 39 | from www.silabs.com although, strictly speaking it is not a requirment to understand this code. 40 | 41 | We no longer use the standard SI5351 library because of its huge overhead due to many unused 42 | features consuming a lot of program space. Instead of depending on an external library we now use 43 | Jerry Gaffke's, KE7ER, lightweight standalone mimimalist "si5351bx" routines (see further down the 44 | code). Here are some defines and declarations used by Jerry's routines: 45 | */ 46 | 47 | 48 | /** 49 | * We need to carefully pick assignment of pin for various purposes. 50 | * There are two sets of completely programmable pins on the Raduino. 51 | * First, on the top of the board, in line with the LCD connector is an 8-pin connector 52 | * that is largely meant for analog inputs and front-panel control. It has a regulated 5v output, 53 | * ground and six pins. Each of these six pins can be individually programmed 54 | * either as an analog input, a digital input or a digital output. 55 | * The pins are assigned as follows (left to right, display facing you): 56 | * Pin 1 (Violet), A7, SPARE 57 | * Pin 2 (Blue), A6, KEYER (DATA) 58 | * Pin 3 (Green), +5v 59 | * Pin 4 (Yellow), Gnd 60 | * Pin 5 (Orange), A3, PTT 61 | * Pin 6 (Red), A2, F BUTTON 62 | * Pin 7 (Brown), A1, ENC B 63 | * Pin 8 (Black), A0, ENC A 64 | *Note: A5, A4 are wired to the Si5351 as I2C interface 65 | * * 66 | * Though, this can be assigned anyway, for this application of the Arduino, we will make the following 67 | * assignment 68 | * A2 will connect to the PTT line, which is the usually a part of the mic connector 69 | * A3 is connected to a push button that can momentarily ground this line. This will be used for RIT/Bandswitching, etc. 70 | * A6 is to implement a keyer, it is reserved and not yet implemented 71 | * A7 is connected to a center pin of good quality 100K or 10K linear potentiometer with the two other ends connected to 72 | * ground and +5v lines available on the connector. This implments the tuning mechanism 73 | */ 74 | 75 | #define ENC_A (A0) 76 | #define ENC_B (A1) 77 | #define FBUTTON (A2) 78 | #define PTT (A3) 79 | #define ANALOG_KEYER (A6) 80 | #define ANALOG_SPARE (A7) 81 | 82 | /** 83 | * The Raduino board is the size of a standard 16x2 LCD panel. It has three connectors: 84 | * 85 | * First, is an 8 pin connector that provides +5v, GND and six analog input pins that can also be 86 | * configured to be used as digital input or output pins. These are referred to as A0,A1,A2, 87 | * A3,A6 and A7 pins. The A4 and A5 pins are missing from this connector as they are used to 88 | * talk to the Si5351 over I2C protocol. 89 | * 90 | * Second is a 16 pin LCD connector. This connector is meant specifically for the standard 16x2 91 | * LCD display in 4 bit mode. The 4 bit mode requires 4 data lines and two control lines to work: 92 | * Lines used are : RESET, ENABLE, D4, D5, D6, D7 93 | * We include the library and declare the configuration of the LCD panel too 94 | */ 95 | 96 | #include 97 | LiquidCrystal lcd(8,9,10,11,12,13); 98 | 99 | /** 100 | * The Arduino, unlike C/C++ on a regular computer with gigabytes of RAM, has very little memory. 101 | * We have to be very careful with variables that are declared inside the functions as they are 102 | * created in a memory region called the stack. The stack has just a few bytes of space on the Arduino 103 | * if you declare large strings inside functions, they can easily exceed the capacity of the stack 104 | * and mess up your programs. 105 | * We circumvent this by declaring a few global buffers as kitchen counters where we can 106 | * slice and dice our strings. These strings are mostly used to control the display or handle 107 | * the input and output from the USB port. We must keep a count of the bytes used while reading 108 | * the serial port as we can easily run out of buffer space. This is done in the serial_in_count variable. 109 | */ 110 | char c[30], b[30]; 111 | char printBuff[2][17]; //mirrors what is showing on the two lines of the display 112 | int count = 0; //to generally count ticks, loops, etc 113 | 114 | /** 115 | * The second set of 16 pins on the Raduino's bottom connector are have the three clock outputs and the digital lines to control the rig. 116 | * This assignment is as follows : 117 | * Pin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 118 | * GND +5V CLK0 GND GND CLK1 GND GND CLK2 GND D2 D3 D4 D5 D6 D7 119 | * These too are flexible with what you may do with them, for the Raduino, we use them to : 120 | * - TX_RX line : Switches between Transmit and Receive after sensing the PTT or the morse keyer 121 | * - CW_KEY line : turns on the carrier for CW 122 | */ 123 | 124 | #define TX_RX (7) 125 | #define CW_TONE (6) 126 | #define TX_LPF_A (5) 127 | #define TX_LPF_B (4) 128 | #define TX_LPF_C (3) 129 | #define CW_KEY (2) 130 | 131 | /** 132 | * These are the indices where these user changable settinngs are stored in the EEPROM 133 | */ 134 | #define MASTER_CAL 0 135 | #define LSB_CAL 4 136 | #define USB_CAL 8 137 | #define SIDE_TONE 12 138 | //these are ids of the vfos as well as their offset into the eeprom storage, don't change these 'magic' values 139 | #define VFO_A 16 140 | #define VFO_B 20 141 | #define CW_SIDETONE 24 142 | #define CW_SPEED 28 143 | 144 | /** 145 | * The uBITX is an upconnversion transceiver. The first IF is at 45 MHz. 146 | * The first IF frequency is not exactly at 45 Mhz but about 5 khz lower, 147 | * this shift is due to the loading on the 45 Mhz crystal filter by the matching 148 | * L-network used on it's either sides. 149 | * The first oscillator works between 48 Mhz and 75 MHz. The signal is subtracted 150 | * from the first oscillator to arriive at 45 Mhz IF. Thus, it is inverted : LSB becomes USB 151 | * and USB becomes LSB. 152 | * The second IF of 12 Mhz has a ladder crystal filter. If a second oscillator is used at 153 | * 57 Mhz, the signal is subtracted FROM the oscillator, inverting a second time, and arrives 154 | * at the 12 Mhz ladder filter thus doouble inversion, keeps the sidebands as they originally were. 155 | * If the second oscillator is at 33 Mhz, the oscilaltor is subtracated from the signal, 156 | * thus keeping the signal's sidebands inverted. The USB will become LSB. 157 | * We use this technique to switch sidebands. This is to avoid placing the lsbCarrier close to 158 | * 12 MHz where its fifth harmonic beats with the arduino's 16 Mhz oscillator's fourth harmonic 159 | */ 160 | 161 | // the second oscillator should ideally be at 57 MHz, however, the crystal filter's center frequency 162 | // is shifted down a little due to the loading from the impedance matching L-networks on either sides 163 | #define SECOND_OSC_USB (56995000l) 164 | #define SECOND_OSC_LSB (32995000l) 165 | //these are the two default USB and LSB frequencies. The best frequencies depend upon your individual taste and filter shape 166 | #define INIT_USB_FREQ (11996500l) 167 | // limits the tuning and working range of the ubitx between 3 MHz and 30 MHz 168 | #define LOWEST_FREQ (3000000l) 169 | #define HIGHEST_FREQ (30000000l) 170 | 171 | //we directly generate the CW by programmin the Si5351 to the cw tx frequency, hence, both are different modes 172 | //these are the parameter passed to startTx 173 | #define TX_SSB 0 174 | #define TX_CW 1 175 | 176 | char ritOn = 0; 177 | char vfoActive = VFO_A; 178 | int8_t meter_reading = 0; // a -1 on meter makes it invisible 179 | unsigned long vfoA=7150000L, vfoB=14200000L, sideTone=800, usbCarrier; 180 | unsigned long frequency, ritRxFrequency, ritTxFrequency; //frequency is the current frequency on the dial 181 | 182 | int cwSpeed = 100; //this is actuall the dot period in milliseconds 183 | extern int32_t calibration; 184 | 185 | /** 186 | * Raduino needs to keep track of current state of the transceiver. These are a few variables that do it 187 | */ 188 | boolean txCAT = false; //turned on if the transmitting due to a CAT command 189 | char inTx = 0; //it is set to 1 if in transmit mode (whatever the reason : cw, ptt or cat) 190 | char splitOn = 0; //working split, uses VFO B as the transmit frequency, (NOT IMPLEMENTED YET) 191 | char keyDown = 0; //in cw mode, denotes the carrier is being transmitted 192 | char isUSB = 0; //upper sideband was selected, this is reset to the default for the 193 | //frequency when it crosses the frequency border of 10 MHz 194 | byte menuOn = 0; //set to 1 when the menu is being displayed, if a menu item sets it to zero, the menu is exited 195 | unsigned long cwTimeout = 0; //milliseconds to go before the cw transmit line is released and the radio goes back to rx mode 196 | unsigned long dbgCount = 0; //not used now 197 | unsigned char txFilter = 0; //which of the four transmit filters are in use 198 | boolean modeCalibrate = false;//this mode of menus shows extended menus to calibrate the oscillators and choose the proper 199 | //beat frequency 200 | /** 201 | * Below are the basic functions that control the uBitx. Understanding the functions before 202 | * you start hacking around 203 | */ 204 | 205 | /** 206 | * Select the properly tx harmonic filters 207 | * The four harmonic filters use only three relays 208 | * the four LPFs cover 30-21 Mhz, 18 - 14 Mhz, 7-10 MHz and 3.5 to 5 Mhz 209 | * Briefly, it works like this, 210 | * - When KT1 is OFF, the 'off' position routes the PA output through the 30 MHz LPF 211 | * - When KT1 is ON, it routes the PA output to KT2. Which is why you will see that 212 | * the KT1 is on for the three other cases. 213 | * - When the KT1 is ON and KT2 is off, the off position of KT2 routes the PA output 214 | * to 18 MHz LPF (That also works for 14 Mhz) 215 | * - When KT1 is On, KT2 is On, it routes the PA output to KT3 216 | * - KT3, when switched on selects the 7-10 Mhz filter 217 | * - KT3 when switched off selects the 3.5-5 Mhz filter 218 | * See the circuit to understand this 219 | */ 220 | 221 | void setTXFilters(unsigned long freq){ 222 | 223 | if (freq > 21000000L){ // the default filter is with 35 MHz cut-off 224 | digitalWrite(TX_LPF_A, 0); 225 | digitalWrite(TX_LPF_B, 0); 226 | digitalWrite(TX_LPF_C, 0); 227 | } 228 | else if (freq >= 14000000L){ //thrown the KT1 relay on, the 30 MHz LPF is bypassed and the 14-18 MHz LPF is allowd to go through 229 | digitalWrite(TX_LPF_A, 1); 230 | digitalWrite(TX_LPF_B, 0); 231 | digitalWrite(TX_LPF_C, 0); 232 | } 233 | else if (freq > 7000000L){ 234 | digitalWrite(TX_LPF_A, 1); 235 | digitalWrite(TX_LPF_B, 1); 236 | digitalWrite(TX_LPF_C, 0); 237 | } 238 | else { 239 | digitalWrite(TX_LPF_A, 1); 240 | digitalWrite(TX_LPF_B, 1); 241 | digitalWrite(TX_LPF_C, 1); 242 | } 243 | } 244 | 245 | /** 246 | * This is the most frequently called function that configures the 247 | * radio to a particular frequeny, sideband and sets up the transmit filters 248 | * 249 | * The transmit filter relays are powered up only during the tx so they dont 250 | * draw any current during rx. 251 | * 252 | * The carrier oscillator of the detector/modulator is permanently fixed at 253 | * uppper sideband. The sideband selection is done by placing the second oscillator 254 | * either 12 Mhz below or above the 45 Mhz signal thereby inverting the sidebands 255 | * through mixing of the second local oscillator. 256 | */ 257 | 258 | void setFrequency(unsigned long f){ 259 | uint64_t osc_f; 260 | 261 | setTXFilters(f); 262 | 263 | if (isUSB){ 264 | si5351bx_setfreq(2, SECOND_OSC_USB - usbCarrier + f); 265 | si5351bx_setfreq(1, SECOND_OSC_USB); 266 | } 267 | else{ 268 | si5351bx_setfreq(2, SECOND_OSC_LSB + usbCarrier + f); 269 | si5351bx_setfreq(1, SECOND_OSC_LSB); 270 | } 271 | 272 | frequency = f; 273 | } 274 | 275 | /** 276 | * startTx is called by the PTT, cw keyer and CAT protocol to 277 | * put the uBitx in tx mode. It takes care of rit settings, sideband settings 278 | * Note: In cw mode, doesnt key the radio, only puts it in tx mode 279 | */ 280 | 281 | void startTx(byte txMode){ 282 | unsigned long tx_freq = 0; 283 | digitalWrite(TX_RX, 1); 284 | inTx = 1; 285 | 286 | if (ritOn){ 287 | //save the current as the rx frequency 288 | ritRxFrequency = frequency; 289 | setFrequency(ritTxFrequency); 290 | } 291 | 292 | if (txMode == TX_CW){ 293 | //turn off the second local oscillator and the bfo 294 | si5351bx_setfreq(0, 0); 295 | si5351bx_setfreq(1, 0); 296 | 297 | //shif the first oscillator to the tx frequency directly 298 | //the key up and key down will toggle the carrier unbalancing 299 | //the exact cw frequency is the tuned frequency + sidetone 300 | if (isUSB) 301 | si5351bx_setfreq(2, frequency + sideTone); 302 | else 303 | si5351bx_setfreq(2, frequency - sideTone); 304 | } 305 | updateDisplay(); 306 | } 307 | 308 | void stopTx(){ 309 | inTx = 0; 310 | 311 | digitalWrite(TX_RX, 0); //turn off the tx 312 | si5351bx_setfreq(0, usbCarrier); //set back the carrier oscillator anyway, cw tx switches it off 313 | 314 | if (ritOn) 315 | setFrequency(ritRxFrequency); 316 | else 317 | setFrequency(frequency); 318 | 319 | updateDisplay(); 320 | } 321 | 322 | /** 323 | * ritEnable is called with a frequency parameter that determines 324 | * what the tx frequency will be 325 | */ 326 | void ritEnable(unsigned long f){ 327 | ritOn = 1; 328 | //save the non-rit frequency back into the VFO memory 329 | //as RIT is a temporary shift, this is not saved to EEPROM 330 | ritTxFrequency = f; 331 | } 332 | 333 | // this is called by the RIT menu routine 334 | void ritDisable(){ 335 | if (ritOn){ 336 | ritOn = 0; 337 | setFrequency(ritTxFrequency); 338 | updateDisplay(); 339 | } 340 | } 341 | 342 | /** 343 | * Basic User Interface Routines. These check the front panel for any activity 344 | */ 345 | 346 | /** 347 | * The PTT is checked only if we are not already in a cw transmit session 348 | * If the PTT is pressed, we shift to the ritbase if the rit was on 349 | * flip the T/R line to T and update the display to denote transmission 350 | */ 351 | 352 | void checkPTT(){ 353 | //we don't check for ptt when transmitting cw 354 | if (cwTimeout > 0) 355 | return; 356 | 357 | if (digitalRead(PTT) == 0 && inTx == 0){ 358 | startTx(TX_SSB); 359 | delay(50); //debounce the PTT 360 | } 361 | 362 | if (digitalRead(PTT) == 1 && inTx == 1) 363 | stopTx(); 364 | } 365 | 366 | void checkButton(){ 367 | int i, t1, t2, knob, new_knob; 368 | 369 | //only if the button is pressed 370 | if (!btnDown()) 371 | return; 372 | delay(50); 373 | if (!btnDown()) //debounce 374 | return; 375 | 376 | doMenu(); 377 | //wait for the button to go up again 378 | while(btnDown()) 379 | delay(10); 380 | delay(50);//debounce 381 | } 382 | 383 | 384 | /** 385 | * The tuning jumps by 50 Hz on each step when you tune slowly 386 | * As you spin the encoder faster, the jump size also increases 387 | * This way, you can quickly move to another band by just spinning the 388 | * tuning knob 389 | */ 390 | 391 | void doTuning(){ 392 | int s; 393 | unsigned long prev_freq; 394 | 395 | s = enc_read(); 396 | if (s){ 397 | prev_freq = frequency; 398 | 399 | if (s > 10) 400 | frequency += 200000l; 401 | if (s > 7) 402 | frequency += 10000l; 403 | else if (s > 4) 404 | frequency += 1000l; 405 | else if (s > 2) 406 | frequency += 500; 407 | else if (s > 0) 408 | frequency += 50l; 409 | else if (s > -2) 410 | frequency -= 50l; 411 | else if (s > -4) 412 | frequency -= 500l; 413 | else if (s > -7) 414 | frequency -= 1000l; 415 | else if (s > -9) 416 | frequency -= 10000l; 417 | else 418 | frequency -= 200000l; 419 | 420 | if (prev_freq < 10000000l && frequency > 10000000l) 421 | isUSB = true; 422 | 423 | if (prev_freq > 10000000l && frequency < 10000000l) 424 | isUSB = false; 425 | 426 | setFrequency(frequency); 427 | updateDisplay(); 428 | } 429 | } 430 | 431 | /** 432 | * RIT only steps back and forth by 100 hz at a time 433 | */ 434 | void doRIT(){ 435 | unsigned long newFreq; 436 | 437 | int knob = enc_read(); 438 | unsigned long old_freq = frequency; 439 | 440 | if (knob < 0) 441 | frequency -= 100l; 442 | else if (knob > 0) 443 | frequency += 100; 444 | 445 | if (old_freq != frequency){ 446 | setFrequency(frequency); 447 | updateDisplay(); 448 | } 449 | } 450 | 451 | /** 452 | * The settings are read from EEPROM. The first time around, the values may not be 453 | * present or out of range, in this case, some intelligent defaults are copied into the 454 | * variables. 455 | */ 456 | void initSettings(){ 457 | //read the settings from the eeprom and restore them 458 | //if the readings are off, then set defaults 459 | EEPROM.get(MASTER_CAL, calibration); 460 | EEPROM.get(USB_CAL, usbCarrier); 461 | EEPROM.get(VFO_A, vfoA); 462 | EEPROM.get(VFO_B, vfoB); 463 | EEPROM.get(CW_SIDETONE, sideTone); 464 | EEPROM.get(CW_SPEED, cwSpeed); 465 | if (usbCarrier > 12010000l || usbCarrier < 11990000l) 466 | usbCarrier = 11997000l; 467 | if (vfoA > 35000000l || 3500000l > vfoA) 468 | vfoA = 7150000l; 469 | if (vfoB > 35000000l || 3500000l > vfoB) 470 | vfoB = 14150000l; 471 | if (sideTone < 100 || 2000 < sideTone) 472 | sideTone = 800; 473 | if (cwSpeed < 10 || 1000 < cwSpeed) 474 | cwSpeed = 100; 475 | 476 | } 477 | 478 | void initPorts(){ 479 | 480 | analogReference(DEFAULT); 481 | 482 | //?? 483 | pinMode(ENC_A, INPUT_PULLUP); 484 | pinMode(ENC_B, INPUT_PULLUP); 485 | pinMode(FBUTTON, INPUT_PULLUP); 486 | 487 | //configure the function button to use the external pull-up 488 | // pinMode(FBUTTON, INPUT); 489 | // digitalWrite(FBUTTON, HIGH); 490 | 491 | pinMode(PTT, INPUT_PULLUP); 492 | pinMode(ANALOG_KEYER, INPUT_PULLUP); 493 | 494 | pinMode(CW_TONE, OUTPUT); 495 | digitalWrite(CW_TONE, 0); 496 | 497 | pinMode(TX_RX,OUTPUT); 498 | digitalWrite(TX_RX, 0); 499 | 500 | pinMode(TX_LPF_A, OUTPUT); 501 | pinMode(TX_LPF_B, OUTPUT); 502 | pinMode(TX_LPF_C, OUTPUT); 503 | digitalWrite(TX_LPF_A, 0); 504 | digitalWrite(TX_LPF_B, 0); 505 | digitalWrite(TX_LPF_C, 0); 506 | 507 | pinMode(CW_KEY, OUTPUT); 508 | digitalWrite(CW_KEY, 0); 509 | } 510 | 511 | void setup() 512 | { 513 | Serial.begin(9600); 514 | 515 | lcd.begin(16, 2); 516 | 517 | //we print this line so this shows up even if the raduino 518 | //crashes later in the code 519 | printLine1("uBITX v0.20"); 520 | delay(500); 521 | 522 | initMeter(); //not used in this build 523 | initSettings(); 524 | initPorts(); 525 | initOscillators(); 526 | 527 | frequency = vfoA; 528 | setFrequency(vfoA); 529 | updateDisplay(); 530 | 531 | if (btnDown()) 532 | factory_alignment(); 533 | } 534 | 535 | 536 | /** 537 | * The loop checks for keydown, ptt, function button and tuning. 538 | */ 539 | 540 | byte flasher = 0; 541 | void loop(){ 542 | 543 | cwKeyer(); 544 | if (!txCAT) 545 | checkPTT(); 546 | checkButton(); 547 | 548 | //tune only when not tranmsitting 549 | if (!inTx){ 550 | if (ritOn) 551 | doRIT(); 552 | else 553 | doTuning(); 554 | } 555 | 556 | //we check CAT after the encoder as it might put the radio into TX 557 | checkCAT(); 558 | } 559 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_cat.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * The CAT protocol is used by many radios to provide remote control to comptuers through 3 | * the serial port. 4 | * 5 | * This is very much a work in progress. Parts of this code have been liberally 6 | * borrowed from other GPLicensed works like hamlib. 7 | * 8 | * WARNING : This is an unstable version and it has worked with fldigi, 9 | * it gives time out error with WSJTX 1.8.0 10 | */ 11 | 12 | // The next 4 functions are needed to implement the CAT protocol, which 13 | // uses 4-bit BCD formatting. 14 | // 15 | byte setHighNibble(byte b,byte v) { 16 | // Clear the high nibble 17 | b &= 0x0f; 18 | // Set the high nibble 19 | return b | ((v & 0x0f) << 4); 20 | } 21 | 22 | byte setLowNibble(byte b,byte v) { 23 | // Clear the low nibble 24 | b &= 0xf0; 25 | // Set the low nibble 26 | return b | (v & 0x0f); 27 | } 28 | 29 | byte getHighNibble(byte b) { 30 | return (b >> 4) & 0x0f; 31 | } 32 | 33 | byte getLowNibble(byte b) { 34 | return b & 0x0f; 35 | } 36 | 37 | // Takes a number and produces the requested number of decimal digits, staring 38 | // from the least significant digit. 39 | // 40 | void getDecimalDigits(unsigned long number,byte* result,int digits) { 41 | for (int i = 0; i < digits; i++) { 42 | // "Mask off" (in a decimal sense) the LSD and return it 43 | result[i] = number % 10; 44 | // "Shift right" (in a decimal sense) 45 | number /= 10; 46 | } 47 | } 48 | 49 | // Takes a frequency and writes it into the CAT command buffer in BCD form. 50 | // 51 | void writeFreq(unsigned long freq,byte* cmd) { 52 | // Convert the frequency to a set of decimal digits. We are taking 9 digits 53 | // so that we can get up to 999 MHz. But the protocol doesn't care about the 54 | // LSD (1's place), so we ignore that digit. 55 | byte digits[9]; 56 | getDecimalDigits(freq,digits,9); 57 | // Start from the LSB and get each nibble 58 | cmd[3] = setLowNibble(cmd[3],digits[1]); 59 | cmd[3] = setHighNibble(cmd[3],digits[2]); 60 | cmd[2] = setLowNibble(cmd[2],digits[3]); 61 | cmd[2] = setHighNibble(cmd[2],digits[4]); 62 | cmd[1] = setLowNibble(cmd[1],digits[5]); 63 | cmd[1] = setHighNibble(cmd[1],digits[6]); 64 | cmd[0] = setLowNibble(cmd[0],digits[7]); 65 | cmd[0] = setHighNibble(cmd[0],digits[8]); 66 | } 67 | 68 | // This function takes a frquency that is encoded using 4 bytes of BCD 69 | // representation and turns it into an long measured in Hz. 70 | // 71 | // [12][34][56][78] = 123.45678? Mhz 72 | // 73 | unsigned long readFreq(byte* cmd) { 74 | // Pull off each of the digits 75 | byte d7 = getHighNibble(cmd[0]); 76 | byte d6 = getLowNibble(cmd[0]); 77 | byte d5 = getHighNibble(cmd[1]); 78 | byte d4 = getLowNibble(cmd[1]); 79 | byte d3 = getHighNibble(cmd[2]); 80 | byte d2 = getLowNibble(cmd[2]); 81 | byte d1 = getHighNibble(cmd[3]); 82 | byte d0 = getLowNibble(cmd[3]); 83 | return 84 | (unsigned long)d7 * 100000000L + 85 | (unsigned long)d6 * 10000000L + 86 | (unsigned long)d5 * 1000000L + 87 | (unsigned long)d4 * 100000L + 88 | (unsigned long)d3 * 10000L + 89 | (unsigned long)d2 * 1000L + 90 | (unsigned long)d1 * 100L + 91 | (unsigned long)d0 * 10L; 92 | } 93 | 94 | /** 95 | * Responds to all the cat commands, emulates FT-817 96 | */ 97 | 98 | void processCATCommand(byte* cmd) { 99 | byte response[5]; 100 | 101 | // Debugging code, enable it to fix the cat implementation 102 | 103 | count++; 104 | if (cmd[4] == 0x00){ 105 | response[0]=0; 106 | Serial.write(response, 1); 107 | } 108 | else if (cmd[4] == 0x01) { 109 | unsigned long f = readFreq(cmd); 110 | setFrequency(f); 111 | updateDisplay(); 112 | //sprintf(b, "set:%ld", f); 113 | //printLine2(b); 114 | 115 | } 116 | // Get frequency 117 | else if (cmd[4] == 0x03){ 118 | writeFreq(frequency,response); // Put the frequency into the buffer 119 | if (isUSB) 120 | response[4] = 0x01; //USB 121 | else 122 | response[4] = 0x00; //LSB 123 | Serial.write(response,5); 124 | printLine2("cat:getfreq"); 125 | } 126 | else if (cmd[4] == 0x07){ // set mode 127 | if (cmd[0] == 0x00 || cmd[0] == 0x03) 128 | isUSB = 0; 129 | else 130 | isUSB = 1; 131 | response[0] = 0x00; 132 | Serial.write(response, 1); 133 | setFrequency(frequency); 134 | //printLine2("cat: mode changed"); 135 | //updateDisplay(); 136 | } 137 | else if (cmd[4] == 0x88){ 138 | if (inTx){ 139 | stopTx(); 140 | txCAT = false; 141 | } 142 | else 143 | response[0] = 0xf0; 144 | printLine2("tx > rx"); 145 | Serial.write(response,1); 146 | } 147 | else if (cmd[4] == 0x08) { // PTT On 148 | if (!inTx) { 149 | response[0] = 0; 150 | txCAT = true; 151 | startTx(TX_SSB); 152 | updateDisplay(); 153 | } else { 154 | response[0] = 0xf0; 155 | } 156 | Serial.write(response,1); 157 | printLine2("rx > tx"); 158 | } 159 | // Read TX keyed state 160 | else if (cmd[4] == 0x10) { 161 | if (!inTx) { 162 | response[0] = 0; 163 | } else { 164 | response[0] = 0xf0; 165 | } 166 | Serial.write(response,1); 167 | printLine2("cat;0x10"); 168 | } 169 | // PTT Off 170 | else if (cmd[4] == 0x88) { 171 | byte resBuf[0]; 172 | if (inTx) { 173 | response[0] = 0; 174 | } else { 175 | response[0] = 0xf0; 176 | } 177 | Serial.write(response,1); 178 | printLine2("cat;0x88"); 179 | //keyed = false; 180 | //digitalWrite(13,LOW); 181 | } 182 | // Read receiver status 183 | else if (cmd[4] == 0xe7) { 184 | response[0] = 0x09; 185 | Serial.write(response,1); 186 | printLine2("cat;0xe7"); 187 | } 188 | else if (cmd[4] == 0xf5){ 189 | 190 | } 191 | // Read receiver status 192 | else if (cmd[4] == 0xf7) { 193 | response[0] = 0x00; 194 | if (inTx) { 195 | response[0] = response[0] | 0xf0; 196 | } 197 | Serial.write(response,1); 198 | printLine2("cat;0xf7"); 199 | } 200 | else { 201 | //somehow, get this to print the four bytes 202 | ultoa(*((unsigned long *)cmd), c, 16); 203 | itoa(cmd[4], b, 16); 204 | strcat(b, ":"); 205 | strcat(b, c); 206 | printLine2(b); 207 | response[0] = 0x00; 208 | Serial.write(response[0]); 209 | } 210 | 211 | } 212 | 213 | 214 | 215 | void checkCAT(){ 216 | static byte cat[5]; 217 | byte i; 218 | 219 | if (Serial.available() < 5) 220 | return; 221 | 222 | cat[4] = cat[3]; 223 | cat[3] = cat[2]; 224 | cat[2] = cat[0]; 225 | for (i = 0; i < 5; i++) 226 | cat[i] = Serial.read(); 227 | 228 | processCATCommand(cat); 229 | } 230 | 231 | 232 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_factory_alignment.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * This procedure is only for those who have a signal generator/transceiver tuned to exactly 7.150 and a dummy load 4 | */ 5 | 6 | void btnWaitForClick(){ 7 | while(!btnDown()) 8 | delay(50); 9 | while(btnDown()) 10 | delay(50); 11 | delay(50); 12 | } 13 | 14 | void factory_alignment(){ 15 | 16 | factoryCalibration(1); 17 | 18 | if (calibration == 0){ 19 | printLine2("Setup Aborted"); 20 | return; 21 | } 22 | 23 | //move it away to 7.160 for an LSB signal 24 | setFrequency(7160000l); 25 | updateDisplay(); 26 | printLine2("#2 BFO"); 27 | delay(1000); 28 | 29 | usbCarrier = 11994999l; 30 | menuSetupCarrier(1); 31 | 32 | if (usbCarrier == 11994999l){ 33 | printLine2("Setup Aborted"); 34 | return; 35 | } 36 | 37 | 38 | printLine2("#3:Test 3.5MHz"); 39 | isUSB = false; 40 | setFrequency(3500000l); 41 | updateDisplay(); 42 | 43 | while (!btnDown()){ 44 | checkPTT(); 45 | delay(100); 46 | } 47 | 48 | btnWaitForClick(); 49 | printLine2("#4:Test 7MHz"); 50 | 51 | setFrequency(7150000l); 52 | updateDisplay(); 53 | while (!btnDown()){ 54 | checkPTT(); 55 | delay(100); 56 | } 57 | 58 | btnWaitForClick(); 59 | printLine2("#5:Test 14MHz"); 60 | 61 | isUSB = true; 62 | setFrequency(14000000l); 63 | updateDisplay(); 64 | while (!btnDown()){ 65 | checkPTT(); 66 | delay(100); 67 | } 68 | 69 | btnWaitForClick(); 70 | printLine2("#6:Test 28MHz"); 71 | 72 | setFrequency(28000000l); 73 | updateDisplay(); 74 | while (!btnDown()){ 75 | checkPTT(); 76 | delay(100); 77 | } 78 | 79 | printLine2("Alignment done"); 80 | delay(1000); 81 | 82 | isUSB = false; 83 | setFrequency(7150000l); 84 | updateDisplay(); 85 | 86 | } 87 | 88 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_keyer.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * CW Keyer 3 | * 4 | * The CW keyer handles either a straight key or an iambic / paddle key. 5 | * They all use just one analog input line. This is how it works. 6 | * The analog line has the internal pull-up resistor enabled. 7 | * When a straight key is connected, it shorts the pull-up resistor, analog input is 0 volts 8 | * When a paddle is connected, the dot and the dash are connected to the analog pin through 9 | * a 10K and a 2.2K resistors. These produce a 4v and a 2v input to the analog pins. 10 | * So, the readings are as follows : 11 | * 0v - straight key 12 | * 1-2.5 v - paddle dot 13 | * 2.5 to 4.5 v - paddle dash 14 | * 2.0 to 0.5 v - dot and dash pressed 15 | * 16 | * The keyer is written to transparently handle all these cases 17 | * 18 | * Generating CW 19 | * The CW is cleanly generated by unbalancing the front-end mixer 20 | * and putting the local oscillator directly at the CW transmit frequency. 21 | * The sidetone, generated by the Arduino is injected into the volume control 22 | */ 23 | 24 | 25 | // in milliseconds, this is the parameter that determines how long the tx will hold between cw key downs 26 | #define CW_TIMEOUT (600l) 27 | #define PADDLE_DOT 1 28 | #define PADDLE_DASH 2 29 | #define PADDLE_BOTH 3 30 | #define PADDLE_STRAIGHT 4 31 | 32 | //we store the last padde's character 33 | //to alternatively send dots and dashes 34 | //when both are simultaneously pressed 35 | char lastPaddle = 0; 36 | 37 | 38 | //reads the analog keyer pin and reports the paddle 39 | byte getPaddle(){ 40 | int paddle = analogRead(ANALOG_KEYER); 41 | 42 | if (paddle > 800) // above 4v is up 43 | return 0; 44 | 45 | if (paddle > 600) // 4-3v is dot 46 | return PADDLE_DASH; 47 | else if (paddle > 300) //1-2v is dash 48 | return PADDLE_DOT; 49 | else if (paddle > 50) 50 | return PADDLE_BOTH; //both are between 1 and 2v 51 | else 52 | return PADDLE_STRAIGHT; //less than 1v is the straight key 53 | } 54 | 55 | /** 56 | * Starts transmitting the carrier with the sidetone 57 | * It assumes that we have called cwTxStart and not called cwTxStop 58 | * each time it is called, the cwTimeOut is pushed further into the future 59 | */ 60 | void cwKeydown(){ 61 | keyDown = 1; //tracks the CW_KEY 62 | tone(CW_TONE, (int)sideTone); 63 | digitalWrite(CW_KEY, 1); 64 | cwTimeout = millis() + CW_TIMEOUT; 65 | } 66 | 67 | /** 68 | * Stops the cw carrier transmission along with the sidetone 69 | * Pushes the cwTimeout further into the future 70 | */ 71 | void cwKeyUp(){ 72 | keyDown = 0; //tracks the CW_KEY 73 | noTone(CW_TONE); 74 | digitalWrite(CW_KEY, 0); 75 | cwTimeout = millis() + CW_TIMEOUT; 76 | } 77 | 78 | /** 79 | * The keyer handles the straight key as well as the iambic key 80 | * This module keeps looping until the user stops sending cw 81 | * if the cwTimeout is set to 0, then it means, we have to exit the keyer loop 82 | * Each time the key is hit the cwTimeout is pushed to a time in the future by cwKeyDown() 83 | */ 84 | 85 | void cwKeyer(){ 86 | byte paddle; 87 | lastPaddle = 0; 88 | 89 | while(1){ 90 | paddle = getPaddle(); 91 | 92 | // do nothing if the paddle has not been touched, unless 93 | // we are in the cw mode and we have timed out 94 | if (!paddle){ 95 | if (0 < cwTimeout && cwTimeout < millis()){ 96 | cwTimeout = 0; 97 | keyDown = 0; 98 | stopTx(); 99 | } 100 | 101 | if (!cwTimeout) 102 | return; 103 | 104 | //if a paddle was used (not a straight key) we should extend the space to be a full dash 105 | //by adding two more dots long space (one has already been added at the end of the dot or dash) 106 | if (cwTimeout > 0 && lastPaddle != PADDLE_STRAIGHT) 107 | delay(cwSpeed * 2); 108 | 109 | // got back to the begining of the loop, if no further activity happens on the paddle or the straight key 110 | // we will time out, and return out of this routine 111 | delay(5); 112 | continue; 113 | } 114 | 115 | Serial.print("paddle:");Serial.println(paddle); 116 | // if we are here, it is only because the key or the paddle is pressed 117 | if (!inTx){ 118 | keyDown = 0; 119 | cwTimeout = millis() + CW_TIMEOUT; 120 | startTx(TX_CW); 121 | updateDisplay(); 122 | } 123 | 124 | // star the transmission) 125 | // we store the transmitted character in the lastPaddle 126 | cwKeydown(); 127 | if (paddle == PADDLE_DOT){ 128 | delay(cwSpeed); 129 | lastPaddle = PADDLE_DOT; 130 | } 131 | else if (paddle == PADDLE_DASH){ 132 | delay(cwSpeed * 3); 133 | lastPaddle = PADDLE_DASH; 134 | } 135 | else if (paddle == PADDLE_BOTH){ //both paddles down 136 | //depending upon what was sent last, send the other 137 | if (lastPaddle == PADDLE_DOT) { 138 | delay(cwSpeed * 3); 139 | lastPaddle = PADDLE_DASH; 140 | }else{ 141 | delay(cwSpeed); 142 | lastPaddle = PADDLE_DOT; 143 | } 144 | } 145 | else if (paddle == PADDLE_STRAIGHT){ 146 | while (getPaddle() == PADDLE_STRAIGHT) 147 | delay(1); 148 | lastPaddle = PADDLE_STRAIGHT; 149 | } 150 | cwKeyUp(); 151 | //introduce a dot long gap between characters if the keyer was used 152 | if (lastPaddle != PADDLE_STRAIGHT) 153 | delay(cwSpeed); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_menu.ino: -------------------------------------------------------------------------------- 1 | /** Menus 2 | * The Radio menus are accessed by tapping on the function button. 3 | * - The main loop() constantly looks for a button press and calls doMenu() when it detects 4 | * a function button press. 5 | * - As the encoder is rotated, at every 10th pulse, the next or the previous menu 6 | * item is displayed. Each menu item is controlled by it's own function. 7 | * - Eache menu function may be called to display itself 8 | * - Each of these menu routines is called with a button parameter. 9 | * - The btn flag denotes if the menu itme was clicked on or not. 10 | * - If the menu item is clicked on, then it is selected, 11 | * - If the menu item is NOT clicked on, then the menu's prompt is to be displayed 12 | */ 13 | 14 | 15 | 16 | int menuBand(int btn){ 17 | int knob = 0; 18 | int band; 19 | unsigned long offset; 20 | 21 | // band = frequency/1000000l; 22 | // offset = frequency % 1000000l; 23 | 24 | if (!btn){ 25 | printLine2("Band Select?"); 26 | return; 27 | } 28 | 29 | printLine2("Press to confirm"); 30 | //wait for the button menu select button to be lifted) 31 | while (btnDown()) 32 | delay(50); 33 | delay(50); 34 | ritDisable(); 35 | 36 | while(!btnDown()){ 37 | 38 | knob = enc_read(); 39 | if (knob != 0){ 40 | /* 41 | if (band > 3 && knob < 0) 42 | band--; 43 | if (band < 30 && knob > 0) 44 | band++; 45 | if (band > 10) 46 | isUSB = true; 47 | else 48 | isUSB = false; 49 | setFrequency(((unsigned long)band * 1000000l) + offset); */ 50 | if (knob < 0 && frequency > 3000000l) 51 | setFrequency(frequency - 200000l); 52 | if (knob > 0 && frequency < 30000000l) 53 | setFrequency(frequency + 200000l); 54 | if (frequency > 10000000l) 55 | isUSB = true; 56 | else 57 | isUSB = false; 58 | updateDisplay(); 59 | } 60 | delay(20); 61 | } 62 | 63 | while(btnDown()) 64 | delay(50); 65 | delay(50); 66 | 67 | printLine2(""); 68 | updateDisplay(); 69 | menuOn = 0; 70 | } 71 | 72 | void menuVfoToggle(int btn){ 73 | 74 | if (!btn){ 75 | if (vfoActive == VFO_A) 76 | printLine2("Select VFO B? "); 77 | else 78 | printLine2("Select VFO A? "); 79 | } 80 | else { 81 | if (vfoActive == VFO_B){ 82 | vfoB = frequency; 83 | EEPROM.put(VFO_B, frequency); 84 | vfoActive = VFO_A; 85 | printLine2("Selected VFO A "); 86 | frequency = vfoA; 87 | } 88 | else { 89 | vfoA = frequency; 90 | EEPROM.put(VFO_A, frequency); 91 | vfoActive = VFO_B; 92 | printLine2("Selected VFO B "); 93 | frequency = vfoB; 94 | } 95 | 96 | ritDisable(); 97 | setFrequency(frequency); 98 | if (frequency >= 10000000l) 99 | isUSB = true; 100 | else 101 | isUSB = false; 102 | updateDisplay(); 103 | printLine2(""); 104 | delay(1000); 105 | //exit the menu 106 | menuOn = 0; 107 | } 108 | } 109 | 110 | void menuRitToggle(int btn){ 111 | if (!btn){ 112 | if (ritOn == 1) 113 | printLine2("RIT:On, Off? "); 114 | else 115 | printLine2("RIT:Off, On? "); 116 | } 117 | else { 118 | if (ritOn == 0){ 119 | printLine2("RIT is ON"); 120 | //enable RIT so the current frequency is used at transmit 121 | ritEnable(frequency); 122 | } 123 | else{ 124 | printLine2("RIT is OFF"); 125 | ritDisable(); 126 | } 127 | menuOn = 0; 128 | delay(500); 129 | printLine2(""); 130 | updateDisplay(); 131 | } 132 | } 133 | 134 | void menuSidebandToggle(int btn){ 135 | if (!btn){ 136 | if (isUSB == true) 137 | printLine2("Select LSB?"); 138 | else 139 | printLine2("Select USB?"); 140 | } 141 | else { 142 | if (isUSB == true){ 143 | isUSB = false; 144 | printLine2("LSB Selected"); 145 | delay(500); 146 | printLine2(""); 147 | } 148 | else { 149 | isUSB = true; 150 | printLine2("USB Selected"); 151 | delay(500); 152 | printLine2(""); 153 | } 154 | 155 | updateDisplay(); 156 | menuOn = 0; 157 | } 158 | } 159 | 160 | /** 161 | * The calibration routines are not normally shown in the menu as they are rarely used 162 | * They can be enabled by choosing this menu option 163 | */ 164 | void menuSetup(int btn){ 165 | if (!btn){ 166 | if (!modeCalibrate) 167 | printLine2("Setup On?"); 168 | else 169 | printLine2("Setup Off?"); 170 | }else { 171 | if (!modeCalibrate){ 172 | modeCalibrate = true; 173 | printLine2("Setup:On "); 174 | } 175 | else { 176 | modeCalibrate = false; 177 | printLine2("Setup:Off "); 178 | } 179 | delay(2000); 180 | printLine2(""); 181 | menuOn = 0; 182 | } 183 | } 184 | 185 | void menuExit(int btn){ 186 | 187 | if (!btn){ 188 | printLine2("Exit Menu? "); 189 | } 190 | else{ 191 | printLine2("Exiting menu"); 192 | delay(300); 193 | printLine2(""); 194 | updateDisplay(); 195 | menuOn = 0; 196 | } 197 | } 198 | 199 | int menuCWSpeed(int btn){ 200 | int knob = 0; 201 | int wpm; 202 | 203 | wpm = 1200/cwSpeed; 204 | 205 | if (!btn){ 206 | strcpy(b, "CW:"); 207 | itoa(wpm,c, 10); 208 | strcat(b, c); 209 | strcat(b, "WPM Change?"); 210 | printLine2(b); 211 | return; 212 | } 213 | 214 | printLine1("Press PTT to set"); 215 | strcpy(b, "WPM:"); 216 | itoa(wpm,c, 10); 217 | strcat(b, c); 218 | printLine2(b); 219 | delay(300); 220 | 221 | while(!btnDown() && digitalRead(PTT) == HIGH){ 222 | 223 | knob = enc_read(); 224 | if (knob != 0){ 225 | if (wpm > 3 && knob < 0) 226 | wpm--; 227 | if (wpm < 50 && knob > 0) 228 | wpm++; 229 | 230 | strcpy(b, "WPM:"); 231 | itoa(wpm,c, 10); 232 | strcat(b, c); 233 | printLine2(b); 234 | } 235 | //abort if this button is down 236 | if (btnDown()) 237 | //re-enable the clock1 and clock 2 238 | break; 239 | } 240 | 241 | //save the setting 242 | if (digitalRead(PTT) == LOW){ 243 | printLine2("CW Speed set!"); 244 | cwSpeed = 1200/wpm; 245 | EEPROM.put(CW_SPEED, cwSpeed); 246 | delay(2000); 247 | } 248 | printLine2(""); 249 | menuOn = 0; 250 | } 251 | 252 | 253 | 254 | /** 255 | * Take a deep breath, math(ematics) ahead 256 | * The 25 mhz oscillator is multiplied by 35 to run the vco at 875 mhz 257 | * This is divided by a number to generate different frequencies. 258 | * If we divide it by 875, we will get 1 mhz signal 259 | * So, if the vco is shifted up by 875 hz, the generated frequency of 1 mhz is shifted by 1 hz (875/875) 260 | * At 12 Mhz, the carrier will needed to be shifted down by 12 hz for every 875 hz of shift up of the vco 261 | * 262 | */ 263 | 264 | //this is used by the si5351 routines in the ubitx_5351 file 265 | extern int32_t calibration; 266 | extern uint32_t si5351bx_vcoa; 267 | 268 | int factoryCalibration(int btn){ 269 | int knob = 0; 270 | int32_t prev_calibration; 271 | 272 | 273 | //keep clear of any previous button press 274 | while (btnDown()) 275 | delay(100); 276 | delay(100); 277 | 278 | if (!btn){ 279 | printLine2("Set Calibration?"); 280 | return 0; 281 | } 282 | 283 | prev_calibration = calibration; 284 | calibration = 0; 285 | 286 | isUSB = true; 287 | 288 | //turn off the second local oscillator and the bfo 289 | si5351_set_calibration(calibration); 290 | startTx(TX_CW); 291 | si5351bx_setfreq(2, 10000000l); 292 | 293 | strcpy(b, "#1 10 MHz cal:"); 294 | ltoa(calibration/8750, c, 10); 295 | strcat(b, c); 296 | printLine2(b); 297 | 298 | while (!btnDown()) 299 | { 300 | 301 | if (digitalRead(PTT) == LOW && !keyDown) 302 | cwKeydown(); 303 | if (digitalRead(PTT) == HIGH && keyDown) 304 | cwKeyUp(); 305 | 306 | knob = enc_read(); 307 | 308 | if (knob > 0) 309 | calibration += 875; 310 | else if (knob < 0) 311 | calibration -= 875; 312 | else 313 | continue; //don't update the frequency or the display 314 | 315 | si5351_set_calibration(calibration); 316 | si5351bx_setfreq(2, 10000000l); 317 | strcpy(b, "#1 10 MHz cal:"); 318 | ltoa(calibration/8750, c, 10); 319 | strcat(b, c); 320 | printLine2(b); 321 | } 322 | 323 | cwTimeout = 0; 324 | keyDown = 0; 325 | stopTx(); 326 | 327 | printLine2("Calibration set!"); 328 | EEPROM.put(MASTER_CAL, calibration); 329 | initOscillators(); 330 | setFrequency(frequency); 331 | updateDisplay(); 332 | 333 | while(btnDown()) 334 | delay(50); 335 | delay(100); 336 | } 337 | 338 | int menuSetupCalibration(int btn){ 339 | int knob = 0; 340 | int32_t prev_calibration; 341 | 342 | if (!btn){ 343 | printLine2("Set Calibration?"); 344 | return 0; 345 | } 346 | 347 | printLine1("Set to Zero-beat,"); 348 | printLine2("press PTT to save"); 349 | delay(1000); 350 | 351 | prev_calibration = calibration; 352 | calibration = 0; 353 | si5351_set_calibration(calibration); 354 | setFrequency(frequency); 355 | 356 | strcpy(b, "cal:"); 357 | ltoa(calibration/8750, c, 10); 358 | strcat(b, c); 359 | printLine2(b); 360 | 361 | while (digitalRead(PTT) == HIGH && !btnDown()) 362 | { 363 | knob = enc_read(); 364 | 365 | if (knob > 0){ 366 | calibration += 8750; 367 | usbCarrier += 120; 368 | } 369 | else if (knob < 0){ 370 | calibration -= 8750; 371 | usbCarrier -= 120; 372 | } 373 | else 374 | continue; //don't update the frequency or the display 375 | 376 | si5351_set_calibration(calibration); 377 | si5351bx_setfreq(0, usbCarrier); 378 | setFrequency(frequency); 379 | 380 | strcpy(b, "cal:"); 381 | ltoa(calibration/8750, c, 10); 382 | strcat(b, c); 383 | printLine2(b); 384 | } 385 | 386 | //save the setting 387 | if (digitalRead(PTT) == LOW){ 388 | printLine1("Calibration set!"); 389 | printLine2("Set Carrier now"); 390 | EEPROM.put(MASTER_CAL, calibration); 391 | delay(2000); 392 | } 393 | else 394 | calibration = prev_calibration; 395 | 396 | printLine2(""); 397 | initOscillators(); 398 | //si5351_set_calibration(calibration); 399 | setFrequency(frequency); 400 | updateDisplay(); 401 | menuOn = 0; 402 | } 403 | 404 | 405 | void printCarrierFreq(unsigned long freq){ 406 | 407 | memset(c, 0, sizeof(c)); 408 | memset(b, 0, sizeof(b)); 409 | 410 | ultoa(freq, b, DEC); 411 | 412 | strncat(c, b, 2); 413 | strcat(c, "."); 414 | strncat(c, &b[2], 3); 415 | strcat(c, "."); 416 | strncat(c, &b[5], 1); 417 | printLine2(c); 418 | } 419 | 420 | void menuSetupCarrier(int btn){ 421 | int knob = 0; 422 | unsigned long prevCarrier; 423 | 424 | if (!btn){ 425 | printLine2("Set the BFO"); 426 | return; 427 | } 428 | 429 | prevCarrier = usbCarrier; 430 | printLine1("Tune to best Signal"); 431 | printLine2("PTT to confirm. "); 432 | delay(1000); 433 | 434 | usbCarrier = 11995000l; 435 | si5351bx_setfreq(0, usbCarrier); 436 | printCarrierFreq(usbCarrier); 437 | 438 | //disable all clock 1 and clock 2 439 | while (digitalRead(PTT) == HIGH && !btnDown()) 440 | { 441 | knob = enc_read(); 442 | 443 | if (knob > 0) 444 | usbCarrier -= 50; 445 | else if (knob < 0) 446 | usbCarrier += 50; 447 | else 448 | continue; //don't update the frequency or the display 449 | 450 | si5351bx_setfreq(0, usbCarrier); 451 | printCarrierFreq(usbCarrier); 452 | 453 | delay(100); 454 | } 455 | 456 | //save the setting 457 | if (digitalRead(PTT) == LOW){ 458 | printLine2("Carrier set! "); 459 | EEPROM.put(USB_CAL, usbCarrier); 460 | delay(1000); 461 | } 462 | else 463 | usbCarrier = prevCarrier; 464 | 465 | si5351bx_setfreq(0, usbCarrier); 466 | setFrequency(frequency); 467 | updateDisplay(); 468 | printLine2(""); 469 | menuOn = 0; 470 | } 471 | 472 | void menuSetupCwTone(int btn){ 473 | int knob = 0; 474 | int prev_sideTone; 475 | 476 | if (!btn){ 477 | printLine2("Change CW Tone"); 478 | return; 479 | } 480 | 481 | prev_sideTone = sideTone; 482 | printLine1("Tune CW tone"); 483 | printLine2("PTT to confirm. "); 484 | delay(1000); 485 | tone(CW_TONE, sideTone); 486 | 487 | //disable all clock 1 and clock 2 488 | while (digitalRead(PTT) == LOW || !btnDown()) 489 | { 490 | knob = enc_read(); 491 | 492 | if (knob > 0 && sideTone < 2000) 493 | sideTone += 10; 494 | else if (knob < 0 && sideTone > 100 ) 495 | sideTone -= 10; 496 | else 497 | continue; //don't update the frequency or the display 498 | 499 | tone(CW_TONE, sideTone); 500 | itoa(sideTone, b, 10); 501 | printLine2(b); 502 | 503 | delay(100); 504 | } 505 | noTone(CW_TONE); 506 | //save the setting 507 | if (digitalRead(PTT) == LOW){ 508 | printLine2("Sidetone set! "); 509 | EEPROM.put(CW_SIDETONE, usbCarrier); 510 | delay(2000); 511 | } 512 | else 513 | sideTone = prev_sideTone; 514 | 515 | printLine2(""); 516 | updateDisplay(); 517 | menuOn = 0; 518 | } 519 | 520 | void doMenu(){ 521 | int select=0, i,btnState; 522 | 523 | //wait for the button to be raised up 524 | while(btnDown()) 525 | delay(50); 526 | delay(50); //debounce 527 | 528 | menuOn = 2; 529 | 530 | while (menuOn){ 531 | i = enc_read(); 532 | btnState = btnDown(); 533 | 534 | if (i > 0){ 535 | if (modeCalibrate && select + i < 110) 536 | select += i; 537 | if (!modeCalibrate && select + i < 70) 538 | select += i; 539 | } 540 | if (i < 0 && select - i >= 0) 541 | select += i; //caught ya, i is already -ve here, so you add it 542 | 543 | if (select < 10) 544 | menuBand(btnState); 545 | else if (select < 20) 546 | menuRitToggle(btnState); 547 | else if (select < 30) 548 | menuVfoToggle(btnState); 549 | else if (select < 40) 550 | menuSidebandToggle(btnState); 551 | else if (select < 50) 552 | menuCWSpeed(btnState); 553 | else if (select < 60) 554 | menuSetup(btnState); 555 | else if (select < 70 && !modeCalibrate) 556 | menuExit(btnState); 557 | else if (select < 80 && modeCalibrate) 558 | menuSetupCalibration(btnState); //crystal 559 | else if (select < 90 && modeCalibrate) 560 | menuSetupCarrier(btnState); //lsb 561 | else if (select < 100 && modeCalibrate) 562 | menuSetupCwTone(btnState); 563 | else if (select < 110 && modeCalibrate) 564 | menuExit(btnState); 565 | } 566 | 567 | //debounce the button 568 | while(btnDown()) 569 | delay(50); 570 | delay(50); 571 | } 572 | 573 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_si5351.ino: -------------------------------------------------------------------------------- 1 | // ************* SI5315 routines - tks Jerry Gaffke, KE7ER *********************** 2 | 3 | // An minimalist standalone set of Si5351 routines. 4 | // VCOA is fixed at 875mhz, VCOB not used. 5 | // The output msynth dividers are used to generate 3 independent clocks 6 | // with 1hz resolution to any frequency between 4khz and 109mhz. 7 | 8 | // Usage: 9 | // Call si5351bx_init() once at startup with no args; 10 | // Call si5351bx_setfreq(clknum, freq) each time one of the 11 | // three output CLK pins is to be updated to a new frequency. 12 | // A freq of 0 serves to shut down that output clock. 13 | 14 | // The global variable si5351bx_vcoa starts out equal to the nominal VCOA 15 | // frequency of 25mhz*35 = 875000000 Hz. To correct for 25mhz crystal errors, 16 | // the user can adjust this value. The vco frequency will not change but 17 | // the number used for the (a+b/c) output msynth calculations is affected. 18 | // Example: We call for a 5mhz signal, but it measures to be 5.001mhz. 19 | // So the actual vcoa frequency is 875mhz*5.001/5.000 = 875175000 Hz, 20 | // To correct for this error: si5351bx_vcoa=875175000; 21 | 22 | // Most users will never need to generate clocks below 500khz. 23 | // But it is possible to do so by loading a value between 0 and 7 into 24 | // the global variable si5351bx_rdiv, be sure to return it to a value of 0 25 | // before setting some other CLK output pin. The affected clock will be 26 | // divided down by a power of two defined by 2**si5351_rdiv 27 | // A value of zero gives a divide factor of 1, a value of 7 divides by 128. 28 | // This lightweight method is a reasonable compromise for a seldom used feature. 29 | 30 | 31 | #define BB0(x) ((uint8_t)x) // Bust int32 into Bytes 32 | #define BB1(x) ((uint8_t)(x>>8)) 33 | #define BB2(x) ((uint8_t)(x>>16)) 34 | 35 | #define SI5351BX_ADDR 0x60 // I2C address of Si5351 (typical) 36 | #define SI5351BX_XTALPF 2 // 1:6pf 2:8pf 3:10pf 37 | 38 | // If using 27mhz crystal, set XTAL=27000000, MSA=33. Then vco=891mhz 39 | #define SI5351BX_XTAL 25000000 // Crystal freq in Hz 40 | #define SI5351BX_MSA 35 // VCOA is at 25mhz*35 = 875mhz 41 | 42 | // User program may have reason to poke new values into these 3 RAM variables 43 | uint32_t si5351bx_vcoa = (SI5351BX_XTAL*SI5351BX_MSA); // 25mhzXtal calibrate 44 | uint8_t si5351bx_rdiv = 0; // 0-7, CLK pin sees fout/(2**rdiv) 45 | uint8_t si5351bx_drive[3] = {1, 1, 1}; // 0=2ma 1=4ma 2=6ma 3=8ma for CLK 0,1,2 46 | uint8_t si5351bx_clken = 0xFF; // Private, all CLK output drivers off 47 | int32_t calibration = 0; 48 | 49 | void i2cWrite(uint8_t reg, uint8_t val) { // write reg via i2c 50 | Wire.beginTransmission(SI5351BX_ADDR); 51 | Wire.write(reg); 52 | Wire.write(val); 53 | Wire.endTransmission(); 54 | } 55 | 56 | void i2cWriten(uint8_t reg, uint8_t *vals, uint8_t vcnt) { // write array 57 | Wire.beginTransmission(SI5351BX_ADDR); 58 | Wire.write(reg); 59 | while (vcnt--) Wire.write(*vals++); 60 | Wire.endTransmission(); 61 | } 62 | 63 | 64 | void si5351bx_init() { // Call once at power-up, start PLLA 65 | uint8_t reg; uint32_t msxp1; 66 | Wire.begin(); 67 | i2cWrite(149, 0); // SpreadSpectrum off 68 | i2cWrite(3, si5351bx_clken); // Disable all CLK output drivers 69 | i2cWrite(183, SI5351BX_XTALPF << 6); // Set 25mhz crystal load capacitance 70 | msxp1 = 128 * SI5351BX_MSA - 512; // and msxp2=0, msxp3=1, not fractional 71 | uint8_t vals[8] = {0, 1, BB2(msxp1), BB1(msxp1), BB0(msxp1), 0, 0, 0}; 72 | i2cWriten(26, vals, 8); // Write to 8 PLLA msynth regs 73 | i2cWrite(177, 0x20); // Reset PLLA (0x80 resets PLLB) 74 | // for (reg=16; reg<=23; reg++) i2cWrite(reg, 0x80); // Powerdown CLK's 75 | // i2cWrite(187, 0); // No fannout of clkin, xtal, ms0, ms4 76 | } 77 | 78 | void si5351bx_setfreq(uint8_t clknum, uint32_t fout) { // Set a CLK to fout Hz 79 | uint32_t msa, msb, msc, msxp1, msxp2, msxp3p2top; 80 | if ((fout < 500000) || (fout > 109000000)) // If clock freq out of range 81 | si5351bx_clken |= 1 << clknum; // shut down the clock 82 | else { 83 | msa = si5351bx_vcoa / fout; // Integer part of vco/fout 84 | msb = si5351bx_vcoa % fout; // Fractional part of vco/fout 85 | msc = fout; // Divide by 2 till fits in reg 86 | while (msc & 0xfff00000) { 87 | msb = msb >> 1; 88 | msc = msc >> 1; 89 | } 90 | msxp1 = (128 * msa + 128 * msb / msc - 512) | (((uint32_t)si5351bx_rdiv) << 20); 91 | msxp2 = 128 * msb - 128 * msb / msc * msc; // msxp3 == msc; 92 | msxp3p2top = (((msc & 0x0F0000) << 4) | msxp2); // 2 top nibbles 93 | uint8_t vals[8] = { BB1(msc), BB0(msc), BB2(msxp1), BB1(msxp1), 94 | BB0(msxp1), BB2(msxp3p2top), BB1(msxp2), BB0(msxp2) 95 | }; 96 | i2cWriten(42 + (clknum * 8), vals, 8); // Write to 8 msynth regs 97 | i2cWrite(16 + clknum, 0x0C | si5351bx_drive[clknum]); // use local msynth 98 | si5351bx_clken &= ~(1 << clknum); // Clear bit to enable clock 99 | } 100 | i2cWrite(3, si5351bx_clken); // Enable/disable clock 101 | } 102 | 103 | void si5351_set_calibration(int32_t cal){ 104 | si5351bx_vcoa = (SI5351BX_XTAL * SI5351BX_MSA) + cal; // apply the calibration correction factor 105 | si5351bx_setfreq(0, usbCarrier); 106 | } 107 | 108 | void initOscillators(){ 109 | //initialize the SI5351 110 | si5351bx_init(); 111 | si5351bx_vcoa = (SI5351BX_XTAL * SI5351BX_MSA) + calibration; // apply the calibration correction factor 112 | si5351bx_setfreq(0, usbCarrier); 113 | } 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /ubitx_20/ubitx_ui.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * The user interface of the ubitx consists of the encoder, the push-button on top of it 3 | * and the 16x2 LCD display. 4 | * The upper line of the display is constantly used to display frequency and status 5 | * of the radio. Occasionally, it is used to provide a two-line information that is 6 | * quickly cleared up. 7 | */ 8 | 9 | //returns true if the button is pressed 10 | int btnDown(){ 11 | if (digitalRead(FBUTTON) == HIGH) 12 | return 0; 13 | else 14 | return 1; 15 | } 16 | 17 | /** 18 | * Meter (not used in this build for anything) 19 | * the meter is drawn using special characters. Each character is composed of 5 x 8 matrix. 20 | * The s_meter array holds the definition of the these characters. 21 | * each line of the array is is one character such that 5 bits of every byte 22 | * makes up one line of pixels of the that character (only 5 bits are used) 23 | * The current reading of the meter is assembled in the string called meter 24 | */ 25 | 26 | char meter[17]; 27 | 28 | byte s_meter_bitmap[] = { 29 | B00000,B00000,B00000,B00000,B00000,B00100,B00100,B11011, 30 | B10000,B10000,B10000,B10000,B10100,B10100,B10100,B11011, 31 | B01000,B01000,B01000,B01000,B01100,B01100,B01100,B11011, 32 | B00100,B00100,B00100,B00100,B00100,B00100,B00100,B11011, 33 | B00010,B00010,B00010,B00010,B00110,B00110,B00110,B11011, 34 | B00001,B00001,B00001,B00001,B00101,B00101,B00101,B11011 35 | }; 36 | 37 | 38 | 39 | // initializes the custom characters 40 | // we start from char 1 as char 0 terminates the string! 41 | void initMeter(){ 42 | lcd.createChar(1, s_meter_bitmap); 43 | lcd.createChar(2, s_meter_bitmap + 8); 44 | lcd.createChar(3, s_meter_bitmap + 16); 45 | lcd.createChar(4, s_meter_bitmap + 24); 46 | lcd.createChar(5, s_meter_bitmap + 32); 47 | lcd.createChar(6, s_meter_bitmap + 40); 48 | } 49 | 50 | /** 51 | * The meter is drawn with special characters. 52 | * character 1 is used to simple draw the blocks of the scale of the meter 53 | * characters 2 to 6 are used to draw the needle in positions 1 to within the block 54 | * This displays a meter from 0 to 100, -1 displays nothing 55 | */ 56 | void drawMeter(int8_t needle){ 57 | int16_t best, i, s; 58 | 59 | if (needle < 0) 60 | return; 61 | 62 | s = (needle * 4)/10; 63 | for (i = 0; i < 8; i++){ 64 | if (s >= 5) 65 | meter[i] = 1; 66 | else if (s >= 0) 67 | meter[i] = 2 + s; 68 | else 69 | meter[i] = 1; 70 | s = s - 5; 71 | } 72 | if (needle >= 40) 73 | meter[i-1] = 6; 74 | meter[i] = 0; 75 | } 76 | 77 | // The generic routine to display one line on the LCD 78 | void printLine(char linenmbr, char *c) { 79 | if (strcmp(c, printBuff[linenmbr])) { // only refresh the display when there was a change 80 | lcd.setCursor(0, linenmbr); // place the cursor at the beginning of the selected line 81 | lcd.print(c); 82 | strcpy(printBuff[linenmbr], c); 83 | 84 | for (byte i = strlen(c); i < 16; i++) { // add white spaces until the end of the 16 characters line is reached 85 | lcd.print(' '); 86 | } 87 | } 88 | } 89 | 90 | // short cut to print to the first line 91 | void printLine1(char *c){ 92 | printLine(1,c); 93 | } 94 | // short cut to print to the first line 95 | void printLine2(char *c){ 96 | printLine(0,c); 97 | } 98 | 99 | // this builds up the top line of the display with frequency and mode 100 | void updateDisplay() { 101 | // tks Jack Purdum W8TEE 102 | // replaced fsprint commmands by str commands for code size reduction 103 | 104 | memset(c, 0, sizeof(c)); 105 | memset(b, 0, sizeof(b)); 106 | 107 | ultoa(frequency, b, DEC); 108 | 109 | if (inTx){ 110 | if (cwTimeout > 0) 111 | strcpy(c, " CW:"); 112 | else 113 | strcpy(c, " TX:"); 114 | } 115 | else { 116 | if (ritOn) 117 | strcpy(c, "RIT "); 118 | else { 119 | if (isUSB) 120 | strcpy(c, "USB "); 121 | else 122 | strcpy(c, "LSB "); 123 | } 124 | if (vfoActive == VFO_A) // VFO A is active 125 | strcat(c, "A:"); 126 | else 127 | strcat(c, "B:"); 128 | } 129 | 130 | 131 | 132 | //one mhz digit if less than 10 M, two digits if more 133 | if (frequency < 10000000l){ 134 | c[6] = ' '; 135 | c[7] = b[0]; 136 | strcat(c, "."); 137 | strncat(c, &b[1], 3); 138 | strcat(c, "."); 139 | strncat(c, &b[4], 3); 140 | } 141 | else { 142 | strncat(c, b, 2); 143 | strcat(c, "."); 144 | strncat(c, &b[2], 3); 145 | strcat(c, "."); 146 | strncat(c, &b[5], 3); 147 | } 148 | 149 | if (inTx) 150 | strcat(c, " TX"); 151 | printLine(1, c); 152 | 153 | /* 154 | //now, the second line 155 | memset(c, 0, sizeof(c)); 156 | memset(b, 0, sizeof(b)); 157 | 158 | if (inTx) 159 | strcat(c, "TX "); 160 | else if (ritOn) 161 | strcpy(c, "RIT"); 162 | 163 | strcpy(c, " \xff"); 164 | drawMeter(meter_reading); 165 | strcat(c, meter); 166 | strcat(c, "\xff"); 167 | printLine2(c);*/ 168 | } 169 | 170 | int enc_prev_state = 3; 171 | 172 | /** 173 | * The A7 And A6 are purely analog lines on the Arduino Nano 174 | * These need to be pulled up externally using two 10 K resistors 175 | * 176 | * There are excellent pages on the Internet about how these encoders work 177 | * and how they should be used. We have elected to use the simplest way 178 | * to use these encoders without the complexity of interrupts etc to 179 | * keep it understandable. 180 | * 181 | * The enc_state returns a two-bit number such that each bit reflects the current 182 | * value of each of the two phases of the encoder 183 | * 184 | * The enc_read returns the number of net pulses counted over 50 msecs. 185 | * If the puluses are -ve, they were anti-clockwise, if they are +ve, the 186 | * were in the clockwise directions. Higher the pulses, greater the speed 187 | * at which the enccoder was spun 188 | */ 189 | 190 | byte enc_state (void) { 191 | return (analogRead(ENC_A) > 500 ? 1 : 0) + (analogRead(ENC_B) > 500 ? 2: 0); 192 | } 193 | 194 | int enc_read(void) { 195 | int result = 0; 196 | byte newState; 197 | int enc_speed = 0; 198 | 199 | long stop_by = millis() + 50; 200 | 201 | while (millis() < stop_by) { // check if the previous state was stable 202 | newState = enc_state(); // Get current state 203 | 204 | if (newState != enc_prev_state) 205 | delay (1); 206 | 207 | if (enc_state() != newState || newState == enc_prev_state) 208 | continue; 209 | //these transitions point to the encoder being rotated anti-clockwise 210 | if ((enc_prev_state == 0 && newState == 2) || 211 | (enc_prev_state == 2 && newState == 3) || 212 | (enc_prev_state == 3 && newState == 1) || 213 | (enc_prev_state == 1 && newState == 0)){ 214 | result--; 215 | } 216 | //these transitions point o the enccoder being rotated clockwise 217 | if ((enc_prev_state == 0 && newState == 1) || 218 | (enc_prev_state == 1 && newState == 3) || 219 | (enc_prev_state == 3 && newState == 2) || 220 | (enc_prev_state == 2 && newState == 0)){ 221 | result++; 222 | } 223 | enc_prev_state = newState; // Record state for next pulse interpretation 224 | enc_speed++; 225 | delay(1); 226 | } 227 | return(result); 228 | } 229 | 230 | 231 | -------------------------------------------------------------------------------- /ubitx_wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afarhan/ubitx/ae8d03601d652f9004ed662016bd717158508a57/ubitx_wiring.png -------------------------------------------------------------------------------- /ubitxv3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afarhan/ubitx/ae8d03601d652f9004ed662016bd717158508a57/ubitxv3.pdf --------------------------------------------------------------------------------