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.

how to program timer in pic18f4550

Status
Not open for further replies.

electroing

New Member
i am a newbie in programming pic18f4550. i would like to know a simple LDR circuit produce signal, and pic 18f4550 recieved the signal, then how to program pic to recognize the signal as speed? my partner think of using timer for example: 1 signal every 0.8s means that the speed is 1 revolution per 0.8s. but we don't know how to set the timer in pic.hope can get help here, thanks.
 
Last edited:
oh, did u know that how to write the source code to calculate wind speed? i use the LDR to detect and convert the signal then wanna calculate it. but i didn't use motor. thanks in advance...:)
 
Last edited:
I use a small opto pair.. The chopper wheel has four slits (works like a mouse wheel) the wind turns the wheel and the pulses are produced... I don't use a motor either.

The calculation is all to do with the radius to the center of each cup to the center of rotation... Then you need to co-efficent of the wind resistance from the front and back of the cups and the volume is then adjusted to suit..

Ha Ha .. That was a load of ***** I put it in a wind tunnel and worked it out...
 
Last edited:
thank you.

i am sorry, i not fully understand about:

The calculation is all to do with the radius to the center of each cup to the center of rotation... Then you need to co-efficent of the wind resistance from the front and back of the cups and the volume is then adjusted to suit...

that time, how to program this part? do u mind show me ur source code?
now, i don't know how to program the ldr signal to speed. if i cant do a program, my hardware cant work.

hope i possible done a source code of ldr signal to speed ....
 
Last edited:
I cant post my code as it is copyrighted!! But a hint.. put your output signal onto T0CK1 (ra4) option_reg to clock on external signal.... write a delay for 1second... read the TMR0 viola!! pulses per second

Then you must work out how many in 1 second relates to wind speed (I cant help you here as I dont know your head unit)
 
Perhaps this piece of code will be helpful. I used it to create and calibrate a 1 ms timer. The code can easily be modifed to count the number of events that take place in a second as Ian suggests.
Code:
#include <p18f4550.h>
#include "p18f4550_hw_config.h"  // configures for 20MHz crystal and Fcy of 12MHz
#include "p18f4550_LCD.h"  // control a 2x16 character LCD  display

#define LED  LATCbits.LATC7  // an LED with 470 ohm Rs attached to port C bit 7

void wait_ms(unsigned int time)  // function for delay in ms
{  // an instruction cycle takes 83.3 ns, so 12,000 cycles will create a 1 ms delay
  int i = 0;
  const int cCycles_Per_ms = 921; // This variable will need to be adjusted to calibrate the function for 1 ms delay
  while(time){
  for( i = 0; i < cCycles_Per_ms ; i ++){
  }
  time--;  // decrement the time unit, repeat till time = 0
  }
}

void main(void)
{
  // Hardware Configuration
  // LED Config
  TRISCbits.TRISC7 = 0;  // RC7 pin 26 set for output
  LED = 0; // led off

  // LCD Display
  LCD_init();

  // check the wait_ms() function for accuracy
  // setup timer 0 and turn it on
  // ON  8B  Src Edg PSA PS2 PS1 PS0
  T0CON = 0x88;  //  1  0  0  0  1  0  0  0  -> 16 bit, PS = 1
  TMR0H =  0x00; TMR0L =  0x00; // count up from 0
  wait_ms(3);  // expect 3 ms delay
  T0CON = 0x08;  // Stop the timer
  LCD_byte(TMR0L);  // display TMRO count low byte (must be read first)
  LCD_cmd(0xC0);  // move to line 2 of the LCD
  LCD_byte(TMR0H);  // display TMRO count high byte

  while(1){  // infinite loop to blink an led
  LED = 0; // led off
  wait_ms(800);
  LED = 1; // led on
  wait_ms(200);
  }  // verify that the LED blinks at a 1 sec rate
}
Here's a detailed explanation:
**broken link removed**
**broken link removed**
 
Last edited:
wind speed monitoring a bit pointless on a crane, one small creak let alone movement and I would down faster than a pic 32 flat out!!!:D. As a maths problem it does interest me tho!
Not as simple as it looks, ok wind tunnel one way, but say you were design the cups etc, interesting mathematical relationship. I still wouldnt need a anemometer to tell me when I needed to get down :D
 
LG said:
wind speed monitoring a bit pointless on a crane,
Don't say that!!! I sell loads of them..

Actually its becoming more and more of a requirement... Cranes have to come down (where possible ) when the wind speed exceeds 10 m/s...

LG also said:
I still wouldnt need a anemometer to tell me when I needed to get down :D

One guy asked if I could put the words " You shouldn't be here" on the screen at 15 m/s +...
 
Don't say that!!! I sell loads of them..

Actually its becoming more and more of a requirement... Cranes have to come down (where possible ) when the wind speed exceeds 10 m/s...



One guy asked if I could put the words " You shouldn't be here" on the screen at 15 m/s +...
at that speed It should read, you are too mentally impaired to be driving cranes
 
you got to feel sorry for the guy thats got to put the cups on the top bit :D
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top