Creating a single pulse in ATmega1608

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

Hi, I am trying program ATmgega1608 but have a question. I want to make a single 30us pulse on pin PA3, at the beginning of program and after that it should go back to low. I have few things in mind like making one PWM pulse, but not sure it is the right thing to do. I can also use single shot mode, but there is no event that will generate it at that time. Any suggestions what can I do?

 

Thank you.

This topic has a solution.
Last Edited: Wed. Aug 3, 2022 - 06:44 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is teh VERY first thing your program will do, maybe use teh _delay_us() function and save your sanity?

 

//start of my widget code

set port A3 to low
_delayms(100);
set port A3 high
_delayus(30);
set port A3 low


//the rest of my amazing widget code goes here

 

 

Why make life difficult if you do not have to?

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

jgmdesign wrote:

If it is teh VERY first thing your program will do, maybe use teh _delay_us() function and save your sanity?

 

//start of my widget code

set port A3 to low
_delayms(100);
set port A3 high
_delayus(30);
set port A3 low


//the rest of my amazing widget code goes here

 

 

Why make life difficult if you do not have to?

 

Jim

I totally agree with your solution, but is there any other way?

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

Sure there’s other ways.  Set up a timer to do PWM as you mentioned.  Just seems like a lot of extra work

 

You could also use a timer to do,exactly what I mentioned in post #2 as well instead of PWM.  Much simpler

 

jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Sanka1p wrote:
is there any other way

 

Why it should be any other way. I exactly do this on my projects (if there is one pin free), with the difference that the light pulse is 50us.

 

Of course, it all depends on resistor and Led color, I use 100Ohm to White LED.

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

a) Use _delay_us - simple blocking solution, can control any pin
b) Set pin high, start some timer with top/period at 30us and enable IRQ, in IRQ routine set pin low - complicated non blocking solution, can control any pin
c) use timer output, set timer in "single shot", generate SW event to start timer - the most precise, non blocking solution, can control only TCB output pins or EVOUT
d) use external hardware (RC or CR network)
...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int main() {
  PORTF.DIRSET = PIN5_bm;
  PORTF.OUTSET = PIN5_bm;
  TCB0.CCMP = 999;
  TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm;
  while ((TCB0.INTFLAGS & 0x01) == 0);
  TCB0.INTFLAGS = 0x01;
  PORTF.OUTCLR = PIN5_bm;
  TCB0.CTRLA = 0;

  ...
}

^ Use TCB0 and poll for the timer completion.

Last Edited: Fri. Aug 5, 2022 - 12:31 AM