element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum Progress report on "Microcontrollers for Dummies"
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 3 replies
  • Subscribers 488 subscribers
  • Views 384 views
  • Users 0 members are here
Related

Progress report on "Microcontrollers for Dummies"

cityswift
cityswift over 14 years ago

I have now finished the project I started a year ago, after having the summer off, and thought it would be worth sharing my findings with the element14 community who were so helpful at the start.

There are seven main Headings that I want to use in this progress report on "Microcontrollers for dummies" and they are as follows: -

 

1.The Project

 

2.Choice of microcontroller

 

3.Choice of programming language.

 

4.Dealing with switch bounce

 

5.Use of interrupts.

 

6.Pin behaviour at power up

 

7.The precision clock and the hooter timers

 

8.What is the yardstick for efficiency of code?

 

1.The Project - A Portable controller for starting and finishing yacht races and recording individual times.

 

1.1 The race is started by pressing the control button which starts a 5 minute sequence in which five lights are initially turned on and one light goes out every minute.  At minute five and minute four a hooter is sounded for 1 second, but at the three and two there is no sound.  At the 1 minute signal a 2 second hooter sound is given, and at the start a 1 second signal is given and the last light will go out.

 

1.2 As the finishing boats cross the line the control button is pressed which gives a 1 second hooter signal and records the time in seconds from the start of the race for each finisher.

 

1.3 If an individual recall is needed then a switch is operated after the start and a 1 second hooter signal is given and lights 1 and 2 are flashed simultaneously at 1 second intervals.

 

1.4 If a general recall is required then one switch is operated and the hooter sounds and then a second switch is operated and the hooter sounds again and the lights 1 2 3 and 4 flash simultaneously at one second intervals.

 

1.5 If the race officer wishes to impose penalties on to the fleet during the starting sequence, then he has the option of flashing light 1 during the starting sequence to implement the "round the ends" rule.   If he wishes to further penalise the fleet then he can implement the "black flag" rule, by flashing lights 1 2 and 3 during the starting sequence.

 

2.Choice of microcontroller

 

This comes down to basically deciding how many input and outputs you're likely to need for the project. In this case we have five lights and a hooter and a start/ finish switch and 2 indicator status lights, so it was pretty obvious so we would need in the region of 10 input /outputs on the microcontroller.  Also a precision timer facility would be needed, and an EEPROM memory for the storage of the finish times in seconds up to 3 hours. After a couple of false starts I settled for the Microchip 16F630, and all pins are used apart from RA3.

 

 

3.Choice of programming language.

 

As this was my first microcontroller project I decided to have a look at the use of the language C.  This appears to be quite a powerful language, but what concerned me was that if I didn't understand what every line of the code did then how would I be able to debug it if there were problems.  After looking at the instruction set for the 16F630 then I decided that, by using the various functions such as the "bit tests and skip” commands, then I could quite easily simulate the "if then” programming function used in C. Also the rotate left and right commands gave the means to alter a register progressively in an interrupt sequence, so that one could step through the 5 minute sequence using one piece of interrupt code. It was slow writing in assembly, but I knew exactly what every line was for, and was able to debug confidently.

 

4.Dealing with switch bounce

 

There were quite a few clever bits of programming given in the various tutorials which were designed to eliminate problems caused by switch bounce.  I found these a bit convoluted and difficult to understand.  What I found to be more effective was to use the switch to start the interrupt, and then not to reset the flag.  If it was necessary to have the interrupt functioning again, then it was easy to put in a time delay after the interrupt which covered the time of the switch bounce.  I was using a micro switch and am I had a look on the oscilloscope at the bounce, and this was never a longer than 5 milliseconds. So what I did was to put in a 20 ms delay loop immediately after interrupt before resetting the interrupt. This worked reliably and consistently.

 

5.Use of interrupts.

 

I tried to use the interrupt on change facility which is available on some of the ports but found that this was quite difficult to use consistently.  So much depended on what the ports had been used for prior to the interrupt and in the end I gave this up and settled for the RA2 port which has a special interrupt facility. The Timer 1 interrupt was used to set the 1 minute intervals by preloading the timer registers and this worked reliably.

 

6.Pin behaviour at power up

 

I found that the behaviour of the RA pins on this microcontroller was quite erratic on start up.  For example, before these ports settled at their proper programmed values, then they could give outputs lasting several milliseconds. This meant that any device connected to them could be triggered on switch on. This was not the case at with the RC pins, however. I guess it is something to do with the multiple functions of the RA pins.

 

7.The precision clock and the hooter timers

 

I was advised at first to use a discrete crystal to build a precision timer but I found that the stray capacitance affected the operation so much that it was not possible to build a reliable circuit.  What I did find was an integrated circuit was available which contained a precision oscillator and I used that in the end and have achieved good reliable results. The oscillator is used to feed 2 counters in tandem and this gives me the required precision.   The system has a resolution of one second and is very accurate.  The hooter timers were developed using simple stand alone 555 circuits as it was not possible to use the microcontroller without affecting the timing accuracy of the system.

 

8.What is the yardstick for efficiency of code?

 

