JDW_
Junior Member level 2
- Joined
- Jul 12, 2016
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 2
- Trophy points
- 1,283
- Activity points
- 1,672
First some background. I began learning PIC assembly programming in the 1990s, self-taught from Microchips documents. I have various PICs, a PM3 programmer, and still use MPLAB 8.x. I do not know C. I understand the merits of a debugger but do not have one, nor have I needed one to date. So I would like to proceed with the understanding that I have no debugger. I've only written rather simplistic programs on PICs, so while I am not a novice I would be hesitant to call myself a pro.
I am trying to design a controller for a 12V siren (for an alarm system). The controller will output square waves from the PIC using 2 outputs that are 180-deg out of phase with each other (inverted), both outputs fed through an H-BRIDGE amp to an 8-ohm speaker (to get maximum volume). I do NOT need Sine waves, Sawtooth, etc. I only need to output Square waves. Frequency range will be as low as 300Hz to as high as 2650Hz. I intend to use a DIP switch with the PIC to allow selection of various tones such as these (all 50% duty):
If memory allows, I will ultimately create 16 different selectable tones (fixed frequency and sweeps).
I create my sweep tones in Audacity using its Generate > Chirp… feature. But I want to know how I can recreate these sweep tones on a PIC.
I first started toying with an old 16F84 but couldn't figure out how to implement sweeps, so I posted in another forum about this. It was recommended that I consider using the NCO in the PIC16F150x series, which also has CWG to generate an inverse waveform (180 degrees out of phase) of my primary NCO output, which is needed for use with my H-BRIDGE amplifier. I ordered samples of the 16F1503 and 16F1508, and right now I am trying to figure out the assembly code required.
I have been told that interrupts would likely be needed in this application, even on the 16F150x-series PICs with NCO. In fixed Duty Cycle mode, the NCO Accumulator overflow occurs every 1/2 cycle, at which time the half-cycle output will change. Accumulator overflows appear in NCO1CON-bit5 (NxOUT), which can be polled. Furthermore, PIR2-bit2 is set to HI on an overflow, even when interrupts are disabled, and this bit too could be polled.
I have also been told that a look-up table could be used. But those who mentioned "interrupts and tables" to me are versed in C-code, not assembly, and no one offered me any example assembly code to study, hence my post here.
I don't understand precisely how a look-up table, if truly required, would be used to determine NCO adjustments required to generate sweep tones. I created my sweep tones in Audacity (quite easily via its Generate > Chirp… feature), but must I use Audacity to manually measure each pulse width, from start to finish in my sweep, to know how many pulses and at what width would fit in a given sweep time window on my PIC? Surely there must be a faster and easier way, which is no doubt why I was advised to use an NCO-capable PIC to me in the first place. Perhaps if I knew the algorithm that Audacity uses to create its tonal sweeps, I could then implement the PIC version of that. For truly, my aim is simply to use a PIC to reproduce sweep tones that I have created I Audacity.
All said, if someone versed in PIC Assembly could show me some example code for the 16F150x and the NCO, that's likely all the study I would need to up and running. For example, on the PIC16F150x, when running the HFINTOSC at 16MHz, could anyone offer me example Assembly code that would use the NCO to smoothly sweep from 500Hz to 1200Hz in approximately 400msec, with the NCO output ending in a LO? To see an example of how that is accomplished in Assembly on a PIC16F150x would be very helpful and a good learning experience for me.
Thank you.
I am trying to design a controller for a 12V siren (for an alarm system). The controller will output square waves from the PIC using 2 outputs that are 180-deg out of phase with each other (inverted), both outputs fed through an H-BRIDGE amp to an 8-ohm speaker (to get maximum volume). I do NOT need Sine waves, Sawtooth, etc. I only need to output Square waves. Frequency range will be as low as 300Hz to as high as 2650Hz. I intend to use a DIP switch with the PIC to allow selection of various tones such as these (all 50% duty):
- 500Hz to 1200Hz sweep over 400msec. (repeating)
- 1000Hz & 800Hz alternating, each 250msec. (repeating)
- 500Hz to 2650Hz sweep over 150msec., then 2650Hz to 900Hz sweep over 100msec. (repeating)
- 1050Hz to 2650Hz sweep over 150msec., then 2650Hz to 1050Hz over 150msec. (repeating)
- 280us(HI),280us(LO) (1786Hz) for 4 cycles then 225us(HI),225us(LO) (2222Hz) for 14 cycles repeating for 280ms, then 280ms off (repeating)
If memory allows, I will ultimately create 16 different selectable tones (fixed frequency and sweeps).
I create my sweep tones in Audacity using its Generate > Chirp… feature. But I want to know how I can recreate these sweep tones on a PIC.
I first started toying with an old 16F84 but couldn't figure out how to implement sweeps, so I posted in another forum about this. It was recommended that I consider using the NCO in the PIC16F150x series, which also has CWG to generate an inverse waveform (180 degrees out of phase) of my primary NCO output, which is needed for use with my H-BRIDGE amplifier. I ordered samples of the 16F1503 and 16F1508, and right now I am trying to figure out the assembly code required.
I have been told that interrupts would likely be needed in this application, even on the 16F150x-series PICs with NCO. In fixed Duty Cycle mode, the NCO Accumulator overflow occurs every 1/2 cycle, at which time the half-cycle output will change. Accumulator overflows appear in NCO1CON-bit5 (NxOUT), which can be polled. Furthermore, PIR2-bit2 is set to HI on an overflow, even when interrupts are disabled, and this bit too could be polled.
I have also been told that a look-up table could be used. But those who mentioned "interrupts and tables" to me are versed in C-code, not assembly, and no one offered me any example assembly code to study, hence my post here.
I don't understand precisely how a look-up table, if truly required, would be used to determine NCO adjustments required to generate sweep tones. I created my sweep tones in Audacity (quite easily via its Generate > Chirp… feature), but must I use Audacity to manually measure each pulse width, from start to finish in my sweep, to know how many pulses and at what width would fit in a given sweep time window on my PIC? Surely there must be a faster and easier way, which is no doubt why I was advised to use an NCO-capable PIC to me in the first place. Perhaps if I knew the algorithm that Audacity uses to create its tonal sweeps, I could then implement the PIC version of that. For truly, my aim is simply to use a PIC to reproduce sweep tones that I have created I Audacity.
All said, if someone versed in PIC Assembly could show me some example code for the 16F150x and the NCO, that's likely all the study I would need to up and running. For example, on the PIC16F150x, when running the HFINTOSC at 16MHz, could anyone offer me example Assembly code that would use the NCO to smoothly sweep from 500Hz to 1200Hz in approximately 400msec, with the NCO output ending in a LO? To see an example of how that is accomplished in Assembly on a PIC16F150x would be very helpful and a good learning experience for me.
Thank you.