Author Topic: little querry to get an output to flip/flop  (Read 15224 times)

0 Members and 1 Guest are viewing this topic.

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
little querry to get an output to flip/flop
« on: October 10, 2011, 11:58:52 am »
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.
 

Offline Jimmy

  • Regular Contributor
  • *
  • Posts: 224
  • Country: au
Re: little querry to get an output to flip/flop
« Reply #1 on: October 10, 2011, 12:09:03 pm »
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 
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #2 on: October 10, 2011, 12:14:52 pm »
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
 

Offline joelby

  • Frequent Contributor
  • **
  • Posts: 634
Re: little querry to get an output to flip/flop
« Reply #3 on: October 10, 2011, 12:19:19 pm »
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.
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: gb
Re: little querry to get an output to flip/flop
« Reply #4 on: October 10, 2011, 12:44:24 pm »
Exclusive OR with a '1' in the bit position you want to toggle will toggle the bit as you require.

Jim
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #5 on: October 10, 2011, 12:47:08 pm »
I think the timed set or reset bit program lines will be simpler, silly thought I can up with over lunch
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: au
Re: little querry to get an output to flip/flop
« Reply #6 on: October 10, 2011, 12:59:55 pm »
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

Wich BASIC language are you using?
Proton?

Regards
Testing one two three...
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #7 on: October 10, 2011, 01:00:46 pm »
mikroe-basic, I keep vowing to learn C but just never find the time
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: au
Re: little querry to get an output to flip/flop
« Reply #8 on: October 10, 2011, 01:06:10 pm »
ok, i am thinking you have a few options.

Instead of using +1, i would use NOT to flip the bit.
The timing can be handled by either the pics timer or use a pair of Delay statements.

Regards
Testing one two three...
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #9 on: October 10, 2011, 01:17:29 pm »
ah yes that will do it nicely
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • Country: my
  • reassessing directives...
Re: little querry to get an output to flip/flop
« Reply #10 on: October 10, 2011, 04:49:32 pm »
mikroe-basic, I keep vowing to learn C but just never find the time
why dont you go direct to asm? C is "harder" than asm, much things are out of your control, just like basic. and asm is much closer relation with the mcu. people may argue :P
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #11 on: October 10, 2011, 04:51:52 pm »
mikroe-basic, I keep vowing to learn C but just never find the time
why dont you go direct to asm? C is "harder" than asm, much things are out of your control, just like basic. and asm is much closer relation with the mcu. people may argue :P

 It is because of a number of assholes on another forum insisting that asm which i could not master was the only way and that nearly put me off electronics all together and caused a 2 year delay in my achieving anything in microcontrollers !
 

Offline cyberfish

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
Re: little querry to get an output to flip/flop
« Reply #12 on: October 10, 2011, 07:53:22 pm »
Quote
why dont you go direct to asm? C is "harder" than asm, much things are out of your control, just like basic. and asm is much closer relation with the mcu. people may argue :P
ASM is suitable for some jobs, but for 95% of other things, C is much more suitable.

ASM makes introducing bugs easier, takes a lot longer to write, and the code a lot harder to read and maintain. Don't use ASM unless necessary.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12346
  • Country: us
Re: little querry to get an output to flip/flop
« Reply #13 on: October 10, 2011, 08:23:14 pm »
why dont you go direct to asm? C is "harder" than asm, much things are out of your control, just like basic. and asm is much closer relation with the mcu.
This is a crazy opinion.  :o

Quote
people may argue :P
Indeed they may.   ???
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12346
  • Country: us
Re: little querry to get an output to flip/flop
« Reply #14 on: October 10, 2011, 08:26:18 pm »
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.
The simplest idiom in a language like BASIC is this:

Code: [Select]
x = 0
while (forever)
  x = 1 - x
end
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #15 on: October 10, 2011, 08:51:58 pm »
The usual argument is that asm is faster, well my little 12F micro @ 4MHz can keep up with a car engine and more running a basic program so I can't see why i need asm in there
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19905
  • Country: gb
  • 0999