I would be interested to hear from any readers of what they think is efficient code.  In this case I have achieved the above using 188 lines of code but am at a loss as to know whether this is efficient or not. Does anyone have any comments on that?

  • Sign in to reply
  • Cancel
Parents
  • DAB
    0 DAB over 14 years ago

    Hi Cityswift,

     

    I really like what you are trying to do.  If you need someone to proof read your material and provide comments, I would be more than glad to collaborate.  I wrote an entire Systems and Software Engineering Training course before I was forced to retire.

     

    There are several aspects to "efficient" code.

    To me, the first efficiency needs to be executing each thread within its time domain.  If it does not work, what good is tight code?

    Next comes the use of memory.  The code needs to fit within the memory available.

    Reliability comes next.  The system needs to work first time everytime the same way.

     

    Selecting the right MCU helps you accomplish all of these, which is why you need to carefully elaborate your System and Software requirements before you lock yourself into an architecture that will not support your needs.

    If you select the right MCU, the language you use is incidental.  In my 30+ years of experience, almost any language will do the job.  The question about the nuances between the languages is mostly semantic and more based on which language you learn first.  As long as you understand the language and have the support tools to properly debug the software, the issue is really moot.

     

    I would recommend that you add another section on Test Planning.  Most people ignore the issue that you need to spend almost as much time preparing to test your system and software as you do building the device.  Proper test planning helps you better understand what you are building and how it needs to work once it is done.

     

    Lastly, you need to emphasize documenting your work, from requirements analysis to completing testing.  Most systems built always gets modified to do something else later.  If you do not capture the build by documenting, then you have to rely on your memory.  Not a good idea.

     

    So I encourage you to continue you work and as I stated earlier, I would be more than happy to help.

     

    Good start,

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • cityswift
    0 cityswift over 14 years ago in reply to DAB

    Hi Don

    Many thanks for your reply which answered my questions. As yours has been the only comment, I guess that most people did not realise what I was getting at. Also thanks for your offer of help. I have been in electronics design for 50 years, but only since I semi-retired from management and business consultancy have I had the time to get into microcontrollers and programming. What powerful devices they are  - and a £1 each!

     

    I would be interested to hear if you have used the Micochip development tools, such as the MPLAB IDE and the Simulator debugging tool, and if so ,what you thought of them.

    I am a member of the local Yacht club, and we plan to test out the racecontroller in actual operation when the racing season starts in April next year. Meanwhile I plan to approach a company here which sells a device for just sounding the horn at 1 minute intervals to see if they are interested.

     

    Thanks again for your interest, Dave Tedd, Cityswift Ltd

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • DAB
    0 DAB over 14 years ago in reply to cityswift

    Hi Dave,

     

    My only Microchip experience has been with the basic Stamp and the UNO-32.  I have only used the Stamp software using basic to learn the hardware.  I almost purchased the MPLAB, but decided against it.

    The UNO-32 used the Arduino interface and I found it reasonably intuitive to program.  Their simple C implementation was easy to learn and use.

     

    I am currently learning to program the TI MSP430 line.  TI provides a wealth of free software tools and lots of online support.

     

    I am writing a book with Gordon Smith of NavalHistory.net and I thought that since he also likes sailing I was wondering if you knew him?  My knowledge of British geography is limited except for the major ports and inland cities, so I do not know if you are anywhere near him, but I figure if you enjoy sailing, maybe you are also interested in Naval History.  If not, no matter.

     

    Yes I would be happy to help you flesh out  your paper.  I have 30+ years of Systems and Software experience.  I was also in on the very early microprocessor surge, writting code for the TI9900 back in the late 1970's and early 1980's.  I learned my electronics on vacuum tubes and have the solder burns to qualify as a hands on engineer.  So if you have questions, ask.  If I don't know the answer, I will tell you.  I will never tell you anything that I do not believe to be true.

     

    Good luck on your project and my you enjoy many more days on the water sailing.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • DAB
    0 DAB over 14 years ago in reply to cityswift

    Hi Dave,

     

    My only Microchip experience has been with the basic Stamp and the UNO-32.  I have only used the Stamp software using basic to learn the hardware.  I almost purchased the MPLAB, but decided against it.

    The UNO-32 used the Arduino interface and I found it reasonably intuitive to program.  Their simple C implementation was easy to learn and use.

     

    I am currently learning to program the TI MSP430 line.  TI provides a wealth of free software tools and lots of online support.

     

    I am writing a book with Gordon Smith of NavalHistory.net and I thought that since he also likes sailing I was wondering if you knew him?  My knowledge of British geography is limited except for the major ports and inland cities, so I do not know if you are anywhere near him, but I figure if you enjoy sailing, maybe you are also interested in Naval History.  If not, no matter.

     

    Yes I would be happy to help you flesh out  your paper.  I have 30+ years of Systems and Software experience.  I was also in on the very early microprocessor surge, writting code for the TI9900 back in the late 1970's and early 1980's.  I learned my electronics on vacuum tubes and have the solder burns to qualify as a hands on engineer.  So if you have questions, ask.  If I don't know the answer, I will tell you.  I will never tell you anything that I do not believe to be true.

     

    Good luck on your project and my you enjoy many more days on the water sailing.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube