Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

attiny25, PWM and RC5
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various
View previous topic :: View next topic  
Author Message
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Tue Feb 21, 2012 7:46 pm    Post subject: attiny25, PWM and RC5 Reply with quote

Hey all Smile

new project here Very Happy
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
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Wed Feb 22, 2012 11:48 am    Post subject: Reply with quote

use a tiny25?
Back to top
View user's profile
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Wed Feb 22, 2012 8:23 pm    Post subject: Reply with quote

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 Smile

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
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Wed Feb 22, 2012 9:25 pm    Post subject: Reply with quote

Please write in English. This forum is English only.
_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Wed Feb 22, 2012 9:43 pm    Post subject: Reply with quote

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.

Smile
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 299
Location: Berlin

germany.gif
PostPosted: Wed Feb 22, 2012 10:58 pm    Post subject: Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Thu Feb 23, 2012 5:39 am    Post subject: Reply with quote

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
View user's profile
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Thu Feb 23, 2012 5:30 pm    Post subject: Reply with quote

I'll look around, thanks Smile
Back to top
View user's profile
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Sat Mar 10, 2012 4:02 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sat Mar 10, 2012 4:32 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Sun Mar 11, 2012 2:14 pm    Post subject: Reply with quote

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
View user's profile
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Tue Mar 13, 2012 5:41 pm    Post subject: Reply with quote

hmm, RC5SEND seems to need timer1 to be 16 bit, right?
the tiny25 only has 8 bit timers ...
Back to top
View user's profile
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Thu Mar 15, 2012 8:37 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Mar 16, 2012 12:14 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
wing23

Bascom Member



Joined: 21 Jan 2012
Posts: 35

germany.gif
PostPosted: Fri Mar 16, 2012 6:16 am    Post subject: Reply with quote

I thought so, so what I've tried after that is this:

Code:
$regfile = "ATtiny25.dat"
$crystal = 8000000
$hwstack = 16
$swstack = 8
$framesize = 16

Config Rc5 = Pinb.2                                         'RC5 option
Config Pinb.4 = Output                                      ' pwm
Enable Interrupts

Pinb.4 = 0
Waitms 50

Config Timer1 = Pwm , Compare B 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
Ocr1b = Pwm_val
Wait 1
Ocr1b = 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
         Ocr1b = Pwm_val
      Else
         Pwm_val = 255
         Ocr1b = 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
         Ocr1b = Pwm_val
      Else
         Pwm_val = 0
         Ocr1b = Pwm_val
      End If
   End If
End If
Loop
End


in bascomforum.de someone wrote: it seems bascom doesn't set the PWM1B and also forgets to set the pin to output
so there have to be another 2 lines:
DDRB.PB4 = 1
GTCCR.PWM1B = 1

First I tried this code and then the suggestions but I still don't get a PWM signal on pb.4
that's why I came back here
it seems that there are other people having problems with tiny25/45/85 Smile


Last edited by wing23 on Fri Mar 16, 2012 5:53 pm; edited 1 time in total
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Various All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum