View previous topic :: View next topic |
Author |
Message |
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Tue Feb 21, 2012 7:46 pm Post subject: attiny25, PWM and RC5 |
|
|
Hey all
new project here
I want to dim some LEDs, so I need PWM. I also want to be able to add a remote control option, so I need RC5.
The µC is an attiny13a.
I got the PWM part running, now I wanted to make the RC5 part, but I noticed that RC5 also needs a timer, the attiny13a has only one.
Though people told me that it would be possible to use RC5, PWM and even 2 additional buttons/switches - I did not find anything related on the web.
Do I have to realize the PWM part via software instead of timer0 or is there a better way?
(the functions I planned to use: 2 hardware buttons for incr/decr duty cycle, 1 port for IR receiver RC5, 1 port for PWM)
since there's only 1 timer I'm currently not sure what to do hmm
Best regards,
Nik
Last edited by wing23 on Sat Mar 10, 2012 3:47 pm; edited 1 time in total |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Wed Feb 22, 2012 11:48 am Post subject: |
|
|
use a tiny25? |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Wed Feb 22, 2012 8:23 pm Post subject: |
|
|
lol, das wäre eine Option.
ich hab irgendwie den 25er nicht gefunden bisher XD
Aber der ist auch teurer, bei ebay hab ich 100 Stk tiny13a für 72 EUR gesehen, beim tiny25 wären es schon etwa 150 EUR
Was empfiehlt man denn als clock source, wenn man nur die interne nutzen möchte?
Beim tiny13a hab ich die 9.6 MHz genommen.
Last edited by wing23 on Wed Feb 22, 2012 9:45 pm; edited 1 time in total |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 22, 2012 9:25 pm Post subject: |
|
|
Please write in English. This forum is English only. _________________ / Kim |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Wed Feb 22, 2012 9:43 pm Post subject: |
|
|
oh I see, for some reason I thought I could reply in German, must have been the country flag on laborratte's post or whatever XD
sorry, alright:
lol, this would be an option
somehow I didn't find the tiny25 until now XD
but it's also more expensive, on ebay I found 100 pcs pf tiny13a for 72 EUR, the same amount of tiny25 would cost me at least 150 EUR
what's suggested as clock source if using internal clock source?
I set the tiny13a to 9.6 MHz.
|
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Wed Feb 22, 2012 10:58 pm Post subject: |
|
|
if the price is a serious problem for you:
Other than BASCOM's RC5-Routine (it manipulates the timer0 on each call of GETRC5 - and that would cause a flicker on your LED), you could realize a RC5 receiver by using a constant free running timer0 as in the original application note AVR410 (http://www.atmel.com/Images/doc1473.pdf) . This timer than could generate a PWM signal too.
Welcome in the world of assembler... |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Feb 23, 2012 5:39 am Post subject: |
|
|
Mouser electronics seem to have them for less than 1 EURO if that helps
Regards Paul
Last edited by Paulvk on Fri Feb 24, 2012 5:48 am; edited 1 time in total |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Thu Feb 23, 2012 5:30 pm Post subject: |
|
|
I'll look around, thanks |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Sat Mar 10, 2012 4:02 pm Post subject: |
|
|
ooookay.
changed the topic to attiny25
I ordered one and now try to write the RC5 decoder part.
since I don't know which remote control sends RC5 data, I 1st want to find out more about my RCs here.
Therefore I tried to display the address and command on an LCD using my mega128 dev-board using the bascom RC5 routine.
To no success so far.
So I looked around on the WWW and found a code that doesn't use Bascom's RC5 commands but is able to read more remote controls.
But I don't see anything on my LCD at all ...
I guess it's alright to post the code I found here.
I made some small changes to be able to use my LCD, a different crystal and a different µC port pin, so there was a change about int and timer start value.
Though I think (or hope) I calculated it correctly:
attached the bas file.
my changes:
original code used int7 on porte.7, I use int6 on porte.6
original code uses 16 MHz crystal, I use the internal 8 MHz RC clock
therefore I altered timer1 start value from 56 to 156 (which should generate the 10KHz)
then I added toggle porte.2 in the "if code_found = 1" part to toggle an LED connected to porte.2
it makes me wonder that the LED is toggled everytime I hit a key on any remote control, but the LCD displays nothing at all ...
I also have a philips TV RC, but it's no help.
does anyone know what's wrong?
If I'm able to find out which of my RCs sends RC5 code I can go over to write the code for my attiny25 project ... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Sat Mar 10, 2012 4:32 pm Post subject: |
|
|
impressive piece of code. never seen it before.
i think you can best buy an IR led, and use the bascom rc5send to make your own simple transmitter. then you know it is RC5 code.
philips uses RC5 or RC6.
As always :
- make sure the $crystal value indeed matches the real value (divider fuse, wrong fuse, etc.)
- simple test:
$crystal=8000000
config portb=output
do
toggle portb
waitms 1000
loop
now check portB output, it need to blink with 1 sec on, 1 sec off.
Usually when $baud delivers the proper baud rate, the $crystal value is ok. _________________ Mark |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Sun Mar 11, 2012 2:14 pm Post subject: |
|
|
Hello Mark,
the timing seems to be alright.
I didn't comment out the baud parts, though I don't use a serial connection and try to display everything on the LCD
I have IR LEDs lying around here, I might try to make a RC5 transmitter to test the code above |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Tue Mar 13, 2012 5:41 pm Post subject: |
|
|
hmm, RC5SEND seems to need timer1 to be 16 bit, right?
the tiny25 only has 8 bit timers ... |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
Posted: Thu Mar 15, 2012 8:37 pm Post subject: |
|
|
well anyway ...
I tried it the other way around into the blind (means, without an LCD to display the sent code)
what I did:
took my attiny25, wrote the small getrc5 code into it (if code = 16 -> port on, elseif code = 17 -> port off)
took a remote control, hit the volume buttons and it worked!
now I tried to combine it with my PWM code and now I got the problems coming ...
the pwm works, but the RC5 part doesn't work anymore.
I THINK it's because the PWM needs timer0 and RC5 also needs timer0, right?
now I tried to use timer1 for the PWM part, to no success
I read that bascom has problems with config timer1.
I also can't use PWM1A instead of PWM0Am though I can use OCR1A but the PWM dimmer just won't work
simple code example:
Code: | $regfile = "ATtiny25.dat"
$crystal = 8000000
$hwstack = 16
$swstack = 8
$framesize = 16
Config Rc5 = Pinb.2 'RC5 option
Config Pinb.0 = Output ' pwm
Enable Interrupts
Pinb.0 = 0
Waitms 50
Config Timer0 = Pwm , Compare A Pwm = Clear Up , Prescale = 64
Dim Address As Byte , Command As Byte
Dim I As Byte
Dim Pwm_val As Integer
Dim Pwm_step As Integer
Dim Pwm_sum As Integer
Pwm_val = 0
Pwm_step = 20
Pwm_val = 200
Pwm0a = Pwm_val
Wait 1
Pwm0a = 0
Do
Getrc5(address , Command)
If Address = 0 Then
Command = Command And &B01111111
If Command = 16 Then
Pwm_sum = Pwm_val + Pwm_step
If Pwm_sum <= 255 Then
Pwm_val = Pwm_val + Pwm_step
Pwm0a = Pwm_val
Else
Pwm_val = 255
Pwm0a = Pwm_val
End If
Elseif Command = 17 Then
Pwm_sum = Pwm_val - Pwm_step
If Pwm_sum > 0 Then
Pwm_val = Pwm_val - Pwm_step
Pwm0a = Pwm_val
Else
Pwm_val = 0
Pwm0a = Pwm_val
End If
End If
End If
Loop
End |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Fri Mar 16, 2012 12:14 am Post subject: |
|
|
because getrc5 uses timer0, you can not use timer0 for pwm.
you must use timer1.
if config timer1 does not work, show the code you tried.
you can always configure the timer yourself by writing to the timer registers. it might be the case that timer1 in the tiny25 has a difference i did not catch. _________________ Mark |
|
Back to top |
|
|
wing23
Joined: 21 Jan 2012 Posts: 35
|
|
Back to top |
|
|
|