PROTOCOL NEC HELP

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

PROTOCOL NEC HELP

Post by Genilsonsa »

Ola a great 2016 for all.I wish once more to ask the help of you.I am already in the final phase of a project of interfacing of an appliance from karaoke to adapt in machines here in Brazil.now only need to do the typing of keys for Karaoke.I was studying on the protocol NEC and I would like to know if SCV has as I explain how it works and whether it is possible to implement this in FLOWCODE.

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

NReading a tutorial I understood that this protocol NEC consists of 4 bytes being that address / INVERT ADDRESS /Command /INVERT COMMAND,however like to an aid of how to implement it.

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

My 1st doubt is about start bit.I have to put 1 bit in 9ms in low and the 2 bit 4,5ms in high.This this correct or does not ? Someone who has already worked with NEC protocol with flowcode can help me.

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

I tried to make a simulation of the start bit and like that voçes analizasse if is correct.
Attachments
start bits.fcf
(6 KiB) Downloaded 387 times

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

Ola a todos depois de muita insistência consegui fazer funcionar um transmissor do protocolo NEC que necessitava para um de projeto de interface que preciso fazer nesse ano.E como estava na duvida passarei o exemplo que peguei aqui mesmo no forum.
START BIT = 9MS em LOW e depois 4MS EM HIGH
LOGICO 1 = 565 us em LOW e logo em seguida 1.680 ms em HIGH
LOGICO 0 = 565 us em LOW e logo em seguida 565 us em HIGH
STOP BIT = 9ms em LOW e logo em seguida 2ms em HIGH e mais um pulso de 565us em LOW e 565us em HIGH.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PROTOCOL NEC HELP

Post by Benj »

Hello,

Here is an example that should help to get you started. I simply broke down the protocol into sections and created a macro to output each of the sections.
NEC.fcf
(11.89 KiB) Downloaded 443 times

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

Good Night BENJ you is very good . Thank you for allowing me to reply I managed to do, but it was not that way as efficient and objective which you made ,because I am not so bao as agentkeys that knows very of flowcode .i did well
Attachments
PWM.fcf
(31.04 KiB) Downloaded 353 times

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

I will examine a little more to learn how to use macros.Because is well easier understanding.Thank You

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

Hello Benj i am by examining your example and vi that you do not declare any variable and yes names such as .date and .command vc can explain to me what this means.because I thought that interesting this influences anything .

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PROTOCOL NEC HELP

Post by Benj »

Hello,

.variables are local variables or local parameters which exist only inside the macro. This helps to save RAM usage and make your program more modular.

The project explorer is very useful as it shows you the global variables in the Globals tab but also shows you the locals in the Macros tab.
ProjExp.jpg
ProjExp.jpg (30.96 KiB) Viewed 14172 times
You can also edit the locals when creating a new macro or by double clicking the start icon in a macro.
MacroProps.jpg
MacroProps.jpg (41.09 KiB) Viewed 14172 times
Parameters are values passed into the macro from the calling icon.

Local variables are values used inside the macro to do calculations or keep track of things etc.

Genilsonsa
Posts: 150
Joined: Mon Oct 15, 2012 5:19 pm
Has thanked: 12 times
Been thanked: 18 times
Contact:

Re: PROTOCOL NEC HELP

Post by Genilsonsa »

Ola Benj thank you for allowing me to reply .very interesting and util this mode of use .I will examine more macro to learn to do this .Show of ball . Thank You

:D

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: PROTOCOL NEC HELP

Post by mikn »

Benj wrote:Hello,

Here is an example that should help to get you started. I simply broke down the protocol into sections and created a macro to output each of the sections.
NEC.fcf
Hi Benj,

Tried to run this on Arduino Pro 328 5v, but changed output to D3.
The led is blinking (I look via camera) but the receiver does not recognize the data (receiver is running arduino code).
Is 16mhz enough to run this? Should I change delays from 560us to less?
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PROTOCOL NEC HELP

Post by Benj »

Hello Mikn,

An Arduino running at 16MHz should be fast enough to output the signals at the right speed.