Re: little querry to get an output to flip/flop
« Reply #16 on: October 10, 2011, 09:24:02 pm »
On the PC, I found assembly easier to learn than C which just made me want to give up.

I've used BASIC before but never on an MCU.

I've only done a little programming on MCUs and used assembler which I found quite straightforward.
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: little querry to get an output to flip/flop
« Reply #17 on: October 10, 2011, 10:00:45 pm »
On the PC, I found assembly easier to learn than C which just made me want to give up.

And why do you think that single data point, if true, is sufficient to generalize?
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19905
  • Country: gb
  • 0999
Re: little querry to get an output to flip/flop
« Reply #18 on: October 10, 2011, 10:32:18 pm »
On the PC, I found assembly easier to learn than C which just made me want to give up.

And why do you think that single data point, if true, is sufficient to generalize?
I'm not.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12346
  • Country: us
Re: little querry to get an output to flip/flop
« Reply #19 on: October 11, 2011, 02:10:56 am »
If you "understand" computer hardware then assembly is easy (if tedious); otherwise it is not. However, C is like high level assembly, so if you don't "understand" computer hardware at an intuitive level then C is also hard to learn. On the other hand if you are comfortable with assembly then programming in C should be like a walk in the park.

BASIC is in a different language family, quite deliberately so. Computers are supposed to be labour saving devices, and if BASIC saves on labour compared to C then  program in BASIC and be happy!
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10219
  • Country: nz
Re: little querry to get an output to flip/flop
« Reply #20 on: October 11, 2011, 02:16:57 am »
Programming windows apps in C  is much harder than C programming for a microcontroller.

The Windows API is full of objects, structures and weird callback routenes which can be very annoying to get your head arround when starting out.
You end up writing lots of boring API code just to 'tell' windows to create you a form.
Of course modern IDE's often generate a lot of that code for you, so it's not too bad, but the code is still visible in your editior and gets in the way of following your actual code logic.

When coding a microcontroller in everything is so much simpler. There is no OS API to interface with (unless you create one).
Microcontroller code is normally quite easy to read and understand, even if you have limited skills in the language.
After all, an IF and a LOOP is pretty easy to figure out in almost any language.
(The obvious exception is ASM, where you really have to know the language to be able to read it)

One thing you do need to understand when working with microcontrollers is bitwise operations and how use them. They're used far far more in microcontroller programming than windows programming.
« Last Edit: October 11, 2011, 02:29:58 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • Country: my
  • reassessing directives...
Re: little querry to get an output to flip/flop
« Reply #21 on: October 11, 2011, 02:23:20 am »
here we go again
It is because of a number of assholes on another forum insisting
i'm not insisting, its just only suggestion since the OP did mention vb vs c
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18022
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: little querry to get an output to flip/flop
« Reply #22 on: October 11, 2011, 05:40:22 am »
well I'm not sure how C compares to BASIC, I thought it was about as easy/hard to learn, maybe not ?
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • Country: my
  • reassessing directives...
Re: little querry to get an output to flip/flop
« Reply #23 on: October 11, 2011, 06:03:48 am »
same
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12346
  • Country: us
Re: little querry to get an output to flip/flop
« Reply #24 on: October 11, 2011, 06:09:05 am »
well I'm not sure how C compares to BASIC, I thought it was about as easy/hard to learn, maybe not ?
BASIC was designed to make it easy to get results out of a computer--designed help make writing programs fast and convenient. There have been many varieties of BASIC since the first one but all of them have had the same philosophy, a classic example being Microsoft Visual Basic. Visual Basic is the archetypal "get results fast" language.

On the other hand C was designed to get "close to the metal". Everything about the language was intended to give you complete and full control over the hardware at the level of pointers, memory and data bits. It was intended to let you write every program you could write in assembly, only more easily.

So easy/hard to learn is relative, but I would have to say in general that BASIC is easier to learn than C.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf