Generating Sine Wave

OBW0549

Joined Mar 2, 2015
3,566
:: Features ::
  • Sine, Square and Triangle waves
  • Variable Frequency (0.1Hz to 100KHz)
  • Variable Duty Cycle (1 - 99%)
  • Variable Amplitude (0 - 12 volt)
  • Adjustable DC Offset
  • Mains Powered
  • Metal Project Enclosure

:: User Interface ::
  • LCD HD44780 to Display Information
  • 4 Push Buttons for Menu Navigation
  • Rotary Encoder to Set Frequency and Duty Cycle
  • Pot for Amplitude
  • Pot for DC Offset
Those are some mighty ambitious specs; indeed, they're EXTREMELY ambitious, especially if you're planning on using a PIC16F877A.

Keep us posted as you progress with this thing; it will be interesting to see what you end up with.
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
Those are some mighty ambitious specs; indeed, they're EXTREMELY ambitious, especially if you're planning on using a PIC16F877A.
Awwww come now the 16F877a is an beautiful MCU. Nice and cheap at $2 ea in low quantity on eBay too.

Can you recommend and parallel interface DAC IC as opposed to using an R2R ladder?
 

OBW0549

Joined Mar 2, 2015
3,566
Awwww come now the 16F877a is an beautiful MCU.
Yes. And the Ford Model T is a beautiful automobile, too.

My collection of 16F877's went into the trash years ago, when Microchip introduced the dsPIC series. The dsPICs are much more powerful, WAYYYY easier to program, and still pretty cheap.

Can you recommend and parallel interface DAC IC as opposed to using an R2R ladder?
Here are three parallel DACs that would probably do the job:

http://www.maximintegrated.com/en/p...ters/digital-to-analog-converters/MX7523.html
http://www.linear.com/product/LTC1450
http://www.ti.com/product/tlc7524
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
Yes. And the Ford Model T is a beautiful automobile, too.
My collection of 16F877's went into the trash years ago, when Microchip introduced the dsPIC series. The dsPICs are much more powerful, WAYYYY easier to program, and still pretty cheap.
I like Fords. I practically rebuilt an 2001 AU Falcon back in 2007. The guy I sold it to on eBay loved it. I did everything but the transmission. My father has an FG XR6 Falcon now. 2010 model. But I do get your point though. The 16F877a is old obsolete technology.

The project that I speak of and its specifications has all been done before with old 40-pin PICs. Incidentally, I was the first to get an project published in the Silicon Chip magazine back in 2005 using an 16F877a MCU. It sold as an KIT in an retail store in Australia called Dick Smith Electronics. It was an fail though; it did not sell.

I feel the 16F877a is adequate enough for an 100KHz DDS. A toy it will be is true, and you would run rings around me with your modern state-of-the-art dsPICs coupled with your assembly programming skills.

I encourage YOU to consider submitting some projects to this forum, as I feel they would be very professional :)

Thanks buddy ;)
 

DickCappels

Joined Aug 21, 2008
10,180
Below is a 96 entry sinewave table. It was slightly tweaked to produce an average values as close as possible mid value of 128 because it is used to drive a transformer. Note: It is in comma separated value format.

128,136,144,153,161,169,177,184,192,199,206,212,218,224,229,234,238,242,245,248,251,252,254,254,254,254,253,252,250,247,244,240,236,231,226,221,215,209,202,195,188,180,173,165,157,148,140,132,123,115,107,98,90,82,75,67,60,53,46,40,34,29,24,19,15,11,8,5,3,2,1,1,1,1,3,4,7,10,13,17,21,26,31,37,43,49,56,63,71,78,86,94,102,111,119,128
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
One thing that I am concerned about with this project is the user interface consisting of an LCD, push buttons and an rotary encoder slowing things down when I poll them... and if I do not do it right then it would be more than slowing things down it would be interference of the waveform being produced.

Anyone got any tips?
 
Awwww come now the 16F877a is an beautiful MCU. Nice and cheap at $2 ea in low quantity on eBay too.

Can you recommend and parallel interface DAC IC as opposed to using an R2R ladder?
It's a pretty old PIC, it was more or less replaced with the 16F887. Want to use tables the 18F series have actual table instructions and they're better all around then the old 16F series. A nice nearly pin compatible upgrade to the 16F877A would be the 18F4620 or the top of the series 18F46K20 or 18F46K22 (if you want two USART ports). There are even free compilers such as XC8 or Swordfish BASIC SE (student edition).

They do make PICs with DAC outputs such as the 16F1789, it even has up to three OpAmps & four comparators! Microchip's MAPs can sort through all the PICs they make.

The beauty of PICs are the sheer number of built in peripherals, it's not hard to find just the right part for a particular application.
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
It's a pretty old PIC, it was more or less replaced with the 16F887.
True. The k150 programmer only does the 16F877a though. And I have stock inventory of 100+ pcs of this MCU. Plus I know this MCU reasonably well too. Any other chip would be a new learning curve coupled with new tools to be able to program them.

You understand my situation?
 

OBW0549