I take it the NEC protocol is being sent over IR. The IR emitter and detector will have a peak frequency e.g. 36KHz. The IR emitter should be switched on and off at the right frequency when the output pin is high to allow the receiver to correctly receive the signal and filter it from other signals.

On our EB060 board we do this using a PWM output to get the right frequency to drive the IR emitter and use a diode to allow the enable signal to switch the PWM signal to the IR emitter on and off.

PWM frequency 36KHz
PWM duty = 50%

On page 6 of the datasheet below there is a circuit diagram.

http://www.matrixtsl.com/resources/getr ... php?id=116
IR_Modulation.jpg
IR_Modulation.jpg (19.76 KiB) Viewed 13362 times
TX_IN = NEC Output signal
TX_P_OUT = PWM Output Signal

The PWM could be provided by the micro or from a 555 timer or from a separate 10F device etc.

Pages 4 and 5 of the datasheet explain the IR modulation with a diagram.

Hope this helps.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: PROTOCOL NEC HELP

Post by mikn »

understand now. the problem is that i have used constant light instead of 38khz modulated signal.
and now I understand why you use two different pins in IR settings PWM and Output.
I use simple IR diode connected to D3 and GND. With arduino code it works well, now need to run with FC.

ps: check the video in the attachment. seems like a bug in PWM settings, when I select different channels it selects randomize pins.
Attachments
16-06-28_14-22_0001.rar
(551.88 KiB) Downloaded 238 times
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PROTOCOL NEC HELP

Post by Benj »

Sounds like the Arduino code may be modulating in software before controlling the output. This is certainly possible but I bet it's not at all flexible. As soon as you stop using the one specific pin that works with the code all hell breaks loose.

You could also do this in Flowcode by instead of writing to a output pin you change the PWM duty from 0% for logic 0 and 50% for logic 1. At least doing this it is fairly easy to change PWM channel and therefore I/O. You could also use a timer to do the PWM modulation yourself without requiring a PWM peripheral.

I'll look at your video and see if I can see what the problem might be.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: PROTOCOL NEC HELP

Post by mikn »

thanks for help
after minor changes to your code I've got it working

created new macro SendPWM with PWM component and changed output in your code to this macro, which swithces PWM on and off.
1.GIF
1.GIF (9.74 KiB) Viewed 13344 times
2.GIF
2.GIF (19.19 KiB) Viewed 13344 times
just tested, everything works ok. the only thing is the distance. with arduino TX code I get readings from 3-4 meters, with fc TX code I get only 1-2 meters. maybe need to play with duty cycle of transmitter diode.
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PROTOCOL NEC HELP

Post by Benj »

Try duty of 104 instead of 128 and this should give you closer to 50% duty with the period set to 209.

Smaller duties might work even better e.g. 10% - 25%. RC5 specifies a 25% duty.

A duty of 52 should give you 25%.

Glad it's working now though :D

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: PROTOCOL NEC HELP

Post by mikn »

Let me get back to this.
I have played with duties and didn't succeed with ir led power. So I put back RC5 component and played with it's settings. Finally it worked with all Software (transmit mode and modulation) and I have full power as with Arduino code and no losses. It's with Arduino pro mini board.

Now I have changed the board and use Atmega168 running at 8MHz. Connected IR to B2 port, set all to Software as well and it transmits data, but it's not RC5 but unknown format.
TXPacket(1,1,1) gives me result on receiver:
11100110011000010001101110001 UNKNOWN 483140465
And I wonder if 8 MHz is enough for this?

Also I have found that correct timing for delays and uart communications is only when I set Clock speed to 1mhz instead of 8mhz in settings, however Atmega is running at 8mhz and CKDIV=0. When I set clock speed to 8mhz in settings, the project runs 8 times slower.
Are there any problems with PWM timings due to a 1mhz and not 8mhz in settings? Maybe that's why the receiver gets incorrect data.
Transmitter project included below.
Attachments
irtestTX.fcfx
(8.28 KiB) Downloaded 212 times
FC 6.1.3.2 (18.02.2016)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: PROTOCOL NEC HELP

Post by LeighM »

CKDIV8=0 means fuse programmed, which results in 1/8 system clock,
so you need CKDIV8 to be "1" unprogrammed

Post Reply