How to read pin value without PWM

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I'm using atmega328P with TSOP infrared detector (pin PD2) and Infrared diode TSAL 6200 (pin PB0). I know that my detector is changing value if aim emitting infrared diode (38 kHz) on infrared detector. Unfortunately my infrared diode is not connected to pin which support PWM modulation. In my code im using UART via ft232RL and i want to send value of pin PD2 to hyperterminal. Problem is in my while cycle in my code. I need to fix it, i need to keep my IR led emitting while i want to read pin value. There is my code:

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know about your h/w connections, you said you are using PD2 but in code you have written DDRD=0b00000010.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes i use pin PD0 as RX (input) and pin PD1 for TX (output) and detector is on pin PD2 (input), so thats should be right. Im sry for my english, im not native speaker

Last Edited: Mon. May 25, 2015 - 07:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try by using PIND & (1<<2) instead PIND==(1<<2) this might work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can read value with PIND & (1<<2) and also with inverted result with PIND==(1<<2) but the main problem is, that my diode not blinking in this while loop. I need to blinking with infraLED (PB0) and read value of receiver PD2 in the same time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OP said: I want to do two things at the same time

 

In you code you have:    _delay_ms(1000);

What do you think this does?

While your in the delay loop, your cpu can do nothing else.

You must remove the "delays" and use some other method for your timing of your main loop in order to more then one thing at a time.

Hint:  Use a timer and have it set a flag, in main if the flag is set, do something, and clear the flag.

 

Check out the tutorial forum for hints on using a timer for such activities.

 

 

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
https://www.onegold.com/join/7134f67c2b814c5ca8144a458eccfd61

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is there a "continue;" at the end of the while() loop?

Unfortunately my infrared diode is not connected to pin which support PWM modulation

So why not move it to a pin that does if that's what you need?!?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I cant change the pin because ive already made it to PCB (yes it was my bad early in construction), thats my first board. I saw that somebody used "continue;". Maybe i should use timer as ki0bk said

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You cannot generate the frequency for the IR Led in the main loop.

A timer in CTC mode is mostly used for this.

Or set a timer to overflow every 13 microsec an in the ISR toggle the output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh this used to happen all the time in the early days of PCB design/routing. That's why God invented:

 

https://www.sparkfun.com/product...

 

cheeky

 

It's quite ridiculous to proceed otherwise - you end up having to implement soft-PWM or soft-UART or whatever it is with a huge cost in software complexity and development time to correct a simple error that could be fixed by a short strand of blue wire (it's always blue by the way - just traditional!). When you respin the PCB (as you inevitably will - this probably isn't the only error!) you can then just correct this kind of thing.

 

(I assume you only made a handful of prototype PCBs, not had 200,000 production units made already? - Now that would be a huge mistake)

 

PS I've said it before and will no doubt say it again but has making prototypes gone completely out of fashion? In the old days you'd either prototype the entire design or perhaps just some parts of it on breadboards or something thrown together on a piece of veroboard. Only when you had "proof of concept" would you commit to copper. I know this is easier with DIP packaged rather than SMD chips but generally you can solder any SMD you are using to carrier boards with 0.1" pin spacing for use in the breadboard or veroboard etc.

Last Edited: Tue. May 26, 2015 - 09:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I appreciate all advices, i will try to do something and then i will let you know, if i solve the problem or not.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, to avoid the fix output pin in CTC mode, you can use a compare interrupt and toggle the output there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Oh this used to happen all the time in the early days of PCB design/routing. That's why God invented:

 

https://www.sparkfun.com/products/8187

Is the chip still available as a DIP?  If not one must first make a board that will fit into the wire-wrap socket.

Also, that particular socket is not available at the moment.

Quote:
It's quite ridiculous to proceed otherwise - you end up having to implement soft-PWM or soft-UART or whatever it is with a huge cost in software complexity and development time to correct a simple error that could be fixed by a short strand of blue wire (it's always blue by the way - just traditional!). When you respin the PCB (as you inevitably will - this probably isn't the only error!) you can then just correct this kind of thing.
How old is the tradition?  My recollection is hearing about the "yellow wire phenomenon" from a professor.

 

My URL detector seems to have boundary issues.

"SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then." -- John Woods

Last Edited: Tue. May 26, 2015 - 11:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How old is the tradition?

A bit over 30 years for me - but maybe it's just the lab technicians where I worked had a big reel of blue wire wrap? cheeky