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.

PIC18 Question: Is it possible to output a binary sequence square wave?

Status
Not open for further replies.

picbeginner

New Member
Hello,

I am a beginner in PIC programming. I'm using the PIC18F4550 and I've been able to implement a few of the functionalities of PIC microcontrollers, but I was wondering if it was possible to output a binary sequence.

In other words, I got PWM working for 50% duty cycle, so I can get a 10101010 (and repeated) using the CCP/PWM pin...

But is it possible to output something like, 10011101 (and repeated)? I've been browsing the web and I may not be googling the right terms. Only thing that I can think of is to alter the duty cycle constantly.

Is there an easier way?

Thanks!
 
You can load the SPI with 10011101 but how to get to repeat?
Maybe if you connect Dout to Din ....I don't know.

Do you want that pattern or any pattern?
How fast?
 
It depends how fast you want it. If it's a fairly low baud rate (<100k) then it can be done using an interrupt and the PWM module.

Mike.
 
Not sure how it is with PICs, but with xmega I can use the uart in spi mode with a buffer for tx, so it is possible to output serial data very fast, and still have enough time for the data register empty interrupt to supply new byte. For lower transmit speed it should be possible to make it even without the data buffer.
 
I agree that using a serial output is probably easiest. Either TX from the uart, or SPO from the MSSP/SPI.

Add an interrupt from TX buffer empty to reload the value.
 
Last edited:
Just 2 cents worth, what about using a CONST array with the bits arrangerd as you like then just call the array const.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top