Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
// do simultaneous pulse output on OC1A and OC1B pins with different frequencies //OC1A will be at 50Hz for 20 seconds (1000 pulses) // start OC1A output pulseT1ASetFreq(50); pulseT1ARun(1000); LED_on; // turn on the status LED
Specifically on the ATmega168 there are 6 PWM channels. Does PWM on those pins run in the background?Also what exactly am I looking for in the datasheet. What kind of phrasing?Thanks
Here's a good example by zer0w1ng from his home page: http://geekzone.freehostia.com/
value that fits in 8 bits (156)
You could use a prescale of /64 and an ICR of 255 which with your 1MHz chip would be a base freqency of approximately 30Hz. Then use OCRxx settings of 1-254 to get the full range of duty cycles on each pin. You could also use a prescale of /8 and have a base frequency of approx 244Hz.
Quote from: creedcradle on November 18, 2008, 07:16:53 AMHere's a good example by zer0w1ng from his home page: http://geekzone.freehostia.com/Where exactly is it there?Also if I am not bit-banging and I have hardware PWM channels, then I could do PWM1 ,PWM2, PWM3 successively and it will run in the background , right?
Tiny Threads - Tiny Multitasking Threads for Microcontrollersby: Regulus Berdin * Idea based on http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html. * Only 1 byte RAM needed per thread. * Very small overhead context switching.Limitations: * Maximum 254 lines per thread. * Thread context switching will not work within a switch block.Usage example: TT_DEF(1) { TT_BEGIN(1); while (1) { ... TT_SWITCH(1); ... ... TT_WAIT_UNTIL(1,keypress); } TT_END(1); } TT_DEF(LED_TASK) { TT_BEGIN(LED_TASK); while (1) { LedOn(); delay=DELAY_1_SECOND; TT_WAIT_UNTIL(LED_TASK,delay==0); LedOff(); delay=DELAY_1_SECOND; TT_WAIT_UNTIL(LED_TASK,delay==0); } TT_END(LED_TASK); } void main(void) { ... ... while(1) { TT_SCHED(1); TT_SCHED(LED_TASK); } }
Software PWM in separate threads is an easy way to ask for trouble
Since you're only controlling LEDs and so the PWM doesn't need to be 100% accurate then you could always use the scheduler from:http://www.societyofrobots.com/robotforum/index.php?topic=541.0This only uses one timer and you can use the service routine to flip the port pin on any pin - so now you can make any, or all, of your IO pins into PWM
I wouldn't rely on threading if the MCU is not fast enough, except maybe very slow tasks (blinking a led, sending 2400 baud data, reading a button).Software PWM in separate threads is an easy way to ask for trouble
UART on interruptwhen it isnt in an interrupt do a PWM on the pins using servo-type software or hardware timer based
From what I understand I can use one hardware timer to generate the proper PWM for six pins at the SAME time. Is this correct?
would I have to do the "certain amount of time to wait" in a resolution of uS(instead of the usual mS that servos use) , so I get a better PWM