Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help wth motorola hc912b programming.

Status
Not open for further replies.

m00nd0g

New Member
I am in need of some help with some code that i have to write to turn the hc12 into a frequency counter. I have the basic idea of what i am going to do. but first let me give you a few of the specs that i have to be able to meet.

1) It must count frequencies up to 1Mhz
2) It must display only the two mose significan digits and iunclude a scale factor
3) It must have a push button to perform the measurement.
4) the reference period must be one second.

So far i have decided what i am going to do. I am planning on using the pulse accumulator as well as the RTI system to generate a interupt at a at a second time period and thorw the interupt on the pulse accumulator, as well as on the rti system. After the interupt has been triggered i want to go into a subroutine that will calculate the frequency and display it and wait for the external irq button to be pushed to return from the interupt and star the program over. Now a few questions. I have a few problems however, i am going to have to count overflows on the 16-bit pulse accumulator register since it can not hold the data for a 1MHz frequency, and i think i am going to have to poll to see when the overflow bit gets set. Here is where i have the questions at.

1) Will i be able to run the rti system in the background to generate a one second interupt and poll the Pulse accumulater overflow flag at the same time? If so, how do you set something like that up.

2) Is it possible to set one of the external pins or interupt switches to return from the RTI interupt and start the program over?

any help would be greats. Thanks. :)
 
Interrupts are generated by the hardware without any CPU oversight. When an interrupt is generated the CPU stops executing the code it was running and immediatly jumps to another section of code called an "Interrupt Service Routine" (which you also write). At the end of this code the processor jumps back to where it was running before the interrupt.

To answer you specific questions:

1) The interrupt system will run at the same time the processor is executing other code. To set this up you need to look at the datasheet for your microcontroller and read about setting up interrupts.

You can probably set up the pulse accumulator to generate an interrupt when it overflows. So you won't have to poll it.

2) Theres an assembly command that jumps back from the Interrupt code to the place it was executing. Completely restarting the program is bad programming. Instead you should have a loop that executes forever containing the code you want to repeat.

Brent
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top