• AVR Freaks

Hot!Assigning a PORT pin to pointer or variable: How can that be done?

Page: < 1234 Showing page 4 of 4
Author
ric
Super Member
  • Total Posts : 24624
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 20:02:44 (permalink)
+1 (1)
user2x
Or did you mean to say that I should have a soft counter per led and run a fast enough timer ISR so there is 1 interrupt per soft count?

Yes!
You need about 50Hz period for no flicker,  so if you want 8 bit PWM, you need 50*256 = 12,800Hz interrupt minimum.
 
post edited by ric - 2019/11/18 20:04:44

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#61
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 20:24:44 (permalink)
0
I actually need to get away from 50Hz and 60Hz by at least 25Hz. Some people can see flikker of 30Hz. So I need ~90Hz.
 
That takes it to:
90*256 = 23.040kHz.    
 
To do this, I really need a timer. I have none and want to use a MCCP timer for the purpose.
I can't get that to work (yet), see my other post.
https://www.microchip.com/forums/m1119247.aspx
 
 
#62
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 20:28:02 (permalink)
0
(Access denied again -- Sigh)
 
For for 23.040kHz, there has to be an interrupt every 43.4us.
The optimised code as previous, for 9 LEDS takes 21.04us to execute at he moment, without the suggested counters.
 
That would mean the CPU will be 50% busy just doing the LEDS.  I don't think that will work.
#63
ric
Super Member
  • Total Posts : 24624
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 20:39:44 (permalink)
+1 (1)
Don't you already have a timer running at 38kHz ( https://www.microchip.com/forums/FindPost/1119144 )
You can do more than one thing in each timer service.
I would expect the counter code to execute quicker than your previous attempt.
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#64
ric
Super Member
  • Total Posts : 24624
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 20:49:17 (permalink)
+1 (1)
user2x
I actually need to get away from 50Hz and 60Hz by at least 25Hz. Some people can see flikker of 30Hz. So I need ~90Hz.

I don't follow your logic.
If they can see 30Hz flicker, why can't you use 50Hz?
This is the actual refresh rate, so it's flashing at 50 Hz, not 25 Hz.
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#65
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/18 21:04:36 (permalink)
0
Ahh, but the flikker comes from the beating with mains operated lights, not the actual refresh rate.
 
So at 50Hz LED frequency, you will see a 10Hz flikker in a room with a 60Hz mains operated light.
 
post edited by user2x - 2019/11/18 21:05:40
#66
oliverb
Super Member
  • Total Posts : 245
  • Reward points : 0
  • Joined: 2009/02/16 13:12:38
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 02:15:48 (permalink)
+2 (2)
That shouldn't happen with LEDs as the LED is a light source not a reflector, so its intensity should not depend on the ambient light level. You might get a beat frequency if your DC is unsmoothed and the LED illumination gets modulated by mains ripple, but not from light level.
 
#67
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 02:29:26 (permalink)
0
oliverb
That shouldn't happen with LEDs as the LED is a light source not a reflector, so its intensity should not depend on the ambient light level. You might get a beat frequency if your DC is unsmoothed and the LED illumination gets modulated by mains ripple, but not from light level.
 



I respectfully disagree. The human eye has interesting properties.
#68
ric
Super Member
  • Total Posts : 24624
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 02:54:57 (permalink)
0
I guess somehow you're getting some mixing in your particular device.
I've certainly used 50 Hz refresh on LEDs on a few products, and never observed your effect.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#69
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3348
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 05:56:50 (permalink)
+1 (1)
You make some strange claims.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#70
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3348
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 06:06:09 (permalink)
0
Make the cpu 0% busy.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#71
NorthGuy
Super Member
  • Total Posts : 5810
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 07:31:55 (permalink)
+1 (1)
user2x
That would mean the CPU will be 50% busy just doing the LEDS.  I don't think that will work.



The code will take time whether you run it from the interrupt or from the main. Only the interrupt itself is the overhead, especially if you program in C.
 
Interrupt will give you the time base. Without interrupt you're likely to get flicker from other interrupts meddling with your timing. If you give your interrupt higher priority, it'll be very solid.
 
If you have a counter for each LED, it's 2 instructions per LED - 1.1 us for 9 LEDs if you run at 16 MHz - totally insignificant.
#72
marcov
Super Member
  • Total Posts : 255
  • Reward points : 0
  • Joined: 2006/10/08 01:59:40
  • Location: Eindhoven, NL.
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 09:20:04 (permalink)
0
I have a bunch of lats trigger a bunch of pressure valves on a quadrature encoder timeline, so I tried to optimize setting a _bunch_ of lats in an event. I think setting each single valve costs around .25us.

See https://www.microchip.com/forums/m794597.aspx  Thanks again to Northguy who provided most of the answered in that thread.
 
 
 
 
#73
marcov
Super Member
  • Total Posts : 255
  • Reward points : 0
  • Joined: 2006/10/08 01:59:40
  • Location: Eindhoven, NL.
  • Status: offline
Re: Assigning a PORT pin to pointer or variable: How can that be done? 2019/11/19 09:33:30 (permalink)
0
The forum won't allow changing posts, so for the record, this is a MU814 at 60MHz.
#74
Page: < 1234 Showing page 4 of 4
Jump to:
© 2019 APG vNext Commercial Version 4.5