Joined Mar 2, 2015
3,566
I feel the 16F877a is adequate enough for an 100KHz DDS. A toy it will be is true, and you would run rings around me with your modern state-of-the-art dsPICs coupled with your assembly programming skills.
I did a general-purpose DDS audio signal generator with a PIC16F877 years ago, and found that 10 KHz was about as far as I could go. However, I was using a 12-bit SPI DAC to generate the output because I wanted very low THD, and that slowed things down. Also, for the same reason, I was generating the sine wave with a minimum of 10 samples/cycle at the highest frequency. But even allowing for these "over-design" factors, and figuring you wouldn't object to 5-10% THD or thereabouts, I suspect you're going to have a REALLY tough time getting much higher than 20 KHz at the top end.

Look at it mathematically: to get a 100 KHz sine wave, the theoretical (and definitely NOT practical!) minimum DAC update rate would have to be just over 200 KHz-- that is, an update every 5 microseconds. A PIC16F877A running at maximum 20 MHz clock rate executes 5 instructions every microsecond, so you've got time in between samples to execute at most 25 machine instructions. Won't work.

One thing that I am concerned about with this project is the user interface consisting of an LCD, push buttons and an rotary encoder slowing things down when I poll them... and if I do not do it right then it would be more than slowing things down it would be interference of the waveform being produced.

Anyone got any tips?
Your outputs to the DAC will have to be done in a timer interrupt, otherwise you'll end up with horrible distortion and jitter.
 
True. The k150 programmer only does the 16F877a though. And I have stock inventory of 100+ pcs of this MCU. Plus I know this MCU reasonably well too. Any other chip would be a new learning curve coupled with new tools to be able to program them.

You understand my situation?
Upgrade your programmer, a PICkit3 or even a PICkit2 would be a huge update and also allow for debugging, that K150 is ancient crap.

If you can program a 16F877A you can program any 8 bit PIC. The 18F series is bog easy compared to the obtuse 16F (almost zero bank switching, LAT instruction means no RMW problems, a larger stack, tables yay)
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
Upgrade your programmer, a PICkit3 or even a PICkit2 would be a huge update and also allow for debugging, that K150 is ancient crap.

If you can program a 16F877A you can program any 8 bit PIC. The 18F series is bog easy compared to the obtuse 16F (almost zero bank switching, LAT instruction means no RMW problems, a larger stack, tables yay)
But like I said I have stock of 100+ pcs. I need to use what I have and just get the job done. I am sniffing around for a dozen or so project ideas. Looking to try and make some money you know. I have been told that I can sell pre-programmed MCUs on the forum.
 
But like I said I have stock of 100+ pcs. I need to use what I have and just get the job done. I am sniffing around for a dozen or so project ideas. Looking to try and make some money you know. I have been told that I can sell pre-programmed MCUs on the forum.
Are you making your source code pubic domain? In my experience it's not easy just selling preprogrammed PICs unless they're wrapped around an affordable (cheap) kit.

Example. A DDS waveform generator kit $12.90 US for the whole kit CPU, LCD display, potentiometers, BNC connectors, PCB... including free shipping.
http://www.banggood.com/DDS-Function-Signal-Generator-Module-DIY-Kit-Pulse-Sine-Wave-p-958215.html


PS want a good project for a 16F877A, try building a decent programmer with it.
My ICD2 clone the Inchworm would be ideal IMHO.
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
I gave you a good project in its place :)

An ICD2 even though it's old and barely supported by Microchip anymore, is still a far better programmer then the K150. It's a little slow but it's also a debugger and can program many many PICs including the 18F2550 for when you build your first PICkit2 clone. See my Junebug PICkit2 trainer for details.

The Inchworm is very easy to build, common parts include a MAX232 or ST232 plus the .hex file is easy to find and should still be on Microchips site. MPLAB 8.xx still supports it.
 

DickCappels

Joined Aug 21, 2008
10,180
One thing that I am concerned about with this project is the user interface consisting of an LCD, push buttons and an rotary encoder slowing things down when I poll them... and if I do not do it right then it would be more than slowing things down it would be interference of the waveform being produced.

Anyone got any tips?
The concept below is used on AVR controllers, I suspect similar functionality is available on PIC controllers.

You will probably update your DAC when a timer interrupt occurs. Have one timer interrupt sleep the controller a little bit before a second timer interrupt goes off, triggering the updating of the DAC. This way, you won't have jitter in the phase resulting from where in the instruction cycle the DAC-updating interrupt occurred. It also means that in the time between interrupts the controller can busy itself by scanning control, updating displays, etc.
 
I am working on an CMOS 4000 IC tester at the moment. Got any bad news to tell me about this one? As in you can buy one already made for $12.90 inc ship!!!
Sure a 4000 / 74xx series tester would have been handy in 1980. The better ones e.g. Xeltek use a PC so they can keep the database updated.

Sales so slow that there's virtually no clone market anymore.

Might be helpful if you filled out your country in your profile.
 

Thread Starter

MCU88

Joined Mar 12, 2015
358
The concept below is used on AVR controllers, I suspect similar functionality is available on PIC controllers.

You will probably update your DAC when a timer interrupt occurs. Have one timer interrupt sleep the controller a little bit before a second timer interrupt goes off, triggering the updating of the DAC. This way, you won't have jitter in the phase resulting from where in the instruction cycle the DAC-updating interrupt occurred. It also means that in the time between interrupts the controller can busy itself by scanning control, updating displays, etc.
Yup, yup, yup I see it...
 
Top