Electronics > Microcontrollers

little querry to get an output to flip/flop

(1/10) > >>

Simon:
So I have a project I am already using the PWM output but i need another oscillating output that is no available on the pic I'm using. The program will run in a cycle that coincides with each PWM cycle so I had a thought, using basic as the language, have a "bit" type variable and add 1 to it each time I get round to "that" line of the program, in this way I should get a 0 1 0 1 0 1 0 1..... output, right ? or is there another way of doing it with complicated program lines, I just need a toggling output, frequency and duty are not much of a problem.

Jimmy:
You will have to turn it on and off you can turn it on at the beginning and off half way through your program to output what you want 

Simon:
I could do, i just wondered if I had a single bit variable 0 = 0, 0+1=1, 1+1=0, 0+1=1 etc

joelby:
Can you use a byte type and invert it each time, and then use the lowest bit (foo & 0x01)? You could increment a byte variable too, but using an adder seems like overkill for just toggling a bit.

jimmc:
Exclusive OR with a '1' in the bit position you want to toggle will toggle the bit as you require.

Jim

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version