Commit 3dadf6c0 authored by kamako's avatar kamako
Browse files

Update main.c

parent 22d0cb6c
......@@ -2,9 +2,47 @@
#include "printing.h"
#include "drivers/mss_ace/mss_ace.h"
#include "drivers/mss_pdma/mss_pdma.h"
#include "drivers/mss_timer/mss_timer.h"
const int timerPeriod=1000000*1000/2;
void Timer1_IRQHandler( void ){
move_forward(100);
*((uint32_t*) 0x40050014) = 0xffff9a65;
/*
if(states_remaining!=0){
MSS_TIM1_init(MSS_TIMER_ONE_SHOT_MODE);
MSS_TIM1_load_immediate(timerPeriod);
MSS_TIM1_start();
MSS_TIM1_enable_irq();
}
if(states_remaining == 0) {
MSS_TIM1_stop();
MSS_GPIO_set_outputs(0);
}
*/
MSS_TIM1_clear_irq();
}
void move() {
MSS_TIM1_init(MSS_TIMER_PERIODIC_MODE);
MSS_TIM1_load_immediate(timerPeriod);
MSS_TIM1_start();
MSS_TIM1_enable_irq();
}
int getTemp(double voltage){
if(voltage>2.109) return -84.532*voltage+327.26;
else {
return 289.87*exp(-0.353*voltage);
}
}
int main()
{
wait();
MSS_UART_init(&g_mss_uart0, MSS_UART_9600_BAUD,
MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);
NVIC_EnableIRQ(GPIO0_IRQn);
MSS_GPIO_config( MSS_GPIO_0, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE );
MSS_GPIO_enable_irq( MSS_GPIO_0 );
......@@ -25,30 +63,59 @@ int main()
sizeof(holder)
);*/
uint therm=0;
uint tempC=0;
uint hotEndStatus=0;
double voltage=1;
while(1)
{
printf("%d",tempC);
therm = get_raw_thermistor();
voltage=((double)therm)/4096.0*2.56;
tempC=getTemp(voltage);
*(uint32_t*)((uint32_t)EX_Base + STEPS) = 50;
if (tempC>190)
hotEndStatus=0;
else if (tempC<180)
hotEndStatus=1;
else {
int randNum=(double)rand()/RAND_MAX*10;
if(randNum<(190-tempC))
hotEndStatus=1;
else
hotEndStatus=0;
}
set_hotend_switch(hotEndStatus);
}
init_loco();
init_print();
// DEBUG BEGIN
uint32_t experiod, scaledsp, pidkp, pidki, pidkd, sens, therm, pidsp;
char automode, sw, fan;
experiod = get_extruder_period();
automode = get_hotend_auto();
scaledsp = get_hotend_sp();
sw = get_hotend_switch();
fan = get_hotend_fan();
pidkp = get_hotend_pid_k(KP);
pidki = get_hotend_pid_k(KI);
pidkd = get_hotend_pid_k(KD);
sens = get_hotend_pid_sensitivity();
therm = get_raw_thermistor();
pidsp = get_pid_sp();
// DEBUG END
// // DEBUG BEGIN
// uint32_t experiod, scaledsp, pidkp, pidki, pidkd, sens, therm, pidsp;
// char automode, sw, fan;
// experiod = get_extruder_period();
// automode = get_hotend_auto();
// scaledsp = get_hotend_sp();
// sw = get_hotend_switch();
// fan = get_hotend_fan();
// pidkp = get_hotend_pid_k(KP);
// pidki = get_hotend_pid_k(KI);
// pidkd = get_hotend_pid_k(KD);
// sens = get_hotend_pid_sensitivity();
// therm = get_raw_thermistor();
// pidsp = get_pid_sp();
// // DEBUG END
char hotendTog = 1, fanTog = 1;
move();
while( 1 )
{
move_forward(200);
uint8_t buf[] = "20\n\r";
MSS_UART_polled_tx(&g_mss_uart0, buf, sizeof(buf));
/*
extrude(1);
// DEBUG BEGIN
experiod = get_extruder_period();
......@@ -70,7 +137,7 @@ int main()
// DEBUG END
set_hotend_switch(hotendTog);
set_hotend_fan(fanTog);
*/
}
return 0;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment