\главная\р.л. конструкции\...

Marker generator with PIC 12C509

   This program uses a PIC 12C509 microcontroller to generate accurate square waves at frequencies of 100, 50, 25, 10 and 5 KHz. When the output is coupled via a very small value cap to a receiver, the odd and even  harmonics of these markers can be heard all the way through to 30 MHz.  The markers are selected via a momentary push button switch closure to  ground on pin 7. At powerup, the PIC will output a 100 KHz signal to pin 5. If the momentary switch is pressed and released (PAR), the the output will change to 50 KHz - subsequent PARs will advance down to the 5 KHz marker and then wraparound back to the 100 KHz marker.
 
 If pin 6 is grounded, the marker will be gated (turned on and off at a regular interval). The frequency of the gating will increase as  the user changes the markers to allow easy identification of the marker. The 100 KHz marker has a slow on/off tone while the 5 KHz marker will have a very rapid buzz.
 
 If pin 4 is grounded, the duty cycle will change from the normal 50% square wave to a 10% square wave. The idea was to even out the even and odd harmonic amplitudes, however, this isn't really accomplished but decided to leave it in anyway. It may (depending on the frequency) increase the amplitude of the even harmonics slightly. Note that the pin should be connected either to ground or +5V directly - using the internal pullup or even an external 10K pullup resulted in a frequency shift of the marker.

 Programming notes:
 
 The program is basically a timed loop. The 100 KHz loop is the tightest, executing in 10 microseconds (us). With a 4 MHz clock the PIC executes all instructions in either 1 or 2 us. This makes it quite easy to simply count the cycles of the loop to allow for exactly the correct time delay - the PIC output is then set to a 1 or 0 as needed. Seperate loops are used for all 5 markers and duty cycles - there are undoubtedly more efficient ways to do this, but this method does work.

 The gating of the markers is accomplished with the use of the watch dog timer (WDT) feature of the PIC. The WDT is a seperate RC on-chip oscillator with a period of about 18 ms. The prescaler is used to count an integer number of WDT periods - after the prescaler overflows, the chip is reset, then a matching period of silence is generated using a timed loop. The loop to be executed is determined from the bits of the FSR register - the FSR register was used because it is left alone during a reset of the chip.

 Hardware notes:
 (Click here for the circuit)


 I built a prototype on perf board - I had a little trouble with  adjusting the 4 MHz oscillator to be right on frequency - the value of  the caps or something else may need to be changed - one of the two 33 pf caps connected to the crystal should be variable trimmer cap to allow this adjustment. It should be possible to use an external 4 MHz oscillator to drive pin 2 instead of using a crystal although I haven't actually tried this.
 This code should work in the 12C509a and also in the 12C508 and 12C508a devices (with changes) - HOWEVER, I havne't tried them, so you will need  to make the appropriate changes and tests to insure success with these  other devices.


 PIC pinout:

Pin Name Function / Connection
1 Vdd +5V
2 osc1 connected to the other side of 4 MHz xtal, also 33 pf to gnd
3 osc2 connected to one side of 4 MHz xtal, also 33 pf to gnd
4 GP3 duty cycle select - +5V = 50%, ground = 10%
5 GP2 marker output
6 GP1 marker select switch - normally open, internal pullup
7 GP0 gate select switch - gnd = constant, open = gated, int pullup
8 GND Ground

 


© 2001 - YO5OFH, Csaba Gajdos

Возврат