Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Reading PWM Signal

Status
Not open for further replies.
I have tried... it is the same like previous. I checked already whether the MCU is damaged, I changed the code then write it onto MCU, it runs okay.

Hmm, I am not really sure myself where is the problem.

LED on RB0 should be initially off, but it turned on all the time.
RB1 shows no signal.

By the way, your "reading Pulse" code makes SENSE really... I just don't know why this LED turned on all the time.
 
If you are using a Pickit2 or ICD2 you could set a break point on the return count; line and see what values you are actually getting.

Mike.
 
and from these values I refer back to the iPulse if Statement?? Okay, I would try that now... See how much do I get.
 
i cannot set up the debugger because I dont have any debug kit. hmm, btw Pommie, why is the RB0 high?
 
The only way that RB0 can be high is if vLeft is never executed.

I just noticed that you are setting ADCON1 equal to 7, this leaves port A pins as analogue. When configured as analogue they always read zero! Try changing it to ADCON1=0x0f;

Mike.
 
The only way that RB0 can be high is if vLeft is never executed.

I just noticed that you are setting ADCON1 equal to 7, this leaves port A pins as analogue. When configured as analogue they always read zero! Try changing it to ADCON1=0x0f;

Mike.

IT IS FREAKIN WORKING!!!!

one question.. 0x0f = 15 right?
 
Thanks Mike. You are really helping me out.

Btw Mike, I asked my colleague ystd, he mentioned about having a timer that counts quicker than this, so instead of having 1 range (between 14 and 15 also between 15 and 16), I could do something he mentioned, timer and prescaler and with my ext osc I can adjust how much pulses there are to count the Pulse Width or Ton of my PWM Signal.

He tells me that this will increase the accuracy of my light kit, and then.. I have to count also the number of Toff. So it is like double-checking simulation, and logically speaking sum of both two must be the Tperiod which is 16ms from my receiver. So, in order to do so, I will come back later after I read the tuts about timers etc. Hope you will help me again, as always :) thanks!!!
 
Someone on my forum did something similar; **broken link removed**

Essentially the signals are servo signals and they are transmitted at around 50Hz (every 20mS). The signal ranges from 1000uS to 2000uS and tells the target servo channel where the servo is meant physically be aligned too

I made up a user library in Swordfish to make things easier for him, and it can be utilized like this;
Code:
Device = 18F2550
Clock = 20

Dim Result1 as Word
Dim Result2 as Word

Include "Pulse.bas"


// Start of main program..

While True
    Result1 = PulseIn(0)          // read portc.0 for a servo signal pulse
    Result2 = PulseIn(1)          // read portc.1 for a servo signal pulse
    .
    .
    .
Wend

The result is a value from 0-2000 (the time frame for the period of the servo signal in uS)

It worked really well for him, and he used it to turn LED landing lights/spotlights on and off with his RC plane initially.. after that he went on to use it for something other nifty little ideas (not just R/C plane use)

If your interested then let me know on the thread I linked above, and I will throw it on that forum
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top